Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cldr-language-country

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cldr-language-country

A small utility to get CLDR, country code (cc) and language code (lc) data.

  • 0.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
decreased by-41.03%
Maintainers
1
Weekly downloads
 
Created
Source

cldr-language-country

Tiny util that maps 2-character language codes (lc) and country codes (cc) to CLDR locale data. Especially useful for generating search queries.

Install

npm i cldr-language-country

Usage

functionparametersreturns
generateDatanoneData for all locales
getLocalesnoneArray of all locales (string)
getCountriesnoneArray of all country data, with name and code
getLanguagesnoneArray of all language data, with name, native, and code
keyByCCnoneObject containing all data, keyed by country code
keyByLCnoneObject containing all data, keyed by language code
getByCCcc(String)Array of all data whose country.code matches cc.
getByLClc(String)Array of all data whose language.code matches lc.
getByCountryNamename(string)Array of all data whose country.name matches name.
getByLanguagename(String)Array of all data whose language.name matches name.
getByLocalelocale(String)Array of all data whose locale matches the provided locale
getByNativeNamename(String)Array of all data whose language.name matches name.

generateData()

import { generateData } from 'cldr-language-country';

const locales = generateData();

Result:

[
    {
        language: {
            code: 'en',
            name: 'English',
            native: 'English'
        },
        country: {
            code: 'us',
            name: 'United States'
        },
        locale: 'en-US'
    } 
]

getLocales()

import { getLocales } from 'cldr-language-country';

const locales = getLocales();

Result:

[
  'ps-AF', 'fa-AF', 'uz-AF', 'sv-AX', 'sq-AL', 'en-AL', 'ar-DZ',
  'fr-DZ', 'en-AS', 'ca-AD', 'en-AD', 'ln-AO', 'pt-AO', 'en-AI',
  ...continued
]

getCountries()

import { getCountries } from 'cldr-language-country';

const countries = countries();

Result:

[
  { code: 'AF', name: 'Afghanistan' },
  { code: 'AX', name: 'Åland Islands' },
  { code: 'AL', name: 'Albania' },
  { code: 'DZ', name: 'Algeria' },
  { code: 'AS', name: 'American Samoa' },
  ...continued
]

getLanguages()

import { getLanguages } from 'cldr-language-country';

const languages = getLanguages();

Result:

[
  { code: 'aa', name: 'Afar', native: 'Afar' },
  { code: 'ab', name: 'Abkhazian', native: 'Аҧсуа' },
  { code: 'af', name: 'Afrikaans', native: 'Afrikaans' },
  { code: 'ak', name: 'Akan', native: 'Akana' },
  { code: 'am', name: 'Amharic', native: 'አማርኛ' },
  ...continued
]

keyByCC()

import { keyByCC } from 'cldr-language-country';

const locales = keyByCC();

Result:

{
    'CA': [
        {
            language: {
                code: 'en',
                name: 'English',
                native: 'English'
            },
            country: {
                code: 'CA',
                name: 'Canada'
            },
            locale: 'en-CA'
        },
        {
            language: {
                code: 'fr',
                name: 'French',
                native: 'Français'
            },
            country: {
                code: 'CA',
                name: 'Canada'
            },
            locale: 'fr-CA' 
        }
    ]
}

keyByLC()

import { keyByLC } from 'cldr-language-country';

const locales = keyByLC();

Result:

{
    'en': [
        {
            language: {
                code: 'en',
                name: 'English',
                native: 'English'
            },
            country: {
                code: 'AE',
                name: 'United Arab Emirates'
            },
            locale: 'en-AE'
        },
        {
            language: {
                code: 'en',
                name: 'English',
                native: 'English'
            },
            country: {
                code: 'AG',
                name: 'Antigua and Barbuda'
            },
            locale: 'en-AG'
        },
        ...continued
    ]
}

getByCC(cc)

import { getByCC } from 'cldr-language-country';

const locales = getByCC('US');

Result:

[
  {
    language: { code: 'en', name: 'English', native: 'English' },
    country: { code: 'US', name: 'United States' },
    locale: 'en-US'
  },
  {
    language: { code: 'es', name: 'Spanish', native: 'Español' },
    country: { code: 'US', name: 'United States' },
    locale: 'es-US'
  }
]

getByLC(lc)

import { getByLC } from 'cldr-language-country';

const locales = getByLC('zh');

Result:

[
  {
    language: { code: 'zh', name: 'Chinese', native: '中文' },
    country: { code: 'CN', name: 'China' },
    locale: 'zh-CN'
  },
  {
    language: { code: 'zh', name: 'Chinese', native: '中文' },
    country: { code: 'CN', name: 'China' },
    locale: 'zh-CN'
  },
  ...continued
]

getByCountryName(name)

import { getByCountryName } from 'cldr-language-country';

const locales = getByCountryName('Japan');

Result:

[
  {
    language: { code: 'en', name: 'English', native: 'English' },
    country: { code: 'JP', name: 'Japan' },
    locale: 'en-JP'
  },
  {
    language: { code: 'ja', name: 'Japanese', native: '日本語' },
    country: { code: 'JP', name: 'Japan' },
    locale: 'ja-JP'
  }
]

getByLanguageName(name)

import { getByLanguageName } from 'cldr-language-country';

const locales = getByLanguageName('Tagalog');

Result:

[
  {
    language: { code: 'tl', name: 'Tagalog / Filipino', native: 'Tagalog' },
    country: { code: 'PH', name: 'Philippines' },
    locale: 'tl-PH'
  }
]

getByLocale(locale)

import { getByLocale } from 'cldr-language-country';

const locales = getByLocale('km-KH');

Result:

[
  {
    language: { code: 'km', name: 'Khmer', native: 'ភាសាខ្មែរ' },
    country: { code: 'KH', name: 'Cambodia' },
    locale: 'km-KH'
  }
]

getByNativeName(name)

import { getByNativeName } from 'cldr-language-country';

const locales = getByNativeName('فارسی');

Result:

[
  {
    language: { code: 'fa', name: 'Persian', native: 'فارسی', rtl: 1 },
    country: { code: 'AF', name: 'Afghanistan' },
    locale: 'fa-AF'
  },
  {
    language: { code: 'fa', name: 'Persian', native: 'فارسی', rtl: 1 },
    country: { code: 'IR', name: 'Iran, Islamic Republic of' },
    locale: 'fa-IR'
  }
]

Keywords

FAQs

Package last updated on 29 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc