You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the localisation JSON maps strings 1-1. But in some languages, people may spell the country name differently.
I use this library to parse an API response into Alpha-2 codes. But, this external API sometimes uses slightly different spellings from those in this lib, but are completely valid spellings.
For instance, in Portuguese, mapping US to Estados Unidos da América is as valid as Estados Unidos.
Currently, I have to manually change the localisation file with different values, suited for my use-case or create a hard-coded matching algorithm.
I suggest we allow the possibility of accepting multiple names for a country in a given language. For instance, langs/pt.json#L72 would map to an array:
- "US": "Estados Unidos",+ "US": ["Estados Unidos", "Estados Unidos da América"],
With this proposed syntax, if I run countries.getName("US", "pt"), the lib would return me the first entry in the array ("Estados Unidos"). But, when I do the opposite, either name would be valid.
countries.getName("US","pt")// Estados Unidoscountries.getAlpha2Code("Estados Unidos da América","pt"))// UScountries.getAlpha2Code("Estados Unidos","pt"))// US
or, to avoid confusion on array ordering, we could use a more complex object:
- "US": "Estados Unidos",+ "US": {+ "default": "Estados Unidos",+ "alternatives": ["Estados Unidos da América"]+ },
Checking the current implementation, it doesn't seem difficult to accomplish. getAlpha2Code already searches the entire array of translations. It's just a matter of running
// TODO: Perform lowerCase on array or diacritics removalArray.isArray(codenames[p]) ? codenames[p].includes(name) : codenames[p]===name
The text was updated successfully, but these errors were encountered:
This is a sad breaking change. At least it's in 6.0.0.
Maybe on the readme, you could show an example that getNames might not return just a string.
I have to do something with type matching like this. It's a little painful :(
let c = countries.getNames('en');
this.options = Object.keys(c)
.filter(m => ignoreCountries.indexOf(m) === -1)
.map(code => {
let obj = c[code];
return {
id: code,
text: this.isArray(obj) ? obj[0] : obj
};
});
private isArray(c: string | string[]): c is string[] {
return Array.isArray(c);
}
Currently, the localisation JSON maps strings 1-1. But in some languages, people may spell the country name differently.
I use this library to parse an API response into Alpha-2 codes. But, this external API sometimes uses slightly different spellings from those in this lib, but are completely valid spellings.
For instance, in Portuguese, mapping US to
Estados Unidos da América
is as valid asEstados Unidos
.Currently, I have to manually change the localisation file with different values, suited for my use-case or create a hard-coded matching algorithm.
I suggest we allow the possibility of accepting multiple names for a country in a given language. For instance, langs/pt.json#L72 would map to an array:
With this proposed syntax, if I run
countries.getName("US", "pt")
, the lib would return me the first entry in the array ("Estados Unidos"
). But, when I do the opposite, either name would be valid.or, to avoid confusion on array ordering, we could use a more complex object:
Checking the current implementation, it doesn't seem difficult to accomplish.
getAlpha2Code
already searches the entire array of translations. It's just a matter of runningThe text was updated successfully, but these errors were encountered: