Since it's all about the data you don't need special React library. You can use just the data about the countries like here. It's in json with the following schema (I cut some fields, full example can be found here):
{
"name": {
"common": "Austria",
"official": "Republic of Austria",
"native": {
"bar": {
"official": "Republik Österreich",
"common": "Österreich"
}
}
},
"cca2": "AT",
"cca3": "AUT",
"translations": {
"deu": {"official": "Republik Österreich", "common": "Österreich"},
"fra": {"official": "République d'Autriche", "common": "Autriche"},
"ita": {"official": "Repubblica d'Austria", "common": "Austria"},
"jpn": {"official": "オーストリア共和国", "common": "オーストリア"},
"spa": {"official": "República de Austria", "common": "Austria"}
},
}
Note, that although translations section uses ISO 639-3
codes and identification section uses ISO 3166-1
codes you can easily map them because native language section uses ISO 639-3
code.
Let's say you have to show a list of predefined countries. All you have to do is to get their cca3
codes and place them in a array. Then, when you identified your user locale in ISO 639-3
format (userLoc in the following example), you can use lodash or similar library to get corresponding translations:
// userLoc - current user locale in ISO 639-3
// codesToSelect - array of country codes in ISO 3166-1 you want to show
_.map( codesToSelect, ( cca3 ) => {
let countryObject = _.find( countriesData, { 'cca3': cca3 } );
let translatedName = ( countryObject &&
countryObject.translations &&
countryObject.translations[ userLoc ] )
? countryObject.translations[ userLoc ]
: cca3
return translatedName;
} )
Note, that there might not be a translation for a specified country code so cca3 will be used as a fallback.