@mapbox/locale-utils
v0.0.6
Published
A helper library for finding an appropriate locale from a list of available locales given an input locale.
Downloads
2,017
Maintainers
Keywords
Readme
Locale Utils
A helper library for finding an appropriate locale from a list of available locales given an input locale.
Installation
npm install @mapbox/locale-utils --save
Usage
var locale = require('@mapbox/locale-utils');
var availableLocales = [
'en-US',
'en-GB',
'es-ES',
'pt-PT',
'tr',
'zh-Hans'
];
// Find the best fitting locale given an input locale
var newLocale = locale.bestMatchingLocale('es-MX', availableLocales));
// Returns `es-ES` since `es-MX` is not an available locale.
// Parse a locale into smaller, easier to understand pieces.
var codedLocale = locale.parseLocaleIntoCodes('es-MX');
// Returns:
// {
// locale: 'es-MX',
// language: 'es',
// script: undefined,
// region: 'MX'
// }