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,
|
||||
saveMissingTo: 'current',
|
||||
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, '\\"');
|
||||
// eslint-disable-next-line no-console
|
||||
if (console && console.group && console.log) {
|
||||
@ -35,14 +39,14 @@ i18n
|
||||
backend: {
|
||||
loadPath: '{{lng}}',
|
||||
parse: data => data,
|
||||
ajax: (lng, options, callback) => {
|
||||
ajax: async (lng, options, callback) => {
|
||||
try {
|
||||
import(`locales/${ lng }.yaml`).then(
|
||||
locale => callback(locale, { status: '200' }),
|
||||
() => callback(null, { status: '404' }));
|
||||
const { default: locale } = await import(`locales/${ lng }.yaml`);
|
||||
|
||||
callback(locale, { status: '200' });
|
||||
}
|
||||
catch (e) {
|
||||
callback(null, { status: '404' });
|
||||
callback(null, { status: '500' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user