Open History to see the last commit
1import { resolveLocale } from "@t3tools/client-runtime/locales";
2
3import gtConfig from "../../gt.config.json";
4
5export const DEFAULT_LOCALE = gtConfig.defaultLocale;
6export const SUPPORTED_LOCALES: ReadonlyArray<string> = [DEFAULT_LOCALE, ...gtConfig.locales];
7
8export function resolveWebLocaleSelection(language: string, browserLocales: ReadonlyArray<string>) {
9 const catalogLocale = resolveLocale(language, browserLocales, SUPPORTED_LOCALES, DEFAULT_LOCALE);
10 // Undefined formats with the host locale: "system", and English over a regional English browser.
11 const keepEnglishRegion =
12 language === DEFAULT_LOCALE && /^en(?:-|$)/i.test(browserLocales[0] ?? "");
13 const formattingLocale = language === catalogLocale && !keepEnglishRegion ? language : undefined;
14 return { catalogLocale, formattingLocale };
15}