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); |     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,15 +28,14 @@ const flagIconLoadingChain: ReadonlyArray<(locale: string) => { default: string | |||||||
|  * @returns {string} |  * @returns {string} | ||||||
|  */ |  */ | ||||||
| export function getLocaleIconUrl(locale: string): string { | export function getLocaleIconUrl(locale: string): string { | ||||||
|     for (const flagIconLoadingChainElement of flagIconLoadingChain) { |  | ||||||
|     try { |     try { | ||||||
|             return flagIconLoadingChainElement(locale).default; |         // eslint-disable-next-line @typescript-eslint/no-var-requires | ||||||
|  |         return require(`flag-icon-css/flags/4x3/${localeToCountryCode[locale] || locale}.svg`).default; | ||||||
|     } catch (err) { |     } catch (err) { | ||||||
|         if (!err.message.startsWith('Cannot find module')) { |         if (!err.message.startsWith('Cannot find module')) { | ||||||
|             throw err; |             throw err; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // eslint-disable-next-line @typescript-eslint/no-var-requires |     // eslint-disable-next-line @typescript-eslint/no-var-requires | ||||||
|     return require('./flags/unknown.svg').default; |     return require('./flags/unknown.svg').default; | ||||||
|   | |||||||
| @@ -5,14 +5,18 @@ | |||||||
| const fs = require('fs'); | const fs = require('fs'); | ||||||
| const path = require('path'); | 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/intl': 'node_modules/intl/locale-data/jsonp', | ||||||
|     'packages/app/services/i18n/overrides/pluralrules': 'node_modules/@formatjs/intl-pluralrules/dist/locale-data', |     'packages/app/services/i18n/overrides/pluralrules': 'node_modules/@formatjs/intl-pluralrules/dist/locale-data', | ||||||
|     // eslint-disable-next-line prettier/prettier |     // eslint-disable-next-line prettier/prettier | ||||||
|     'packages/app/services/i18n/overrides/relativetimeformat': 'node_modules/@formatjs/intl-relativetimeformat/dist/locale-data', |     '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.readdirSync(sourceDir).forEach((localeFile) => { | ||||||
|         fs.copyFileSync(path.join(sourceDir, localeFile), path.join(targetDir, localeFile)); |         fs.copyFileSync(path.join(sourceDir, localeFile), path.join(targetDir, localeFile)); | ||||||
|     }); |     }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user