summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2023-04-05 12:46:17 +0200
committerPierre Ossman <ossman@cendio.se>2023-04-05 12:46:17 +0200
commita4453c9a260b6c4003c0ebd0aa460f61b93a499a (patch)
tree803a0361616e5031cdc2258c25625e72ef8b6b23
parent747603c0d5bbdc8ac31b81f7a1b31291a397d280 (diff)
downloadnovnc-a4453c9a260b6c4003c0ebd0aa460f61b93a499a.tar.gz
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.
-rw-r--r--app/localization.js13
-rw-r--r--app/ui.js2
-rw-r--r--tests/test.localization.js10
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"]);