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',
|
2020-06-15 03:34:41 +05:30
|
|
|
|
cs: 'cz',
|
2021-03-25 09:05:45 +05:30
|
|
|
|
fil: 'ph',
|
|
|
|
|
he: 'il',
|
2017-12-31 01:14:32 +05:30
|
|
|
|
};
|
2020-07-20 17:49:15 +05:30
|
|
|
|
const SUPPORTED_LANGUAGES: ReadonlyArray<string> = Object.keys(supportedLocales);
|
2017-12-31 01:14:32 +05:30
|
|
|
|
|
2020-07-20 17:49:15 +05:30
|
|
|
|
export function getCountriesList(): string[] {
|
|
|
|
|
return SUPPORTED_LANGUAGES.map((locale) => localeToCountryCode[locale] || locale);
|
|
|
|
|
}
|
2017-12-31 01:14:32 +05:30
|
|
|
|
|
2020-07-20 17:49:15 +05:30
|
|
|
|
/**
|
|
|
|
|
* Возвращает для указанной локали её флаг с учётом всех нюансов загрузки флага
|
|
|
|
|
* и подбора соответствующего локали флага.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} locale
|
|
|
|
|
*
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
export function getLocaleIconUrl(locale: string): string {
|
2021-03-29 07:05:53 +05:30
|
|
|
|
try {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
|
return require(`flag-icon-css/flags/4x3/${localeToCountryCode[locale] || locale}.svg`).default;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (!err.message.startsWith('Cannot find module')) {
|
|
|
|
|
throw err;
|
2020-07-20 02:22:02 +05:30
|
|
|
|
}
|
2020-07-20 17:49:15 +05:30
|
|
|
|
}
|
2020-07-21 18:53:32 +05:30
|
|
|
|
|
2020-10-11 23:49:12 +05:30
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2020-07-21 18:53:32 +05:30
|
|
|
|
return require('./flags/unknown.svg').default;
|
2020-07-20 17:49:15 +05:30
|
|
|
|
}
|