diff --git a/docs/src/pages/docs/workflows/typescript.mdx b/docs/src/pages/docs/workflows/typescript.mdx index e7626f25e..b71eac8be 100644 --- a/docs/src/pages/docs/workflows/typescript.mdx +++ b/docs/src/pages/docs/workflows/typescript.mdx @@ -203,7 +203,7 @@ TypeScript currently has a [limitation](https://github.com/microsoft/TypeScript/ } ``` -2. Configure the `createMessagesDeclaration` setting in your Next.js config: +2. Configure the `createMessagesDeclarations` setting in your Next.js config: ```tsx filename="next.config.mjs" import {createNextIntlPlugin} from 'next-intl/plugin'; @@ -211,7 +211,7 @@ import {createNextIntlPlugin} from 'next-intl/plugin'; const withNextIntl = createNextIntlPlugin({ experimental: { // Provide the path to the messages that you're using in `AppConfig` - createMessagesDeclaration: './messages/en.json' + createMessagesDeclarations: ['./messages/en.json'] } // ... }); diff --git a/packages/next-intl/src/plugin/createMessagesDeclaration.tsx b/packages/next-intl/src/plugin/createMessagesDeclarations.tsx similarity index 65% rename from packages/next-intl/src/plugin/createMessagesDeclaration.tsx rename to packages/next-intl/src/plugin/createMessagesDeclarations.tsx index 692097da9..e5f300731 100644 --- a/packages/next-intl/src/plugin/createMessagesDeclaration.tsx +++ b/packages/next-intl/src/plugin/createMessagesDeclarations.tsx @@ -11,31 +11,35 @@ function runOnce(fn: () => void) { fn(); } -export default function createMessagesDeclaration(messagesPath: string) { - const fullPath = path.resolve(messagesPath); - - if (!fs.existsSync(fullPath)) { - throwError( - `\`createMessagesDeclaration\` points to a non-existent file: ${fullPath}` - ); - } - if (!fullPath.endsWith('.json')) { - throwError( - `\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${fullPath}` - ); - } - - // Keep this as a runtime check and don't replace - // this with a constant during the build process - const env = process.env['NODE_ENV'.trim()]; - +export default function createMessagesDeclarations( + messagesPaths: Array +) { // Next.js can call the Next.js config multiple // times - ensure we only run once. runOnce(() => { - compileDeclaration(messagesPath); + for (const messagesPath of messagesPaths) { + const fullPath = path.resolve(messagesPath); + + if (!fs.existsSync(fullPath)) { + throwError( + `\`createMessagesDeclaration\` points to a non-existent file: ${fullPath}` + ); + } + if (!fullPath.endsWith('.json')) { + throwError( + `\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${fullPath}` + ); + } + + // Keep this as a runtime check and don't replace + // this with a constant during the build process + const env = process.env['NODE_ENV'.trim()]; + + compileDeclaration(messagesPath); - if (env === 'development') { - startWatching(messagesPath); + if (env === 'development') { + startWatching(messagesPath); + } } }); } diff --git a/packages/next-intl/src/plugin/createNextIntlPlugin.tsx b/packages/next-intl/src/plugin/createNextIntlPlugin.tsx index bc60f83fb..c1d19de83 100644 --- a/packages/next-intl/src/plugin/createNextIntlPlugin.tsx +++ b/packages/next-intl/src/plugin/createNextIntlPlugin.tsx @@ -1,5 +1,5 @@ import type {NextConfig} from 'next'; -import createMessagesDeclaration from './createMessagesDeclaration.js'; +import createMessagesDeclarations from './createMessagesDeclarations.js'; import getNextConfig from './getNextConfig.js'; import type {PluginConfig} from './types.js'; import {warn} from './utils.js'; @@ -14,9 +14,9 @@ function initPlugin( ); } - if (pluginConfig.experimental?.createMessagesDeclaration) { - createMessagesDeclaration( - pluginConfig.experimental.createMessagesDeclaration + if (pluginConfig.experimental?.createMessagesDeclarations) { + createMessagesDeclarations( + pluginConfig.experimental.createMessagesDeclarations ); } diff --git a/packages/next-intl/src/plugin/types.tsx b/packages/next-intl/src/plugin/types.tsx index 915461238..dd632b105 100644 --- a/packages/next-intl/src/plugin/types.tsx +++ b/packages/next-intl/src/plugin/types.tsx @@ -1,6 +1,6 @@ export type PluginConfig = { requestConfig?: string; experimental?: { - createMessagesDeclaration?: string; + createMessagesDeclarations?: Array; }; };