Do not discard user-specified languages from intl.accept_languages when switching... user/paxed/acceptlanguage-nomangle
authorPasi Kallinen <pasi.kallinen@pttk.fi>
Thu, 5 Sep 2013 08:03:36 +0000 (11:03 +0300)
committerPasi Kallinen <pasi.kallinen@pttk.fi>
Thu, 5 Sep 2013 08:55:29 +0000 (11:55 +0300)
Signed-off-by: Pasi Kallinen <pasi.kallinen@pttk.fi>
Open-ILS/xul/staff_client/chrome/content/util/mozilla.js

index a5cbe8c..fb2a191 100644 (file)
@@ -58,13 +58,24 @@ util.mozilla.change_locale = function( locale ) {
         var current_locale = 'en-US';
         try { current_locale = util.mozilla.prefs().getCharPref('general.useragent.locale'); } catch(E) { alert('util.locale.change, prefs() = ' + E); }
         if (locale != current_locale) {
+           var accept_langs;
+           try { accept_langs = util.mozilla.prefs().getCharPref('intl.accept_languages').split(","); } catch(E) { }
+           if (typeof(accept_langs)!='undefined' && accept_langs.length) {
+               var locre = new RegExp('\\b' + locale + '\\b');
+               for (var i = accept_langs.length-1; i >= 0; i--)
+                   if (accept_langs[i].match(locre))
+                       accept_langs.splice(i, 1);
+               accept_langs.unshift(locale);
+           } else {
+               accept_langs = new Array(locale);
+           }
             util.mozilla.prefs().setCharPref('general.useragent.locale',locale);
-            util.mozilla.prefs().setCharPref('intl.accept_languages',locale);
+            util.mozilla.prefs().setCharPref('intl.accept_languages',accept_langs.join());
             util.mozilla.chromeRegistry().reloadChrome();
         }
 
     } catch(E) {
-        alert('FIXME: util.mozilla.change_locale( "' + locale + ") = " + E);
+        alert('FIXME: util.mozilla.change_locale( "' + locale + '" ) = ' + E);
     }
 }