diff --git a/packages/app/components/i18n/flags/eo.svg b/packages/app/components/i18n/flags/eo.svg new file mode 100644 index 0000000..806f44d --- /dev/null +++ b/packages/app/components/i18n/flags/eo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/app/components/i18n/flags/unknown.svg b/packages/app/components/i18n/flags/unknown.svg new file mode 100644 index 0000000..2eeb626 --- /dev/null +++ b/packages/app/components/i18n/flags/unknown.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/packages/app/components/i18n/localeFlags.ts b/packages/app/components/i18n/localeFlags.ts index 3e12eaa..dd233d6 100644 --- a/packages/app/components/i18n/localeFlags.ts +++ b/packages/app/components/i18n/localeFlags.ts @@ -27,8 +27,25 @@ export default { * @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`); + let mod; + + try { + mod = require(`./flags/${locale}.svg`); + } catch (err1) { + if (!err1.message.startsWith('Cannot find module')) { + throw err1; + } + + try { + mod = require(`flag-icon-css/flags/4x3/${localeToCountryCode[locale] || locale}.svg`); + } catch (err2) { + if (!err2.message.startsWith('Cannot find module')) { + throw err2; + } + + mod = require('./flags/unknown.svg'); + } + } return mod.default || mod; }, diff --git a/webpack.config.js b/webpack.config.js index 169d9ae..21d9898 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -114,6 +114,11 @@ const webpackConfig = { /flag-icon-css\/flags\/4x3/, new RegExp(`/(${localeFlags.getCountryList().join('|')})\\.svg`), ), + // @see components/i18n/localeFlags.js + new webpack.ContextReplacementPlugin( + /app\/components\/i18n\/flags/, + new RegExp(`/(${localeFlags.getCountryList().join('|')})\\.svg`), + ), ], module: {