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 dee1907
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .changeset/wet-bats-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@pluginpal/webtools-addon-redirects": patch
"@pluginpal/webtools-addon-sitemap": patch
"@pluginpal/webtools-addon-menus": patch
"@pluginpal/webtools-core": patch
---

Fix issue with the admin translations
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 dee1907

Please sign in to comment.