Convert lang code (ISO 639-1) to country code (ISO 3166-1 alpha-2) in Typescript

Viewed 355

I got a model file like this :

export class LangItem{
  key: string; // ISO 639-1 eg. fr or fr-be
  name: string; //label generated
  countryCode: string; //ISO 3166-1 alpha-2 eg. GB for Great Britain
}

The goal is to display a country flag by language code. The problem is when you have 'en' for 'English' I must get 'gb' or maybe 'us'. I did not find a npm package for that. Is there a tool (library) to do this with Typescript similar to this PHP project ?

0 Answers
Related