fix: Fixes displaying country names which has multiple names listed.

Some countries have multiple names listed in i18n-iso-countries, like US -> ['United States of America', 'USA'].
This commit is contained in:
Дамян Минков 2021-10-01 08:38:00 -05:00
parent 4369579d2b
commit 33503122c4
1 changed files with 14 additions and 3 deletions

View File

@ -66,9 +66,20 @@ class NumbersList extends Component<Props> {
(resultNumbers, number) => {
// The i18n-iso-countries package insists on upper case.
const countryCode = number.countryCode.toUpperCase();
const countryName = countryCode === 'SIP'
? t('info.sip')
: t(`countries:countries.${countryCode}`);
let countryName;
if (countryCode === 'SIP') {
countryName = t('info.sip');
} else {
countryName = t(`countries:countries.${countryCode}`);
// Some countries have multiple names as US ['United States of America', 'USA']
// choose the first one if that is the case
if (!countryName) {
countryName = t(`countries:countries.${countryCode}.0`);
}
}
if (resultNumbers[countryName]) {
resultNumbers[countryName].push(number);