2019-12-07 21:02:00 +02:00
|
|
|
|
import supportedLocales from 'app/i18n';
|
2017-12-30 21:44:32 +02:00
|
|
|
|
|
2020-01-17 23:37:52 +03:00
|
|
|
|
const localeToCountryCode: Record<string, string> = {
|
2020-05-24 02:08:24 +03:00
|
|
|
|
en: 'gb',
|
|
|
|
|
be: 'by',
|
|
|
|
|
pt: 'br',
|
|
|
|
|
uk: 'ua',
|
|
|
|
|
vi: 'vn',
|
|
|
|
|
sl: 'si',
|
|
|
|
|
sr: 'rs',
|
|
|
|
|
zh: 'cn',
|
2020-06-15 01:04:41 +03:00
|
|
|
|
cs: 'cz',
|
2017-12-30 21:44:32 +02:00
|
|
|
|
};
|
2019-12-07 13:28:52 +02:00
|
|
|
|
const SUPPORTED_LANGUAGES: string[] = Object.keys(supportedLocales);
|
2017-12-30 21:44:32 +02:00
|
|
|
|
|
|
|
|
|
export default {
|
2020-05-24 02:08:24 +03:00
|
|
|
|
getCountryList(): string[] {
|
|
|
|
|
return SUPPORTED_LANGUAGES.map((locale) => localeToCountryCode[locale] || locale);
|
|
|
|
|
},
|
2017-12-30 21:44:32 +02:00
|
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает для указанной локали её флаг с учётом всех нюансов загрузки флага
|
|
|
|
|
* и подбора соответствующего локали флага.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} locale
|
|
|
|
|
*
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
getIconUrl(locale: string): string {
|
2020-07-19 23:52:02 +03:00
|
|
|
|
let mod;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mod = require(`./flags/${locale}.svg`);
|
|
|
|
|
} catch (err1) {
|
|
|
|
|
if (!err1.message.startsWith('Cannot find module')) {
|
|
|
|
|
throw err1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mod = require(`flag-icon-css/flags/4x3/${localeToCountryCode[locale] || locale}.svg`);
|
|
|
|
|
} catch (err2) {
|
|
|
|
|
if (!err2.message.startsWith('Cannot find module')) {
|
|
|
|
|
throw err2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod = require('./flags/unknown.svg');
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-25 13:30:47 +02:00
|
|
|
|
|
2020-05-24 02:08:24 +03:00
|
|
|
|
return mod.default || mod;
|
|
|
|
|
},
|
2017-12-30 21:44:32 +02:00
|
|
|
|
};
|