jenkins-bot has submitted this change and it was merged.
Change subject: Provide a default implementation for OO.ui.msg
......................................................................
Provide a default implementation for OO.ui.msg
Just a simple message map in English. Also document localizaton-related
things in OO.ui
Change-Id: Ie74762238ca66747776610157c838dd75a864463
---
M modules/oojs-ui/OO.ui.js
M modules/oojs-ui/elements/OO.ui.IconedElement.js
M modules/ve/init/ve.init.Platform.js
3 files changed, 62 insertions(+), 4 deletions(-)
Approvals:
Trevor Parscal: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/oojs-ui/OO.ui.js b/modules/oojs-ui/OO.ui.js
index 1633281..4bba184 100644
--- a/modules/oojs-ui/OO.ui.js
+++ b/modules/oojs-ui/OO.ui.js
@@ -15,21 +15,78 @@
OO.ui.bind = $.proxy;
+/**
+ * Get the user's language and any fallback languages. These language codes
are used by
+ * OO.ui.IconedElement to select localized icons in the user's language.
+ *
+ * In environments that provide a localization system, this function should be
overridden to
+ * return the user's language(s). The default implementation returns English
(en) only.
+ *
+ * @returns {string[]} Language codes, in descending order of priority
+ */
OO.ui.getUserLanguages = function () {
return [ 'en' ];
+};
+
+( function () {
+
+/**
+ * Message store for the default implementation of OO.ui.msg
+ *
+ * Environments that provide a localization system should not use this, but
should override
+ * OO.ui.msg altogether.
+ *
+ * @private
+ */
+var messages = {
+ // Label text for button to exit from dialog
+ 'ooui-dialog-action-close': 'Close',
+ // TODO remove me
+ 'ooui-inspector-close-tooltip': 'Close',
+ // TODO remove me
+ 'ooui-inspector-remove-tooltip': 'Remove',
+ // Tool tip for a button that moves items in a list down one place
+ 'ooui-outline-control-move-down': 'Move item down',
+ // Tool tip for a button that moves items in a list up one place
+ 'ooui-outline-control-move-up': 'Move item up',
+ // Label for the toolbar group that contains a list of all other
available tools
+ 'ooui-toolbar-more': 'More'
};
/**
* 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.
+ *
* @abstract
* @param {string} key Message key
* @param {Mixed...} [params] Message parameters
+ * @returns {string} Translated message with parameters substituted
*/
OO.ui.msg = function ( key ) {
- return '[' + key + ']';
+ var message = messages[key], params = Array.prototype.slice.call(
arguments, 1 );
+ if ( typeof message === 'string' ) {
+ // Perform $1 substitution
+ message = message.replace( /\$(\d+)/g, function ( unused, n ) {
+ var i = parseInt( n, 10 );
+ return params[i - 1] !== undefined ? params[i - 1] :
'$' + n;
+ } );
+ } else {
+ // Return placeholder if message not found
+ message = '[' + key + ']';
+ }
+ return message;
};
+} )();
+
// Add more as you need
OO.ui.Keys = {
'UNDEFINED': 0,
diff --git a/modules/oojs-ui/elements/OO.ui.IconedElement.js
b/modules/oojs-ui/elements/OO.ui.IconedElement.js
index 321b037..09612f0 100644
--- a/modules/oojs-ui/elements/OO.ui.IconedElement.js
+++ b/modules/oojs-ui/elements/OO.ui.IconedElement.js
@@ -14,7 +14,8 @@
* @constructor
* @param {jQuery} $icon Icon node, assigned to #$icon
* @param {Object} [config] Configuration options
- * @cfg {Object|string} [icon=''] Symbolic icon name, or map of icon names
keyed by language ID
+ * @cfg {Object|string} [icon=''] Symbolic icon name, or map of icon names
keyed by language ID;
+ * use the 'default' key to specify the icon to be used when there is no icon
in the user's language.
*/
OO.ui.IconedElement = function OoUiIconedElement( $icon, config ) {
// Config intialization
@@ -35,7 +36,7 @@
* Set the icon.
*
* @method
- * @param {string} [value] Symbolic name of icon to use
+ * @param {Object|string} [value] Symbolic name of icon to use
* @chainable
*/
OO.ui.IconedElement.prototype.setIcon = function ( value ) {
diff --git a/modules/ve/init/ve.init.Platform.js
b/modules/ve/init/ve.init.Platform.js
index 3572187..f788e29 100644
--- a/modules/ve/init/ve.init.Platform.js
+++ b/modules/ve/init/ve.init.Platform.js
@@ -114,7 +114,7 @@
* @returns {string[]} User language strings
*/
ve.init.Platform.prototype.getUserLanguages = function () {
- throw new Error( 've.init.Platform.getUserLanugages must be overridden
in subclass' );
+ throw new Error( 've.init.Platform.getUserLanguages must be overridden
in subclass' );
};
/**
--
To view, visit https://gerrit.wikimedia.org/r/93000
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie74762238ca66747776610157c838dd75a864463
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits