diff --git a/modules/oojs-ui/OO.ui.js b/modules/oojs-ui/OO.ui.js index 16332813a0..4bba1844e3 100644 --- a/modules/oojs-ui/OO.ui.js +++ b/modules/oojs-ui/OO.ui.js @@ -15,21 +15,78 @@ OO.ui = {}; 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 321b037545..09612f00e8 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 @@ OO.ui.IconedElement = function OoUiIconedElement( $icon, config ) { * 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 357218799e..f788e29c36 100644 --- a/modules/ve/init/ve.init.Platform.js +++ b/modules/ve/init/ve.init.Platform.js @@ -114,7 +114,7 @@ ve.init.Platform.prototype.getSystemPlatform = function () { * @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' ); }; /**