mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Merge "dm.MWTemplateSpecModel: Resolve translations through the TemplateData API"
This commit is contained in:
commit
ac1a386c95
|
@ -29,34 +29,6 @@ ve.dm.MWTemplateSpecModel = function VeDmMWTemplateSpecModel( template ) {
|
|||
this.fill();
|
||||
};
|
||||
|
||||
/* Static Methods */
|
||||
|
||||
/**
|
||||
* Get the correct value from a message property.
|
||||
*
|
||||
* @method
|
||||
* @static
|
||||
* @param {string|Object|null} val Messsage or object with messages keyed by language
|
||||
* @param {Mixed} [fallback=null] Value to use if message is not available
|
||||
* @param {string} [lang] Language to prefer, user interface language will be used by default
|
||||
* @returns {string} Message text or fallback if not available
|
||||
*/
|
||||
ve.dm.MWTemplateSpecModel.getMessage = function ( val, fallback, lang ) {
|
||||
var i, len, langs = lang !== undefined ? [lang] : ve.init.platform.getUserLanguages();
|
||||
if ( fallback === undefined ) {
|
||||
fallback = null;
|
||||
}
|
||||
if ( ve.isPlainObject( val ) ) {
|
||||
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;
|
||||
};
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
|
@ -126,7 +98,7 @@ ve.dm.MWTemplateSpecModel.prototype.fill = function () {
|
|||
*/
|
||||
ve.dm.MWTemplateSpecModel.prototype.getDefaultParameterSpec = function ( name ) {
|
||||
return {
|
||||
'label': { 'en': name },
|
||||
'label': name,
|
||||
'description': null,
|
||||
'default': '',
|
||||
'type': 'string',
|
||||
|
@ -172,7 +144,7 @@ ve.dm.MWTemplateSpecModel.prototype.getLabel = function () {
|
|||
* @returns {string|null} Template description or null if not available
|
||||
*/
|
||||
ve.dm.MWTemplateSpecModel.prototype.getDescription = function () {
|
||||
return this.constructor.getMessage( this.description, null );
|
||||
return this.description;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -207,7 +179,7 @@ ve.dm.MWTemplateSpecModel.prototype.isParameterAlias = function ( name ) {
|
|||
* @returns {string} Parameter label
|
||||
*/
|
||||
ve.dm.MWTemplateSpecModel.prototype.getParameterLabel = function ( name ) {
|
||||
return this.constructor.getMessage( this.params[name].label, name );
|
||||
return this.params[name].label || name;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -218,7 +190,7 @@ ve.dm.MWTemplateSpecModel.prototype.getParameterLabel = function ( name ) {
|
|||
* @returns {string|null} Parameter description
|
||||
*/
|
||||
ve.dm.MWTemplateSpecModel.prototype.getParameterDescription = function ( name ) {
|
||||
return this.constructor.getMessage( this.params[name].description );
|
||||
return this.params[name].description;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -164,7 +164,8 @@ ve.dm.MWTransclusionModel.prototype.fetch = function () {
|
|||
'data': {
|
||||
'format': 'json',
|
||||
'action': 'templatedata',
|
||||
'titles': titles.join( '|' )
|
||||
'titles': titles.join( '|' ),
|
||||
'lang': mw.config.get( 'wgUserLanguage' )
|
||||
}
|
||||
} )
|
||||
.done( function ( data ) {
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
/**
|
||||
* Dialog for inserting and editing MediaWiki transclusions.
|
||||
*
|
||||
* See https://raw.github.com/wikimedia/mediawiki-extensions-TemplateData/master/spec.templatedata.json
|
||||
* for the latest version of the TemplateData specification.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.MWDialog
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue