r92888 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92887‎ | r92888 | r92889 >
Date:21:08, 22 July 2011
Author:catrope
Status:reverted
Tags:
Comment:
1.17wmf1: Update jquery.localize to trunk state. Not bothering to figure out and merge the right revs, just used cp(1).
Modified paths:
  • /branches/wmf/1.17wmf1/resources/jquery/jquery.localize.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/resources/jquery/jquery.localize.js
@@ -1,14 +1,11 @@
22 /**
3 - * Simple Placeholder-based Localization
4 - *
5 - * Call on a selection of HTML which contains <msg key="message-key" /> elements or elements with
6 - * title-msg="message-key" or alt-msg="message-key" attributes. <msg /> elements will be replaced
 3+ * Simple Placeholder-based Localization
 4+ *
 5+ * Call on a selection of HTML which contains <html:msg key="message-key" /> elements or elements with
 6+ * title-msg="message-key" or alt-msg="message-key" attributes. <html:msg /> elements will be replaced
77 * with localized text, elements with title-msg and alt-msg attributes will receive localized title
88 * and alt attributes.
9 - *
10 - * Note that "msg" elements must have html namespacing such as "<html:msg />" to be compatible with
11 - * Internet Explorer.
12 - *
 9+ * *
1310 * Example:
1411 * <p class="somethingCool">
1512 * <html:msg key="my-message" />
@@ -16,49 +13,61 @@
1714 * </p>
1815 *
1916 * Localizes to...
20 - *
21 - * <p class="somethingCool">
22 - * My Message
23 - * <img src="something.jpg" title="My Title Message" alt="My Alt Message" />
24 - * </p>
 17+ * <p class="somethingCool">
 18+ * My Message
 19+ * <img src="something.jpg" title="My Title Message" alt="My Alt Message" />
 20+ * </p>
2521 */
 22+( function( $ ) {
 23+/**
 24+ * Localizes a DOM selection by replacing <html:msg /> elements with localized text and adding
 25+ * localized title and alt attributes to elements with title-msg and alt-msg attributes
 26+ * respectively.
 27+ *
 28+ * @param Object: options Map of options
 29+ * * prefix: Message prefix to use when localizing elements and attributes
 30+ */
2631
27 -( function( $, mw ) {
28 - /**
29 - * Localizes a DOM selection by replacing <msg /> elements with localized text and adding
30 - * localized title and alt attributes to elements with title-msg and alt-msg attributes
31 - * respectively.
32 - *
33 - * @param Object: options Map of options
34 - * * prefix: Message prefix to use when localizing elements and attributes
35 - */
36 -
37 - $.fn.localize = function( options ) {
38 - options = $.extend( { 'prefix': '' }, options );
39 - return $(this)
40 - .find( 'msg,html\\:msg' )
41 - .each( function() {
42 - $(this)
43 - .text( mediaWiki.msg( options.prefix + $(this).attr( 'key' ) ) )
44 - .replaceWith( $(this).html() );
45 - } )
46 - .end()
47 - .find( '[title-msg]' )
48 - .each( function() {
49 - $(this)
50 - .attr( 'title', mw.msg( options.prefix + $(this).attr( 'title-msg' ) ) )
51 - .removeAttr( 'title-msg' );
52 - } )
53 - .end()
54 - .find( '[alt-msg]' )
55 - .each( function() {
56 - $(this)
57 - .attr( 'alt', mw.msg( options.prefix + $(this).attr( 'alt-msg' ) ) )
58 - .removeAttr( 'alt-msg' );
59 - } )
60 - .end();
 32+$.fn.localize = function( options ) {
 33+ options = $.extend( { 'prefix': '', 'keys': {}, 'params': {} }, options );
 34+ function msg( key ) {
 35+ var args = key in options.params ? options.params[key] : [];
 36+ // Format: mw.msg( key [, p1, p2, ...] )
 37+ args.unshift( options.prefix + ( key in options.keys ? options.keys[key] : key ) );
 38+ return mw.msg.apply( mw, args );
6139 };
62 -} )( jQuery, mediaWiki );
 40+ return $(this)
 41+ // Ok, so here's the story on this selector.
 42+ // In IE 6/7, searching for 'msg' turns up the 'html:msg', but searching for 'html:msg' does not.
 43+ // In later IE and other browsers, searching for 'html:msg' turns up the 'html:msg', but searching for 'msg' does not.
 44+ // So searching for both 'msg' and 'html:msg' seems to get the job done.
 45+ // This feels pretty icky, though.
 46+ .find( 'msg,html\\:msg' )
 47+ .each( function() {
 48+ var $el = $(this);
 49+ $el
 50+ .text( msg( $el.attr( 'key' ) ) )
 51+ .replaceWith( $el.html() );
 52+ } )
 53+ .end()
 54+ .find( '[title-msg]' )
 55+ .each( function() {
 56+ var $el = $(this);
 57+ $el
 58+ .attr( 'title', msg( $el.attr( 'title-msg' ) ) )
 59+ .removeAttr( 'title-msg' );
 60+ } )
 61+ .end()
 62+ .find( '[alt-msg]' )
 63+ .each( function() {
 64+ var $el = $(this);
 65+ $el
 66+ .attr( 'alt', msg( $el.attr( 'alt-msg' ) ) )
 67+ .removeAttr( 'alt-msg' );
 68+ } )
 69+ .end();
 70+};
6371
6472 // Let IE know about the msg tag before it's used...
6573 document.createElement( 'msg' );
 74+} )( jQuery );

Follow-up revisions

RevisionCommit summaryAuthorDate
r928891.17wmf1: Revert r92888 per Reedy so I can do it properly with svn copycatrope21:10, 22 July 2011
r928901.17wmf1: Redo r92888 properly: copy jquery.localize.js from trunkcatrope21:11, 22 July 2011

Status & tagging log