diff --git a/.changeset/sour-camels-live.md b/.changeset/sour-camels-live.md new file mode 100644 index 0000000000..30d561934c --- /dev/null +++ b/.changeset/sour-camels-live.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +feat(dashboard): type-safe i18n for UI extensions diff --git a/packages/admin/dashboard/scripts/generate-types.js b/packages/admin/dashboard/scripts/generate-types.js index 18e154396f..5b9fb7e1bf 100644 --- a/packages/admin/dashboard/scripts/generate-types.js +++ b/packages/admin/dashboard/scripts/generate-types.js @@ -11,12 +11,17 @@ async function generateTypes() { const filePath = path.join(distDir, "index.d.ts") const fileContent = ` - declare function App(props: { - plugins?: any[] - }): JSX.Element +declare function App(props: { + plugins?: any[] +}): JSX.Element - export default App - ` +export default App + +import type enTranslation from "./en.json" +export type Resources = { + translation: typeof enTranslation +} +` // Ensure the dist directory exists if (!fs.existsSync(distDir)) { @@ -26,6 +31,13 @@ async function generateTypes() { // Write the content to the index.d.ts file fs.writeFileSync(filePath, fileContent.trim(), "utf8") + // Copy the canonical en translation for type inference + const enTranslationSrcPath = path.join( + __dirname, "../src/i18n/translations/en.json" + ) + const enTranslationDistPath = path.join(distDir, "en.json") + fs.copyFileSync(enTranslationSrcPath, enTranslationDistPath) + console.log(`File created at ${filePath}`) }