Skip to content

Commit

Permalink
fix: refactor validateLangTag (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Oct 12, 2023
1 parent 1ab9c4c commit e72cc8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare namespace Intl {
function getCanonicalLocales(locales: string | string[]): string[]
}

0 comments on commit e72cc8b

Please sign in to comment.