In my Angular application I am trying to get country names in Arabic language only and keep its code in English using i18n-iso-countries library. I installed it using npm
npm -i i18n-iso-countries
Then in my component I imported it like this:
import * as i18IsoCountries from 'i18n-iso-countries';
I tried to replace en with ar but it doesn't work
getCountries(): { id: string; name: string }[] {
return Object.entries(countriesLib.getNames('ar', { select: 'official' })).map((entry) => {
return {
id: entry[0],
name: entry[1]
};
});
}
getCountry(countryKey: string): string {
return countriesLib.getName(countryKey, 'en');
}
CodePudding user response:
you have to import ar language json file
countriesLib.registerLocale(require('i18n-iso-countries/langs/ar.json'));