Reworking i18n error logging to make it less noisy
Also changing locale loading error handling to make the backend retry on failure
This commit is contained in:
parent
cf0ec81730
commit
b774babfb9
14
src/i18n.js
14
src/i18n.js
@ -18,6 +18,10 @@ i18n
|
|||||||
saveMissing: true,
|
saveMissing: true,
|
||||||
saveMissingTo: 'current',
|
saveMissingTo: 'current',
|
||||||
missingKeyHandler: (lng, ns, key, fallback) => {
|
missingKeyHandler: (lng, ns, key, fallback) => {
|
||||||
|
if (!i18n.getResourceBundle(lng)) {
|
||||||
|
return; // Don't bother logging if the resource bundle isn't loaded
|
||||||
|
}
|
||||||
|
|
||||||
const escapedKey = key.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
const escapedKey = key.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
if (console && console.group && console.log) {
|
if (console && console.group && console.log) {
|
||||||
@ -35,14 +39,14 @@ i18n
|
|||||||
backend: {
|
backend: {
|
||||||
loadPath: '{{lng}}',
|
loadPath: '{{lng}}',
|
||||||
parse: data => data,
|
parse: data => data,
|
||||||
ajax: (lng, options, callback) => {
|
ajax: async (lng, options, callback) => {
|
||||||
try {
|
try {
|
||||||
import(`locales/${ lng }.yaml`).then(
|
const { default: locale } = await import(`locales/${ lng }.yaml`);
|
||||||
locale => callback(locale, { status: '200' }),
|
|
||||||
() => callback(null, { status: '404' }));
|
callback(locale, { status: '200' });
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
callback(null, { status: '404' });
|
callback(null, { status: '500' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user