diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2011-06-22 11:28:20 +0200 |
commit | 9db190c7e736ec8d063187d4241b59feaf7dc2d1 (patch) | |
tree | 46d1a0dee7febef5c2d57a9f7b972be16a163b3d /resources/jquery/jquery.localize.js | |
parent | 78677c7bbdcc9739f6c10c75935898a20e1acd9e (diff) |
update to MediaWiki 1.17.0
Diffstat (limited to 'resources/jquery/jquery.localize.js')
-rw-r--r-- | resources/jquery/jquery.localize.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/resources/jquery/jquery.localize.js b/resources/jquery/jquery.localize.js new file mode 100644 index 00000000..3c8f597a --- /dev/null +++ b/resources/jquery/jquery.localize.js @@ -0,0 +1,64 @@ +/** + * Simple Placeholder-based Localization + * + * Call on a selection of HTML which contains <msg key="message-key" /> elements or elements with + * title-msg="message-key" or alt-msg="message-key" attributes. <msg /> elements will be replaced + * with localized text, elements with title-msg and alt-msg attributes will receive localized title + * and alt attributes. + * + * Note that "msg" elements must have html namespacing such as "<html:msg />" to be compatible with + * Internet Explorer. + * + * Example: + * <p class="somethingCool"> + * <html:msg key="my-message" /> + * <img src="something.jpg" title-msg="my-title-message" alt-msg="my-alt-message" /> + * </p> + * + * Localizes to... + * + * <p class="somethingCool"> + * My Message + * <img src="something.jpg" title="My Title Message" alt="My Alt Message" /> + * </p> + */ + +( function( $, mw ) { + /** + * Localizes a DOM selection by replacing <msg /> elements with localized text and adding + * localized title and alt attributes to elements with title-msg and alt-msg attributes + * respectively. + * + * @param Object: options Map of options + * * prefix: Message prefix to use when localizing elements and attributes + */ + + $.fn.localize = function( options ) { + options = $.extend( { 'prefix': '' }, options ); + return $(this) + .find( 'msg,html\\:msg' ) + .each( function() { + $(this) + .text( mediaWiki.msg( options.prefix + $(this).attr( 'key' ) ) ) + .replaceWith( $(this).html() ); + } ) + .end() + .find( '[title-msg]' ) + .each( function() { + $(this) + .attr( 'title', mw.msg( options.prefix + $(this).attr( 'title-msg' ) ) ) + .removeAttr( 'title-msg' ); + } ) + .end() + .find( '[alt-msg]' ) + .each( function() { + $(this) + .attr( 'alt', mw.msg( options.prefix + $(this).attr( 'alt-msg' ) ) ) + .removeAttr( 'alt-msg' ); + } ) + .end(); + }; +} )( jQuery, mediaWiki ); + +// Let IE know about the msg tag before it's used... +document.createElement( 'msg' ); |