mirror of https://github.com/apache/cloudstack.git
UI plugin framework: Support plugin internationalization
Allows UI plugins to contribute their own internationalized strings to the global js dictionary. Each plugin would define a dictionary.js and several dictionary_<locale>.js files. As each plugin is loaded, the appropriate plugin dictionary is loaded into the global js dictionary (with the global dictionary taking precedence in the event of a conflict). Original author: Chris Suich <chris.suich@netapp.com> Reviewed by: Brian Federle <brian.federle@citrix.com>
This commit is contained in:
parent
f87eed5b79
commit
cd056f4572
|
|
@ -84,6 +84,13 @@
|
|||
var css = basePath + id + '.css';
|
||||
var configJS = type == 'plugins' ? basePath + 'config' : null;
|
||||
|
||||
var pluginDictionary;
|
||||
var locale;
|
||||
if (type == 'plugins') {
|
||||
pluginDictionary = basePath + 'dictionary';
|
||||
locale = $.cookie('lang');
|
||||
}
|
||||
|
||||
if (configJS) {
|
||||
// Load config metadata
|
||||
require([configJS]);
|
||||
|
|
@ -100,6 +107,29 @@
|
|||
})
|
||||
);
|
||||
|
||||
if (pluginDictionary) {
|
||||
// Callback for extending the dictionary with new entries
|
||||
var addToDictionary = function() {
|
||||
var additions = cloudStack[type][id].dictionary;
|
||||
$.extend(dictionary, additions);
|
||||
};
|
||||
|
||||
// Only add a suffix if the locale is defined and not english/US
|
||||
var suffix = '';
|
||||
if (locale && (locale != '' && locale != 'en' & locale != 'en_US'))
|
||||
suffix = '_'+locale;
|
||||
|
||||
// Attempt to load the locale's dictionary
|
||||
require([pluginDictionary+suffix], addToDictionary, function() {
|
||||
// If the load failed and there was no suffix, don't try again
|
||||
if (!suffix)
|
||||
return;
|
||||
|
||||
// Otherwise try to load the default dictionary
|
||||
require([pluginDictionary], addToDictionary);
|
||||
});
|
||||
}
|
||||
|
||||
loadedPlugins = loadedPlugins + 1;
|
||||
|
||||
if (loadedPlugins === pluginTotal) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue