Skip to content

Commit

Permalink
fix: registerTrads function (#66)
Browse files Browse the repository at this point in the history
* Fix translations

registerTrads currently returns a string as data, this is not correct. Data is now passed correctly.

Signed-off-by: Andrew Bone <[email protected]>

* Add escaping

Signed-off-by: Andrew Bone <[email protected]>

* chore: adding changeset

---------

Signed-off-by: Andrew Bone <[email protected]>
Co-authored-by: Bassel Kanso <[email protected]>
  • Loading branch information
Link2Twenty and Bassel17 authored Dec 6, 2024
1 parent bf3ede5 commit 2aa1e40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-guests-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/sdk-plugin': patch
---

fix: registerTrads function
56 changes: 18 additions & 38 deletions src/cli/commands/plugin/init/files/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,18 @@ const TYPESCRIPT: TemplateFile[] = [
});
},
async registerTrads(app: any) {
const { locales } = app;
async registerTrads({ locales }: { locales: string[] }) {
return Promise.all(
locales.map(async (locale) => {
try {
const { default: data } = await import(\`./translations/\${locale}.json\`);
const importedTranslations = await Promise.all(
(locales as string[]).map((locale) => {
return import(\`./translations/\${locale}.json\`)
.then(({ default: data }) => {
return {
data: getTranslation(data),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
return { data, locale };
} catch {
return { data: {}, locale };
}
})
);
return importedTranslations;
},
};
`,
Expand Down Expand Up @@ -203,28 +193,18 @@ const JAVASCRIPT: TemplateFile[] = [
});
},
async registerTrads(app) {
const { locales } = app;
async registerTrads({ locales }) {
return Promise.all(
locales.map(async (locale) => {
try {
const { default: data } = await import(\`./translations/\${locale}.json\`);
const importedTranslations = await Promise.all(
locales.map((locale) => {
return import(\`./translations/\${locale}.json\`)
.then(({ default: data }) => {
return {
data: getTranslation(data),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
return { data, locale };
} catch {
return { data: {}, locale };
}
})
);
return importedTranslations;
},
};
`,
Expand Down

0 comments on commit 2aa1e40

Please sign in to comment.