jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/330691 )

Change subject: Include an i18n example in OO.ui.msg documentation
......................................................................


Include an i18n example in OO.ui.msg documentation

Example is a streamlined version of how standalone VisualEditor handles i18n,
using jQuery.i18n.

Change-Id: Ie436df50bd2ae061fcbca252dcfe674ff39fc398
---
M src/core.js
1 file changed, 38 insertions(+), 4 deletions(-)

Approvals:
  Esanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/core.js b/src/core.js
index 9b690d0..ec3dfc4 100644
--- a/src/core.js
+++ b/src/core.js
@@ -372,15 +372,49 @@
        /**
         * Get a localized message.
         *
-        * In environments that provide a localization system, this function 
should be overridden to
-        * return the message translated in the user's language. The default 
implementation always returns
-        * English messages.
-        *
         * After the message key, message parameters may optionally be passed. 
In the default implementation,
         * any occurrences of $1 are replaced with the first parameter, $2 with 
the second parameter, etc.
         * Alternative implementations of OO.ui.msg may use any substitution 
system they like, as long as
         * they support unnamed, ordered message parameters.
         *
+        * In environments that provide a localization system, this function 
should be overridden to
+        * return the message translated in the user's language. The default 
implementation always returns
+        * English messages. An example of doing this with 
[jQuery.i18n](https://github.com/wikimedia/jquery.i18n)
+        * follows.
+        *
+        *     @example
+        *     var i, iLen, button,
+        *         messagePath = 'oojs-ui/dist/i18n/',
+        *         languages = [ $.i18n().locale, 'ur', 'en' ],
+        *         languageMap = {};
+        *
+        *     for ( i = 0, iLen = languages.length; i < iLen; i++ ) {
+        *         languageMap[ languages[ i ] ] = messagePath + languages[ i 
].toLowerCase() + '.json';
+        *     }
+        *
+        *     $.i18n().load( languageMap ).done( function() {
+        *         // Replace the built-in `msg` only once we've loaded the 
internationalization.
+        *         // OOjs UI uses `OO.ui.deferMsg` for all initially-loaded 
messages. So long as
+        *         // you put off creating any widgets until this promise is 
complete, no English
+        *         // will be displayed.
+        *         OO.ui.msg = $.i18n;
+        *
+        *         // A button displaying "OK" in the default locale
+        *         button = new OO.ui.ButtonWidget( {
+        *             label: OO.ui.msg( 'ooui-dialog-message-accept' ),
+        *             icon: 'check'
+        *         } );
+        *         $( 'body' ).append( button.$element );
+        *
+        *         // A button displaying "OK" in Urdu
+        *         $.i18n().locale = 'ur';
+        *         button = new OO.ui.ButtonWidget( {
+        *             label: OO.ui.msg( 'ooui-dialog-message-accept' ),
+        *             icon: 'check'
+        *         } );
+        *         $( 'body' ).append( button.$element );
+        *     } );
+        *
         * @param {string} key Message key
         * @param {...Mixed} [params] Message parameters
         * @return {string} Translated message with parameters substituted

-- 
To view, visit https://gerrit.wikimedia.org/r/330691
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie436df50bd2ae061fcbca252dcfe674ff39fc398
Gerrit-PatchSet: 5
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: Bartosz DziewoƄski <matma....@gmail.com>
Gerrit-Reviewer: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: VolkerE <volke...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to