Skip to content

Function: environmentLocales() ​

environmentLocales(environment?): string[]

Read the languages of a process environment, preferred first, as gettext does: the locale is the first of LC_ALL, LC_MESSAGES and LANG which is set; the colon-separated list of LANGUAGE comes before it, but only when that locale is set and valid (not C or POSIX). The tags are normalized (normalizeLocale), the invalid ones and the duplicates dropped.

Parameters ​

environment? ​

ProcessEnv

The environment variables: process.env by default.

Returns ​

string[]

The language tags, preferred first; empty when the environment gives none.

Example ​

typescript
import {environmentLocales} from 'lakutata/com/i18n'

console.log(environmentLocales({LANG: 'zh_CN.UTF-8', LANGUAGE: 'zh_TW:en'})) //['zh-TW', 'en', 'zh-CN']

Released under the MIT License.