INNER CODE UNIT · TypeScript
getLanguage
vsdudakov/fastadmin · frontend/src/locales/index.ts:53
export const getLanguage = (configured?: string | null): TLanguage => {
const candidates = [
configured,
...(typeof navigator !== "undefined"
? [navigator.language, ...(navigator.languages || [])]
: []),
];
for (const candidate of candidates) {
if (!candidate) {
continue;
}
const base = candidate.toLowerCase().split(/[-_]/)[0];
if (base in resources) {
return base as TLanguage;
}
}
return "en";
};