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',
|
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 {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
|
const mod = require(`flag-icon-css/flags/4x3/${localeToCountryCode[locale] || locale}.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
|
|
|
|
};
|