mirror of
				https://github.com/elyby/accounts-frontend.git
				synced 2025-05-31 14:11:58 +05:30 
			
		
		
		
	Fix locales flags overriding
This commit is contained in:
		| @@ -19,11 +19,6 @@ export function getCountriesList(): string[] { | ||||
|     return SUPPORTED_LANGUAGES.map((locale) => localeToCountryCode[locale] || locale); | ||||
| } | ||||
|  | ||||
| const flagIconLoadingChain: ReadonlyArray<(locale: string) => { default: string }> = [ | ||||
|     (locale) => require(`./flags/${locale}.svg`), | ||||
|     (locale) => require(`flag-icon-css/flags/4x3/${localeToCountryCode[locale] || locale}.svg`), | ||||
| ]; | ||||
|  | ||||
| /** | ||||
|  * Возвращает для указанной локали её флаг с учётом всех нюансов загрузки флага | ||||
|  * и подбора соответствующего локали флага. | ||||
| @@ -33,13 +28,12 @@ const flagIconLoadingChain: ReadonlyArray<(locale: string) => { default: string | ||||
|  * @returns {string} | ||||
|  */ | ||||
| export function getLocaleIconUrl(locale: string): string { | ||||
|     for (const flagIconLoadingChainElement of flagIconLoadingChain) { | ||||
|         try { | ||||
|             return flagIconLoadingChainElement(locale).default; | ||||
|         } catch (err) { | ||||
|             if (!err.message.startsWith('Cannot find module')) { | ||||
|                 throw err; | ||||
|             } | ||||
|     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; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -5,14 +5,18 @@ | ||||
| const fs = require('fs'); | ||||
| const path = require('path'); | ||||
|  | ||||
| const localeOverrides = { | ||||
| const overrideMap = { | ||||
|     // Override some intl definitions | ||||
|     'packages/app/services/i18n/overrides/intl': 'node_modules/intl/locale-data/jsonp', | ||||
|     'packages/app/services/i18n/overrides/pluralrules': 'node_modules/@formatjs/intl-pluralrules/dist/locale-data', | ||||
|     // eslint-disable-next-line prettier/prettier | ||||
|     'packages/app/services/i18n/overrides/relativetimeformat': 'node_modules/@formatjs/intl-relativetimeformat/dist/locale-data', | ||||
|  | ||||
|     // Override country flags | ||||
|     'packages/app/components/i18n/flags': 'node_modules/flag-icon-css/flags/4x3', | ||||
| }; | ||||
|  | ||||
| Object.entries(localeOverrides).forEach(([sourceDir, targetDir]) => { | ||||
| Object.entries(overrideMap).forEach(([sourceDir, targetDir]) => { | ||||
|     fs.readdirSync(sourceDir).forEach((localeFile) => { | ||||
|         fs.copyFileSync(path.join(sourceDir, localeFile), path.join(targetDir, localeFile)); | ||||
|     }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user