Improve i18n language matching (#5939)
Some checks are pending
Auto Test / auto-test (18, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (18, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, windows-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (20, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, windows-latest) (push) Blocked by required conditions
Auto Test / armv7-simple-test (18, ARMv7) (push) Waiting to run
Auto Test / armv7-simple-test (20, ARMv7) (push) Waiting to run
Auto Test / check-linters (push) Waiting to run
Auto Test / e2e-test (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
validate / json-yaml-validate (push) Waiting to run
validate / validate (push) Waiting to run

This commit is contained in:
Ionys 2025-06-22 01:02:52 +02:00 committed by GitHub
parent 5aeda2dab0
commit 072226bde2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -75,13 +75,22 @@ export function currentLocale() {
if (locale in messages) {
return locale;
}
// some locales are further specified such as "en-US".
// If the locale is a 2-letter code, we can try to find a regional variant
// e.g. "fr" may not be in the messages, but "fr-FR" is
if (locale.length === 2) {
const regionalLocale = `${locale}-${locale.toUpperCase()}`;
if (regionalLocale in messages) {
return regionalLocale;
}
} else {
// Some locales are further specified such as "en-US".
// If we only have a generic locale for this, we can use it too
const genericLocale = locale.split("-")[0];
const genericLocale = locale.slice(0, 2);
if (genericLocale in messages) {
return genericLocale;
}
}
}
return "en";
}