From a4453c9a260b6c4003c0ebd0aa460f61b93a499a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 5 Apr 2023 12:46:17 +0200 Subject: Special case English translation fallback We should not be listing this in LINGUAS as that gives the impression that English has en explicit translation. Instead, it is a special case that the code needs to be explicitly aware of. This reverts 9a06058 in favour of a more robust fix. --- app/localization.js | 13 ++++++------- app/ui.js | 2 +- tests/test.localization.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/localization.js b/app/localization.js index 84341da..73f66c5 100644 --- a/app/localization.js +++ b/app/localization.js @@ -40,12 +40,6 @@ export class Localizer { .replace("_", "-") .split("-"); - // Built-in default? - if ((userLang[0] === 'en') && - ((userLang[1] === undefined) || (userLang[1] === 'us'))) { - return; - } - // First pass: perfect match for (let j = 0; j < supportedLanguages.length; j++) { const supLang = supportedLanguages[j] @@ -64,7 +58,12 @@ export class Localizer { return; } - // Second pass: fallback + // Second pass: English fallback + if (userLang[0] === 'en') { + return; + } + + // Third pass pass: other fallback for (let j = 0;j < supportedLanguages.length;j++) { const supLang = supportedLanguages[j] .toLowerCase() diff --git a/app/ui.js b/app/ui.js index 07e0904..c1f6776 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1762,7 +1762,7 @@ const UI = { }; // Set up translations -const LINGUAS = ["cs", "de", "el", "en", "es", "fr", "it", "ja", "ko", "nl", "pl", "pt_BR", "ru", "sv", "tr", "zh_CN", "zh_TW"]; +const LINGUAS = ["cs", "de", "el", "es", "fr", "it", "ja", "ko", "nl", "pl", "pt_BR", "ru", "sv", "tr", "zh_CN", "zh_TW"]; l10n.setup(LINGUAS); if (l10n.language === "en" || l10n.dictionary !== undefined) { UI.prime(); diff --git a/tests/test.localization.js b/tests/test.localization.js index 7e8e6c1..36e8d04 100644 --- a/tests/test.localization.js +++ b/tests/test.localization.js @@ -27,6 +27,16 @@ describe('Localization', function () { l10n.setup(["es", "fr"]); expect(l10n.language).to.equal('en'); }); + it('should fall back to generic English for other English', function () { + window.navigator.languages = ["en-AU", "de"]; + l10n.setup(["de", "fr", "en-GB"]); + expect(l10n.language).to.equal('en'); + }); + it('should prefer specific English over generic', function () { + window.navigator.languages = ["en-GB", "de"]; + l10n.setup(["de", "en-AU", "en-GB"]); + expect(l10n.language).to.equal('en-GB'); + }); it('should use the most preferred user language', function () { window.navigator.languages = ["nl", "de", "fr"]; l10n.setup(["es", "fr", "de"]); -- cgit v1.2.1