i18n-iso-languages
Get started by adding it to your project
yarn add @marcelovicentegc/i18n-iso-languages
npm i @marcelovicentegc/i18n-iso-language
configure
lookup key
IETF language tag
locales
import { configure } from '@marcelovicentegc/i18n-iso-languages'
configure({
localesSubset: {
lookupKey: 'IETFLanguageTag',
locales: ['pt-BR','en-US','zh-CN','es-MX','hi-IN'],
},
})
getLocales
import { getLocales } from '@marcelovicentegc/i18n-iso-languages'
const locales = getLocales()
locales.map((locale) => {
return (
<>
<Separator />
<p>Official language: {locale.officialLanguage}</p>
<p>
Native official language: {locale.nativeOfficialLanguage}
</p>
<p>Region: {locale.region}</p>
<p>Native region: {locale.nativeRegion}</p>
<p>ISO 639-1: {locale.ISO6391}</p>
<p>ISO 639-2: {locale.ISO6392}</p>
<p>ISO 3166-1 alpha-2: {locale.ISO31661Alpha2}</p>
<p>ISO 3166-1 alpha-3: {locale.ISO31661Alpha3}</p>
<p>IETFL language tag: {locale.IETFLanguageTag}</p>
</>
);
})
getLocaleByIETFLanguageTag
You can get a single locale by language tag by providing a single language tag...
import { getLocaleByIETFLanguageTag, Locale } from '@marcelovicentegc/i18n-iso-languages'
const locale = getLocaleByIETFLanguageTag('hi-IN') as Locale
Or you can get multiple by providing multiple language tags!
import { getLocaleByIETFLanguageTag, Locale } from '@marcelovicentegc/i18n-iso-languages'
const locales = getLocaleByIETFLanguageTag(['en-US','es-MX']) as Locale[]
getLocalesByOfficialLanguage
You can get multiple locales by official language by providing a single official language...
import { getLocalesByOfficialLanguage } from '@marcelovicentegc/i18n-iso-languages'
const locales = getLocalesByOfficialLanguage('Portuguese')
Or you can get multiple by providing multiple official languages!
import { getLocalesByOfficialLanguage } from '@marcelovicentegc/i18n-iso-languages'
const locales = getLocalesByOfficialLanguage(['Portuguese','Spanish'])
getLocaleByRegion
You can get multiple locales by region by providing a single region...
import { getLocaleByRegion } from '@marcelovicentegc/i18n-iso-languages'
const locales = getLocaleByRegion('United States')
Or you can get multiple by providing multiple regions!
import { getLocaleByRegion, Locale } from '@marcelovicentegc/i18n-iso-languages'
const locales = getLocaleByRegion(['Brazil','China','United States'])