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:
@@ -18,27 +18,57 @@
|
|||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// 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];
|
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
|
||||||
|
|
||||||
// Collapse the browser's preferred languages to one of our supported locales:
|
// Maps a two-letter language prefix (lowercased) to its canonical supported
|
||||||
// any fr* tag maps to fr-FR, any en* tag maps to en-US. en-US is the ultimate
|
// tag, e.g. any "de*" browser tag resolves to "de-DE".
|
||||||
// fallback when nothing matches. Resolving to a canonical supported tag here
|
const PREFIX_TO_LANGUAGE: Record<string, SupportedLanguage> = {
|
||||||
// means i18next is never asked to load an unsupported locale; fallbackLng only
|
en: "en-US",
|
||||||
// has to cover individual missing keys.
|
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 {
|
export function resolveLanguage(): SupportedLanguage {
|
||||||
const candidates = navigator.languages?.length
|
const candidates = navigator.languages?.length
|
||||||
? navigator.languages
|
? navigator.languages
|
||||||
: [navigator.language];
|
: [navigator.language];
|
||||||
|
|
||||||
for (const tag of candidates) {
|
for (const tag of candidates) {
|
||||||
const lower = tag.toLowerCase();
|
const prefix = tag.toLowerCase().split("-")[0];
|
||||||
if (lower.startsWith("fr")) {
|
const language = PREFIX_TO_LANGUAGE[prefix];
|
||||||
return "fr-FR";
|
if (language) {
|
||||||
}
|
return language;
|
||||||
if (lower.startsWith("en")) {
|
|
||||||
return "en-US";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user