Files
blitzkit/packages/website/src/core/i18n/getBestLocale.ts
T
2025-01-14 19:22:41 -06:00

16 lines
445 B
TypeScript

import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '@blitzkit/i18n';
export function getBestLocale() {
const desiredLocale =
localStorage.getItem('preferred-locale') ??
navigator.language.split('-')[0];
const isSupported = (SUPPORTED_LOCALES as unknown as string[]).includes(
desiredLocale,
);
const isDefault = desiredLocale === DEFAULT_LOCALE;
if (!isSupported || isDefault) return undefined;
return desiredLocale;
}