oleksmarkh / locale-mapper

:gb: provides locale/language normalization and fallback

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

locale-mapper

license deps test coverage code size

Motivation/goals

It was built for streamlining the process of getting a default locale based on window.navigator.language.

Status

Abandoned - not utilized anywhere anymore, but code remains valid and could be used for reference.

How does it look like?

const localeMapper = new LocaleMapper(navigator);

localeMapper.normalize();     // 'en-US'
localeMapper.normalize(true); // 'en', passing the "onlyLanguage" flag

localeMapper.fallback({
  // explicit mapping
  'de-DE': [
    'de',
    'de-DE',
    'de-AT',
  ],

  // another explicit mapping for the same family
  'de-CH': [
    'de-CH',
  ],

  // language family wildcard
  'es': [
    '*',
  ],

  // a wildcard with exclusion
  'pt-PT': [
    '*',
    '!pt-BR',
  ],
});

About

:gb: provides locale/language normalization and fallback

License:The Unlicense


Languages

Language:JavaScript 100.0%