From bb79c4caaddbb3e2526a2225e22d3c1b510367c2 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sun, 22 Oct 2023 09:46:41 -0600 Subject: [PATCH 1/2] loading-screen: Fallback to loading language only translations If we don't have a translation matching any regional locale in `navigator.languages`, try again with only the locale's language. This will allow better fallbacks when the browser doesn't build `navigator.languages` as a fallback list itself like `['es-GT', 'es-419', 'es']`. --- packages/loading-screen/src/main.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/loading-screen/src/main.js b/packages/loading-screen/src/main.js index a7b359a2..7ecf5ca5 100644 --- a/packages/loading-screen/src/main.js +++ b/packages/loading-screen/src/main.js @@ -32,6 +32,15 @@ async function loadBestLocaleData(locales) { } } + // Try again with only the locale's language. + for (const lang of locales.map(l => l.split('-')[0].toLowerCase())) { + try { + return await loadLocaleData(lang); + } catch { + continue; + } + } + return await loadLocaleData(defaultLocale); } From db6ceb8a193940b400b1148f949ffdb0da9b6d3a Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sun, 22 Oct 2023 09:58:57 -0600 Subject: [PATCH 2/2] loading-screen: Make translations regionless This allows matching a much wider set of locales without depending on the browser to build `navigator.languages` as we expect it. Furthermore, we're not actually providing regional translation variation and probably never will. Fixes: #893 --- packages/loading-screen/lang/{en-US.json => en.json} | 0 packages/loading-screen/lang/{es-419.json => es.json} | 0 packages/loading-screen/package.json | 2 +- packages/loading-screen/src/main.js | 4 ++-- 4 files changed, 3 insertions(+), 3 deletions(-) rename packages/loading-screen/lang/{en-US.json => en.json} (100%) rename packages/loading-screen/lang/{es-419.json => es.json} (100%) diff --git a/packages/loading-screen/lang/en-US.json b/packages/loading-screen/lang/en.json similarity index 100% rename from packages/loading-screen/lang/en-US.json rename to packages/loading-screen/lang/en.json diff --git a/packages/loading-screen/lang/es-419.json b/packages/loading-screen/lang/es.json similarity index 100% rename from packages/loading-screen/lang/es-419.json rename to packages/loading-screen/lang/es.json diff --git a/packages/loading-screen/package.json b/packages/loading-screen/package.json index 309c70d7..460a2e1a 100644 --- a/packages/loading-screen/package.json +++ b/packages/loading-screen/package.json @@ -7,7 +7,7 @@ "build": "yarn run compile-messages && vue-cli-service build --no-module && yarn zip", "lint": "vue-cli-service lint", "zip": "../../scripts/bundle_zip.py loading-screen.zip", - "extract-messages": "formatjs extract 'src/**/*.{js,vue}' --format transifex --out-file lang/en-US.json", + "extract-messages": "formatjs extract 'src/**/*.{js,vue}' --format transifex --out-file lang/en.json", "compile-messages": "formatjs compile-folder --format transifex lang compiled-lang" }, "dependencies": { diff --git a/packages/loading-screen/src/main.js b/packages/loading-screen/src/main.js index 7ecf5ca5..887e1a4b 100644 --- a/packages/loading-screen/src/main.js +++ b/packages/loading-screen/src/main.js @@ -11,8 +11,8 @@ import LoadingRetry from '@/views/LoadingRetry.vue'; import store from "@/store"; // Language codes are RFC 5646 (https://datatracker.ietf.org/doc/html/rfc5646) -const supportedLocales = ['en-US', 'es-419']; -const defaultLocale = 'en-US'; +const supportedLocales = ['en', 'es']; +const defaultLocale = 'en'; const requestedLocales = navigator.languages; function loadLocaleData(locale) {