update setLocale (handle module localization)

This commit is contained in:
rolux 2013-05-09 17:41:00 +02:00
parent 83f4282917
commit e6522b8fef

View file

@ -13,7 +13,8 @@
success <b> If true, locale has been set success <b> If true, locale has been set
@*/ @*/
Ox.setLocale = function(locale, url, callback) { Ox.setLocale = function(locale, url, callback) {
var isValidLocale = Ox.contains(Object.keys(Ox.LOCALES), locale); var isValidLocale = Ox.contains(Object.keys(Ox.LOCALE_NAMES), locale),
urls = [];
if (arguments.length == 2) { if (arguments.length == 2) {
callback = arguments[1]; callback = arguments[1];
url = null; url = null;
@ -24,20 +25,21 @@
translations = {}; translations = {};
callback(true); callback(true);
} else { } else {
Ox.getJSON( Ox.forEach(Ox.LOCALES, function(locales, module) {
Ox.PATH + 'Ox/json/locale.' + locale + '.json', if (Ox.contains(locales, locale)) {
function(data) { urls.push([
translations = data; Ox.PATH + 'Ox' + (module ? '.' + module : '')
if (url) { + '/json/locale.' + locale + '.json'
Ox.getJSON(url, function(data) { ]);
Ox.extend(translations, data); }
});
url && urls.push([url]);
Ox.getJSON(urls, function(data) {
urls.forEach(function(url) {
Ox.extend(translations, data[url]);
callback(true); callback(true);
}); });
} else { });
callback(true);
}
}
);
} }
} else { } else {
callback(isValidLocale); callback(isValidLocale);