Skip to content

Commit 2a72cb1

Browse files
fix: Adding require into try catch to simplify by catching error inside single try-catch
1 parent e74594a commit 2a72cb1

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

admin/src/index.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,20 @@ export default {
4949
bootstrap(app) {},
5050
async registerTrads({ locales }) {
5151
const importedTrads = await Promise.all(
52-
locales.map((locale) => {
53-
return import(
54-
/* webpackChunkName: "config-sync-translation-[request]" */ `./translations/${locale}.json`
55-
)
56-
.then(({ default: data }) => {
57-
return {
58-
data: prefixPluginTranslations(data, pluginId),
59-
locale,
60-
};
61-
})
62-
.catch(() => {
63-
return import(
64-
/* webpackChunkName: "config-sync-translation-[request]" */ `./translations/en.json`
65-
)
66-
.then(({ default: data }) => {
67-
return {
68-
data: prefixPluginTranslations(data, pluginId),
69-
locale,
70-
};
71-
})
72-
.catch(() => {
73-
return {
74-
data: {},
75-
locale,
76-
};
77-
});
78-
});
52+
locales.map(async (locale) => {
53+
try {
54+
// eslint-disable-next-line import/no-dynamic-require
55+
const data = require(`./translations/${locale}.json`);
56+
return {
57+
data: prefixPluginTranslations(data, pluginId),
58+
locale,
59+
};
60+
} catch {
61+
return {
62+
data: {},
63+
locale,
64+
};
65+
}
7966
}),
8067
);
8168

0 commit comments

Comments
 (0)