2019-12-08 00:32:00 +05:30
|
|
|
|
import supportedLocales from 'app/i18n';
|
2017-12-31 01:14:32 +05:30
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
|
const localeToCountryCode: Record<string, string> = {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
en: 'gb',
|
|
|
|
|
be: 'by',
|
|
|
|
|
pt: 'br',
|
|
|
|
|
uk: 'ua',
|
|
|
|
|
vi: 'vn',
|
|
|
|
|
sl: 'si',
|
|
|
|
|
sr: 'rs',
|
|
|
|
|
zh: 'cn',
|
2017-12-31 01:14:32 +05:30
|
|
|
|
};
|
2019-12-07 16:58:52 +05:30
|
|
|
|
const SUPPORTED_LANGUAGES: string[] = Object.keys(supportedLocales);
|
2017-12-31 01:14:32 +05:30
|
|
|
|
|
|
|
|
|
export default {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
getCountryList(): string[] {
|
|
|
|
|
return SUPPORTED_LANGUAGES.map((locale) => localeToCountryCode[locale] || locale);
|
|
|
|
|
},
|
2017-12-31 01:14:32 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
/**
|
|
|
|
|
* Возвращает для указанной локали её флаг с учётом всех нюансов загрузки флага
|
|
|
|
|
* и подбора соответствующего локали флага.
|
|
|
|
|
*
|
|
|
|
|
* @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 17:00:47 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
return mod.default || mod;
|
|
|
|
|
},
|
2017-12-31 01:14:32 +05:30
|
|
|
|
};
|