Implemented loading of custom flags for languages, not associated with concrete country.

Implemented "unknown" language flag to prevent errors for new languages when flag can't be associated automatically
This commit is contained in:
ErickSkrauch 2020-07-19 23:52:02 +03:00
parent 49698e6bda
commit 9a9bd74763
4 changed files with 34 additions and 2 deletions

View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="480">
<path fill="#FFF" d="M0 0h242v242H0"/>
<path d="M0 240h240V0h400v480H0m69.6-291.6l49.2-151.2L168 188.4 39.6 94.8h159.6" fill="#090"/>
</svg>

After

Width:  |  Height:  |  Size: 215 B

View File

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" width="640" height="480">
<path fill="#BCBCBC" d="M0 390h640v90H0z"/>
<path fill="#F2F2F2" d="M0 90h640v300H0z"/>
<path fill="#BCBCBC" d="M0 0h640v90H0z"/>
<path d="M338 281.75v28.5a4.762 4.762 0 01-4.75 4.75h-28.5a4.762 4.762 0 01-4.75-4.75v-28.5a4.762 4.762 0 014.75-4.75h28.5a4.762 4.762 0 014.75 4.75zm36.985-69.875c0 22.268-15.217 30.817-26.42 37.028-6.959 3.982-11.322 12.067-11.322 15.472 0 2.58-2.007 5.625-4.717 5.625H304.22c-2.597 0-4.242-3.983-4.242-6.563v-5.272c0-14.183 14.153-26.37 24.532-31.058 9.08-4.102 12.854-7.964 12.854-15.472 0-6.563-8.612-12.42-18.16-12.42-5.307 0-10.146 1.642-12.735 3.398-2.83 1.994-5.661 4.807-12.62 13.477-.944 1.17-2.363 1.875-3.654 1.875-1.064 0-2.008-.352-2.951-.938l-19.34-14.647c-2.007-1.523-2.475-4.102-1.177-6.21C279.461 175.193 297.39 165 321.452 165 346.694 165 375 185.04 375 211.875h-.015z" fill="#000"/>
</svg>

After

Width:  |  Height:  |  Size: 923 B

View File

@ -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;
},

View File

@ -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: {