mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
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
This commit is contained in:
parent
2ea9437e32
commit
5b3ed2bc56
|
@ -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,
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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' );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue