import * as bcp47 from 'bcp-47' ; import { BaseTagSystem } from './base' ; import { Config } from '~/core' ; export class BCP47 extends BaseTagSystem { normalize ( locale ? , fallback = 'en' , strict = false ) { if ( ! locale ) return fallback ; return bcp47 . stringify ( bcp47 . parse ( locale , { normalize : strict , forgiving : ! strict } ) ) || fallback ; } toBCP47 ( locale ) { return bcp47 . stringify ( bcp47 . parse ( locale , { normalize : true , forgiving : false } ) ) || undefined ; } toFlagname ( locale ) { const { region , language } = bcp47 . parse ( locale , { normalize : true , forgiving : true } ) ; if ( ! language ) return '' ; return ( region || Config . localeCountryMap [ language ] || language || '' ) . toLowerCase ( ) ; } lookup ( locale ) { locale = this . normalize ( locale ) ; const canonical = Intl . getCanonicalLocales ( locale ) [ 0 ] ; return Intl . Collator . supportedLocalesOf ( canonical , { localeMatcher : 'lookup' } ) [ 0 ] ; } }