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
@*/
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) {
callback = arguments[1];
url = null;
@ -24,20 +25,21 @@
translations = {};
callback(true);
} else {
Ox.getJSON(
Ox.PATH + 'Ox/json/locale.' + locale + '.json',
function(data) {
translations = data;
if (url) {
Ox.getJSON(url, function(data) {
Ox.extend(translations, data);
Ox.forEach(Ox.LOCALES, function(locales, module) {
if (Ox.contains(locales, locale)) {
urls.push([
Ox.PATH + 'Ox' + (module ? '.' + module : '')
+ '/json/locale.' + locale + '.json'
]);
}
});
url && urls.push([url]);
Ox.getJSON(urls, function(data) {
urls.forEach(function(url) {
Ox.extend(translations, data[url]);
callback(true);
});
} else {
callback(true);
}
}
);
});
}
} else {
callback(isValidLocale);