mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Merge changes Id2328d6e,I840b689d
* changes: Remove language variants from bold/italic now we have fallbacks Implement fallback langauges
This commit is contained in:
commit
841a414c31
|
@ -42,14 +42,17 @@ ve.dm.MWTemplateSpecModel = function VeDmMWTemplateSpecModel( template ) {
|
|||
* @returns {string} Message text or fallback if not available
|
||||
*/
|
||||
ve.dm.MWTemplateSpecModel.getMessage = function ( val, fallback, lang ) {
|
||||
if ( lang === undefined ) {
|
||||
lang = ve.init.platform.getUserLanguage();
|
||||
}
|
||||
var i, len, langs = lang !== undefined ? [lang] : ve.init.platform.getUserLanguages();
|
||||
if ( fallback === undefined ) {
|
||||
fallback = null;
|
||||
}
|
||||
if ( ve.isPlainObject( val ) ) {
|
||||
return val[lang] || fallback;
|
||||
for ( i = 0, len = langs.length; i < len; i++ ) {
|
||||
if ( val[langs[i]] ) {
|
||||
return val[langs[i]];
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
return typeof val === 'string' ? val : fallback;
|
||||
};
|
||||
|
|
|
@ -90,8 +90,16 @@ ve.init.mw.Platform.prototype.getSystemPlatform = function () {
|
|||
};
|
||||
|
||||
/** */
|
||||
ve.init.mw.Platform.prototype.getUserLanguage = function () {
|
||||
return mw.config.get( 'wgUserLanguage' );
|
||||
ve.init.mw.Platform.prototype.getUserLanguages = function () {
|
||||
var lang = mw.config.get( 'wgUserLanguage' ),
|
||||
langParts = lang.split( '-' ),
|
||||
langs = [ lang ];
|
||||
|
||||
if ( langParts.length > 0 ) {
|
||||
langs.push( langParts[0] );
|
||||
}
|
||||
|
||||
return langs;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,10 +110,17 @@ ve.init.sa.Platform.prototype.getSystemPlatform = function () {
|
|||
};
|
||||
|
||||
/** */
|
||||
ve.init.sa.Platform.prototype.getUserLanguage = function () {
|
||||
ve.init.sa.Platform.prototype.getUserLanguages = function () {
|
||||
// IE or Firefox Safari Opera
|
||||
var lang = window.navigator.userLanguage || window.navigator.language;
|
||||
return lang.split( '-' )[0];
|
||||
var lang = window.navigator.userLanguage || window.navigator.language,
|
||||
langParts = lang.split( '-' ),
|
||||
langs = [ lang ];
|
||||
|
||||
if ( langParts.length > 0 ) {
|
||||
langs.push( langParts[0] );
|
||||
}
|
||||
|
||||
return langs;
|
||||
};
|
||||
|
||||
/* Initialization */
|
||||
|
|
|
@ -106,12 +106,12 @@ ve.init.Platform.prototype.getSystemPlatform = function () {
|
|||
};
|
||||
|
||||
/**
|
||||
* Gets the user language.
|
||||
* Gets the user language and any fallback languages.
|
||||
*
|
||||
* @method
|
||||
* @abstract
|
||||
* @returns {string} User language string
|
||||
* @returns {string[]} User language strings
|
||||
*/
|
||||
ve.init.Platform.prototype.getUserLanguage = function () {
|
||||
throw new Error( 've.init.Platform.getUserLanugage must be overridden in subclass' );
|
||||
ve.init.Platform.prototype.getUserLanguages = function () {
|
||||
throw new Error( 've.init.Platform.getUserLanugages must be overridden in subclass' );
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ ve.ui.BoldButtonTool.static.name = 'bold';
|
|||
|
||||
ve.ui.BoldButtonTool.static.icon = {
|
||||
'default': 'bold-a',
|
||||
'be-tarask': 'bold-cyrl-te',
|
||||
'be': 'bold-cyrl-te',
|
||||
'cs': 'bold-b',
|
||||
'da': 'bold-f',
|
||||
'de': 'bold-f',
|
||||
|
@ -50,7 +50,6 @@ ve.ui.BoldButtonTool.static.icon = {
|
|||
'os': 'bold-cyrl-be',
|
||||
'pl': 'bold-b',
|
||||
'pt': 'bold-n',
|
||||
'pt-br': 'bold-n',
|
||||
'ru': 'bold-cyrl-zhe',
|
||||
'sv': 'bold-f'
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ ve.ui.ItalicButtonTool.static.name = 'italic';
|
|||
|
||||
ve.ui.ItalicButtonTool.static.icon = {
|
||||
'default': 'italic-a',
|
||||
'be-tarask': 'italic-cyrl-ka',
|
||||
'be': 'italic-cyrl-ka',
|
||||
'cs': 'italic-i',
|
||||
'da': 'italic-k',
|
||||
'de': 'italic-k',
|
||||
|
@ -50,7 +50,6 @@ ve.ui.ItalicButtonTool.static.icon = {
|
|||
'os': 'italic-cyrl-ka',
|
||||
'pl': 'italic-i',
|
||||
'pt': 'italic-i',
|
||||
'pt-br': 'italic-i',
|
||||
'ru': 'italic-cyrl-ka',
|
||||
'sv': 'italic-k'
|
||||
};
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
* @param {Object} [config] Config options
|
||||
*/
|
||||
ve.ui.ButtonTool = function VeUiButtonTool( toolbar, config ) {
|
||||
var icon = this.constructor.static.icon,
|
||||
lang = ve.init.platform.getUserLanguage();
|
||||
var i, len,
|
||||
icon = this.constructor.static.icon,
|
||||
langs = ve.init.platform.getUserLanguages();
|
||||
|
||||
// Parent constructor
|
||||
ve.ui.Tool.call( this, toolbar, config );
|
||||
|
@ -37,7 +38,13 @@ ve.ui.ButtonTool = function VeUiButtonTool( toolbar, config ) {
|
|||
this.$icon.addClass( 've-ui-buttonTool-icon' );
|
||||
if ( icon ) {
|
||||
if ( ve.isPlainObject( icon ) ) {
|
||||
icon = lang in icon ? icon[lang] : icon['default'];
|
||||
langs.push( 'default' );
|
||||
for ( i = 0, len = langs.length; i < len; i++ ) {
|
||||
if ( langs[i] in icon ) {
|
||||
icon = icon[langs[i]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.$icon.addClass( 've-ui-icon-' + icon );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue