Register eleven new compliance-portal locales

Add German, Spanish, Indonesian, Italian, Japanese, Korean, Polish,
Portuguese, Turkish, Ukrainian, and Simplified Chinese to
SUPPORTED_LANGUAGES, and map each one's browser language-tag prefix to
its canonical locale in resolveLanguage() so i18next can be asked to
load it. Catalog JSON for these locales lands in the following
commits.

Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
Bryan Frimin
2026-07-20 15:48:15 +02:00
parent 177a5d0361
commit c61ff9721e

View File

@@ -18,27 +18,57 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
export const SUPPORTED_LANGUAGES = ["en-US", "fr-FR"] as const;
export const SUPPORTED_LANGUAGES = [
"en-US",
"fr-FR",
"de-DE",
"es-ES",
"id-ID",
"it-IT",
"ja-JP",
"ko-KR",
"pl-PL",
"pt-PT",
"tr-TR",
"uk-UA",
"zh-CN",
] as const;
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
// Collapse the browser's preferred languages to one of our supported locales:
// any fr* tag maps to fr-FR, any en* tag maps to en-US. en-US is the ultimate
// fallback when nothing matches. Resolving to a canonical supported tag here
// means i18next is never asked to load an unsupported locale; fallbackLng only
// has to cover individual missing keys.
// Maps a two-letter language prefix (lowercased) to its canonical supported
// tag, e.g. any "de*" browser tag resolves to "de-DE".
const PREFIX_TO_LANGUAGE: Record<string, SupportedLanguage> = {
en: "en-US",
fr: "fr-FR",
de: "de-DE",
es: "es-ES",
id: "id-ID",
it: "it-IT",
ja: "ja-JP",
ko: "ko-KR",
pl: "pl-PL",
pt: "pt-PT",
tr: "tr-TR",
uk: "uk-UA",
zh: "zh-CN",
};
// Collapse the browser's preferred languages to one of our supported locales
// by matching the two-letter language prefix (e.g. any "fr*" tag maps to
// fr-FR). en-US is the ultimate fallback when nothing matches. Resolving to a
// canonical supported tag here means i18next is never asked to load an
// unsupported locale; fallbackLng only has to cover individual missing keys.
export function resolveLanguage(): SupportedLanguage {
const candidates = navigator.languages?.length
? navigator.languages
: [navigator.language];
for (const tag of candidates) {
const lower = tag.toLowerCase();
if (lower.startsWith("fr")) {
return "fr-FR";
}
if (lower.startsWith("en")) {
return "en-US";
const prefix = tag.toLowerCase().split("-")[0];
const language = PREFIX_TO_LANGUAGE[prefix];
if (language) {
return language;
}
}