Reputation: 153
I'm using npm 'country-data'. I need to display the country based on German and English language & also in alphabetical order.
this.stateOptions = [];
lodash.each(countries.all, (state) => {
if (state.status !== 'assigned') {
return;
}
console.log(state)
this.stateOptions.push({
value: state.alpha2,
label: state.name
})
});
}
Upvotes: 3
Views: 3078
Reputation: 739
Try this i18n-iso-countries. May It's will help you.
Installing Install it using npm: npm install i18n-iso-countries
var countries = require("i18n-iso-countries");
If you use i18n-iso-countries with Node.js your are done. If you use the package in a browser environment you also have to register the languages you want to use to minimize file size.
// Support french & english languages.
countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
countries.registerLocale(require("i18n-iso-countries/langs/fr.json"));
Code to Country Get the name of a country by its ISO 3166-1 Alpha-2, Alpha-3 or Numeric code // this is important
var countries = require("i18n-iso-countries");
// in a browser environment:
countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
console.log("US (Alpha-2) => " + countries.getName("US", "en")); // United States of America
console.log("US (Alpha-2) => " + countries.getName("US", "de")); // Vereinigte Staaten von Amerika
console.log("USA (Alpha-3) => " + countries.getName("USA", "en")); // United States of America
console.log("USA (Numeric) => " + countries.getName("840", "en")); /
Upvotes: 2