Skip to content

Commit

Permalink
fix: issue with translations in the plugin admin sections
Browse files Browse the repository at this point in the history
  • Loading branch information
boazpoolman committed Jan 16, 2024
1 parent 9c6e0d8 commit 6b43609
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ export default {
},
async registerTrads({ locales }: { locales: string[] }) {
const importedTrads = await Promise.all(
locales.map((locale: string) => import(
/* webpackChunkName: "sitemap-translation-[request]" */ `./translations/${locale}.json`
)
.then(({ default: data }) => ({
data: prefixPluginTranslations(data as Record<string, string>, pluginId),
locale,
}))
.catch(() => ({
data: {},
locale,
}))),
locales.map((locale) => {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const data = require(`./translations/${locale}.json`) as Record<string, string>;
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
} catch {
return {
data: {},
locale,
};
}
}),
);

return Promise.resolve(importedTrads);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ export default {
},
async registerTrads({ locales }: { locales: string[] }) {
const importedTrads = await Promise.all(
locales.map((locale: string) => import(
/* webpackChunkName: "sitemap-translation-[request]" */ `./translations/${locale}.json`
)
.then(({ default: data }) => ({
data: prefixPluginTranslations(data as Record<string, string>, pluginId),
locale,
}))
.catch(() => ({
data: {},
locale,
}))),
locales.map((locale) => {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const data = require(`./translations/${locale}.json`) as Record<string, string>;
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
} catch {
return {
data: {},
locale,
};
}
}),
);

return Promise.resolve(importedTrads);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ export default {
},
async registerTrads({ locales }: { locales: string[] }) {
const importedTrads = await Promise.all(
locales.map((locale: string) => import(
/* webpackChunkName: "sitemap-translation-[request]" */ `./translations/${locale}.json`
)
.then(({ default: data }) => ({
data: prefixPluginTranslations(data as Record<string, string>, pluginId),
locale,
}))
.catch(() => ({
data: {},
locale,
}))),
locales.map((locale) => {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const data = require(`./translations/${locale}.json`) as Record<string, string>;
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
} catch {
return {
data: {},
locale,
};
}
}),
);

return Promise.resolve(importedTrads);
Expand Down
28 changes: 16 additions & 12 deletions packages/core/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,23 @@ export default {
});
}
},
async registerTrads({ locales }) {
async registerTrads({ locales }: { locales: string[] }) {
const importedTrads = await Promise.all(
locales.map((locale: string) => import(
/* webpackChunkName: "webtools-translation-[request]" */ `./translations/${locale}.json`
)
.then(({ default: data }) => ({
data: prefixPluginTranslations(data, pluginId),
locale,
}))
.catch(() => ({
data: {},
locale,
}))),
locales.map((locale) => {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const data = require(`./translations/${locale}.json`);
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
} catch {
return {
data: {},
locale,
};
}
}),
);

return Promise.resolve(importedTrads);
Expand Down

0 comments on commit 6b43609

Please sign in to comment.