From de34c0ec7b59c75d70ec5a96da09e218c2813d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Fri, 2 Aug 2013 17:04:46 +0200 Subject: [PATCH 1/2] Implement language fallback. Fix issue #492. --- unpacked/MathJax.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/unpacked/MathJax.js b/unpacked/MathJax.js index 7210d8013..0e857e02a 100644 --- a/unpacked/MathJax.js +++ b/unpacked/MathJax.js @@ -1068,7 +1068,9 @@ MathJax.Localization = { en: {menuTitle: "English", isLoaded: true}, // nothing needs to be loaded for this de: {menuTitle: "Deutsch"}, fr: {menuTitle: "Fran\u00E7ais"}, - it: {menuTitle: "Italiano"} + it: {menuTitle: "Italiano"}, + pt: {menuTitle: "portugus\u00EA", remap: "pt-br"}, + "pt-br": {menuTitle: "portugu\u00EAs do Brasil"} }, // @@ -1394,8 +1396,20 @@ MathJax.Localization = { // Set the current language // setLocale: function(locale) { - // don't set it if there isn't a definition for it - if (this.strings[locale]) {this.locale = locale} + // Selection algorithm: + // 1) Downcase locale name (e.g. "en-US" => "en-us") + // 2) Try a parent language (e.g. "en-us" => "en") + // 3) Try the fallback specified in the data (e.g. "pt" => "pt-br") + // 4) Otherwise don't change the locale. + if (!locale) return; + locale = locale.toLowerCase(); + while (!this.strings[locale]) { + var dashPos = locale.lastIndexOf("-"); + if (dashPos === -1) return; + locale = locale.substring(0, dashPos); + } + var remap = this.strings[locale].remap; + this.locale = remap ? remap : locale; if (MathJax.Menu) {this.loadDomain("MathMenu")} }, From 0af5c438fa947790920d295e399f8f33ba641bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Thu, 8 Aug 2013 12:56:13 +0200 Subject: [PATCH 2/2] Fix how the locale is set from menu config / query param. #492 --- unpacked/MathJax.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/unpacked/MathJax.js b/unpacked/MathJax.js index 0e857e02a..018062722 100644 --- a/unpacked/MathJax.js +++ b/unpacked/MathJax.js @@ -1393,9 +1393,9 @@ MathJax.Localization = { }, // - // Set the current language + // Reset the current language // - setLocale: function(locale) { + resetLocale: function(locale) { // Selection algorithm: // 1) Downcase locale name (e.g. "en-US" => "en-us") // 2) Try a parent language (e.g. "en-us" => "en") @@ -1410,6 +1410,13 @@ MathJax.Localization = { } var remap = this.strings[locale].remap; this.locale = remap ? remap : locale; + }, + + // + // Set the current language + // + setLocale: function(locale) { + this.resetLocale(locale); if (MathJax.Menu) {this.loadDomain("MathMenu")} }, @@ -2297,7 +2304,7 @@ MathJax.Hub.Startup = { // set the locale and the default menu value for the locale // if (this.params.locale) { - MathJax.Localization.locale = this.params.locale; + MathJax.Localization.resetLocale(this.params.locale); MathJax.Hub.config.menuSettings.locale = this.params.locale; } // @@ -2375,7 +2382,7 @@ MathJax.Hub.Startup = { ["Get",MathJax.HTML.Cookie,"menu",MathJax.Hub.config.menuSettings], [function (config) { if (config.menuSettings.locale) - {MathJax.Localization.locale = config.menuSettings.locale} + {MathJax.Localization.resetLocale(config.menuSettings.locale)} var renderer = config.menuSettings.renderer, jax = config.jax; if (renderer) { var name = "output/"+renderer; jax.sort();