From e6522b8fef6671bb281a612b6d5d543a8d1afb47 Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 9 May 2013 17:41:00 +0200 Subject: [PATCH] update setLocale (handle module localization) --- source/Ox/js/Locale.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/source/Ox/js/Locale.js b/source/Ox/js/Locale.js index 5a1ef406..0ecc311d 100644 --- a/source/Ox/js/Locale.js +++ b/source/Ox/js/Locale.js @@ -13,7 +13,8 @@ success 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); - callback(true); - }); - } else { - callback(true); - } + 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(isValidLocale);