Is there a NPM package that converts language codes like this?
- en-US => USA
- ja => JPN
- pt-BR => BRA
Software Recommendations Stack Exchange is a question and answer site for people seeking specific software recommendations. It only takes a minute to sign up.
Sign up to join this communityIs there a NPM package that converts language codes like this?
You can look at this extensive package, it covers a lot of different variants
i18n-iso-countries
https://www.npmjs.com/package/i18n-iso-countries
npm install i18n-iso-countries
I've embedded this in my Localization package:
import { Language } from 'com.recoyxgroup.localization';
let {country} = Language('en-US');
country.getName('en-US'); // English (United States)
country.toString(); // en-US
Only specific languages are linked to a Country, so, currently retrieving country from less known languages would result in null. To link a country, the constructor calls at Language.js#L50 just need a second argument (ISO 3166-1 Alpha-3 country code).