diff --git a/src/shared.ts b/src/shared.ts index 70bf362..3f0837a 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -42,8 +42,7 @@ export function toLocale(val: string | Intl.Locale): Intl.Locale { */ export function validateLangTag(lang: string): boolean { try { - // TODO: if we have a better way to validate the language tag, we should use it. - new Intl.Locale(lang) + Intl.getCanonicalLocales(lang) return true } catch { return false diff --git a/src/shim.d.ts b/src/shim.d.ts new file mode 100644 index 0000000..4f541fa --- /dev/null +++ b/src/shim.d.ts @@ -0,0 +1,3 @@ +declare namespace Intl { + function getCanonicalLocales(locales: string | string[]): string[] +}