From 5489823a612631b1e84c8d19d8ef2363c896f644 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 17 Jul 2013 10:24:22 +0000 Subject: [PATCH] dont set default locale in user.ui and use first browser locale by default if available and fall back to site default after that, fixes #1578; load locale from unjoined json files in debug mode --- pandora/app/views.py | 2 ++ pandora/config.0xdb.jsonc | 3 ++- pandora/config.indiancinema.jsonc | 3 ++- pandora/config.padma.jsonc | 3 ++- pandora/config.pandora.jsonc | 3 ++- static/js/pandora.js | 3 ++- static/js/utils.js | 22 +++++++++++++++++----- 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pandora/app/views.py b/pandora/app/views.py index 4a56c5b30..b79ebe9f4 100644 --- a/pandora/app/views.py +++ b/pandora/app/views.py @@ -154,6 +154,8 @@ def init(request): config = copy.deepcopy(settings.CONFIG) del config['keys'] + if 'HTTP_ACCEPT_LANGUAGE' in request.META: + response['data']['locale'] = request.META['HTTP_ACCEPT_LANGUAGE'].split(';')[0].split('-')[0] response['data']['site'] = config response['data']['user'] = init_user(request.user, request) request.session['last_init'] = str(datetime.now()) diff --git a/pandora/config.0xdb.jsonc b/pandora/config.0xdb.jsonc index 375a44389..0e0d86e3c 100644 --- a/pandora/config.0xdb.jsonc +++ b/pandora/config.0xdb.jsonc @@ -716,6 +716,7 @@ "system": "0xDB@0xDB.org" }, "https": true, + "locale": "en", "id": "0xdb", "name": "0xDB", "url": "0xDB.org", @@ -803,7 +804,7 @@ "listSort": [{"key": "director", "operator": "+"}], "listView": "grid", "lists": {}, - "locale": "en", + "locale": "", "mapFind": "", "mapSelection": "", "page": "", diff --git a/pandora/config.indiancinema.jsonc b/pandora/config.indiancinema.jsonc index a17ce114b..0ec8bdf6a 100644 --- a/pandora/config.indiancinema.jsonc +++ b/pandora/config.indiancinema.jsonc @@ -729,6 +729,7 @@ }, "folderdepth": 4, "https": true, + "locale": "en", "id": "indiancinema", "name": "Indiancine.ma", "url": "indiancine.ma", @@ -815,7 +816,7 @@ "listSort": [{"key": "year", "operator": "+"}], "listView": "grid", "lists": {}, - "locale": "en", + "locale": "", "mapFind": "", "mapSelection": "", "page": "", diff --git a/pandora/config.padma.jsonc b/pandora/config.padma.jsonc index 98b9f5260..c08ffb4e4 100644 --- a/pandora/config.padma.jsonc +++ b/pandora/config.padma.jsonc @@ -607,6 +607,7 @@ "system": "system@pad.ma" }, "https": true, + "locale": "en", "id": "padma", "name": "Pad.ma", "url": "pad.ma", @@ -693,7 +694,7 @@ "listSort": [{"key": "title", "operator": "+"}], "listView": "grid", "lists": {}, - "locale": "en", + "locale": "", "mapFind": "", "mapSelection": "", "page": "", diff --git a/pandora/config.pandora.jsonc b/pandora/config.pandora.jsonc index 7a5699a3c..8f07848eb 100644 --- a/pandora/config.pandora.jsonc +++ b/pandora/config.pandora.jsonc @@ -527,6 +527,7 @@ }, "https": false, "id": "pandora", + "locale": "en", "name": "Demo", "url": "pandora.local", "videoprefix": "" @@ -612,7 +613,7 @@ "listSort": [{"key": "title", "operator": "+"}], "listView": "grid", "lists": {}, - "locale": "en", + "locale": "", "mapFind": "", "mapSelection": "", "page": "", diff --git a/static/js/pandora.js b/static/js/pandora.js index b361cb07f..57d2bd691 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -327,7 +327,8 @@ appPanel }); // set locale and initialize url controller - pandora.setLocale(pandora.user.ui.locale, function() { + // data.locale + pandora.setLocale(pandora.user.ui.locale || data.locale, function() { pandora.URL.init().parse(function() { var isHome = Ox.contains(['/', '/home'], document.location.pathname); if (data.browserSupported) { diff --git a/static/js/utils.js b/static/js/utils.js index f550671fc..ec77ab0dc 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1734,11 +1734,23 @@ pandora.selectList = function() { }; pandora.setLocale = function(locale, callback) { - Ox.setLocale( - locale, - locale && locale != 'en' ? '/static/json/locale.' + locale + '.json' : null, - callback - ); + var url; + // language from http header might not be supported, + // fall back to site default + if (Ox.isUndefined(Ox.LOCALE_NAMES[locale])) { + locale = pandora.site.site.locale; + } + if (locale != 'en') { + if (pandora.localStorage('enableDebugMode')) { + url = [ + '/static/json/locale.pandora.' + locale + '.json', + '/static/json/locale.' + pandora.site.site.id + '.' + locale + '.json', + ]; + } else { + url = '/static/json/locale.' + locale + '.json' + } + } + Ox.setLocale(locale, url, callback); }; pandora.unloadWindow = function() {