Allow the application to work without en.json file in dev environment

This commit is contained in:
ErickSkrauch 2020-06-09 21:02:03 +03:00
parent 02e767b57c
commit cd6c5fce4c
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E

View File

@ -72,6 +72,7 @@ class I18N {
locale: string;
messages: Record<string, string>;
}> {
try {
const [{ default: messages }] = await Promise.all([
import(/* webpackChunkName: "locale-[request]" */ `app/i18n/${locale}.json`),
intlPolyfill(locale),
@ -81,6 +82,25 @@ class I18N {
locale,
messages,
};
} catch (err) {
if (process.env.NODE_ENV !== 'production') {
if (err.message === "Cannot find module './en.json'") {
console.warn(
[
"Locales module for the source language isn't exists.",
'You may generate this file by running yarn i18n:extract command.',
'Until then, defaultMessages will be used for displaying on the site.',
].join(' '),
);
} else {
console.error(err);
}
return { locale, messages: {} };
}
throw err;
}
}
}