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',
|
2021-03-25 04:35:45 +01:00
|
|
|
|
fil: 'ph',
|
|
|
|
|
he: 'il',
|
2017-12-30 21:44:32 +02:00
|
|
|
|
};
|
2020-07-20 15:19:15 +03:00
|
|
|
|
const SUPPORTED_LANGUAGES: ReadonlyArray<string> = Object.keys(supportedLocales);
|
2017-12-30 21:44:32 +02:00
|
|
|
|
|
2020-07-20 15:19:15 +03:00
|
|
|
|
export function getCountriesList(): string[] {
|
|
|
|
|
return SUPPORTED_LANGUAGES.map((locale) => localeToCountryCode[locale] || locale);
|
|
|
|
|
}
|
2017-12-30 21:44:32 +02:00
|
|
|
|
|
2020-07-20 15:19:15 +03:00
|
|
|
|
/**
|
|
|
|
|
* Возвращает для указанной локали её флаг с учётом всех нюансов загрузки флага
|
|
|
|
|
* и подбора соответствующего локали флага.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} locale
|
|
|
|
|
*
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
export function getLocaleIconUrl(locale: string): string {
|
2021-03-29 03:35:53 +02:00
|
|
|
|
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-19 23:52:02 +03:00
|
|
|
|
}
|
2020-07-20 15:19:15 +03:00
|
|
|
|
}
|
2020-07-21 16:23:32 +03:00
|
|
|
|
|
2020-10-11 21:19:12 +03:00
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2020-07-21 16:23:32 +03:00
|
|
|
|
return require('./flags/unknown.svg').default;
|
2020-07-20 15:19:15 +03:00
|
|
|
|
}
|