cloudflare-next-intl 0.10.28 → 0.10.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/src/client_messages_scan/scan_project.js +1 -1
- package/dist/src/general/pick_client_messages.d.ts +1 -1
- package/dist/src/general/pick_client_messages.js +2 -2
- package/dist/src/vite/auto_client_messages_plugin.js +7 -2
- package/dist/src/vite/plugin.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -167,17 +167,19 @@ export function Navigation() {
|
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
`IntlProvider` sends the locale's messages to the client for `useTranslations`
|
|
170
|
-
in client components.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
in client components. By default, `clientMessages: "auto"` and `autoClientMessages`
|
|
171
|
+
Vite plugin are **enabled by default** with `{ onDynamic: "fallback", fallbackNamespaces: [] }`
|
|
172
|
+
to automatically scan and ship only the namespaces your client components use.
|
|
173
|
+
|
|
174
|
+
You can customize or disable either side:
|
|
175
|
+
- Set `clientMessages: false` (server-only messages), `true` (all messages), or `["Auth", "Common", "Categories*"]` in intl config.
|
|
176
|
+
- In `vite.config.ts`, pass `autoClientMessages: false` to disable scanning, or customize options:
|
|
174
177
|
|
|
175
178
|
```ts
|
|
176
|
-
// vite.config.ts
|
|
179
|
+
// vite.config.ts (optional customization — enabled by default)
|
|
177
180
|
cloudflareNextIntl({
|
|
178
|
-
autoClientMessages: { fallbackNamespaces: ["Common"],
|
|
181
|
+
autoClientMessages: { fallbackNamespaces: ["Common"], packages: ["@my/ui"] }
|
|
179
182
|
})
|
|
180
|
-
// intl.config.ts -> setIntlConfig({ clientMessages: "auto", ... })
|
|
181
183
|
```
|
|
182
184
|
|
|
183
185
|
> UI library packages can declare `"i18n": { "namespaces": ["Buttons"] }` in `package.json` for automatic inclusion.
|
|
@@ -19,7 +19,7 @@ function walk(dir, out, skipNodeModules) {
|
|
|
19
19
|
}
|
|
20
20
|
export function scanProject(opts) {
|
|
21
21
|
const files = [];
|
|
22
|
-
for (const d of opts.dirs ?? ["src", "app", "components"]) {
|
|
22
|
+
for (const d of opts.dirs ?? ["src", "app", "components", "pages", "shared", "modules", "lib"]) {
|
|
23
23
|
const full = join(opts.root, d);
|
|
24
24
|
if (existsSync(full))
|
|
25
25
|
walk(full, files, true);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { TranslationObject } from "../types/types.js";
|
|
2
|
-
export default function pickClientMessages(messages: TranslationObject, clientMessages
|
|
2
|
+
export default function pickClientMessages(messages: TranslationObject, clientMessages?: boolean | "auto" | readonly string[] | undefined, autoManifest?: string[] | true | undefined): TranslationObject;
|
|
@@ -2,9 +2,9 @@ import { matchesNamespacePattern } from "../client_messages_scan/match_namespace
|
|
|
2
2
|
function readAutoManifest() {
|
|
3
3
|
return typeof __CFNI_CLIENT_MESSAGES__ === "undefined" ? undefined : __CFNI_CLIENT_MESSAGES__;
|
|
4
4
|
}
|
|
5
|
-
export default function pickClientMessages(messages, clientMessages, autoManifest = readAutoManifest()) {
|
|
5
|
+
export default function pickClientMessages(messages, clientMessages = "auto", autoManifest = readAutoManifest()) {
|
|
6
6
|
const list = clientMessages === "auto" ? autoManifest ?? true : clientMessages;
|
|
7
|
-
if (list ===
|
|
7
|
+
if (list === true)
|
|
8
8
|
return messages;
|
|
9
9
|
const picked = {};
|
|
10
10
|
if (list === false)
|
|
@@ -2,12 +2,17 @@ import { scanProject } from "../client_messages_scan/scan_project.js";
|
|
|
2
2
|
const KEY = "__CFNI_CLIENT_MESSAGES__";
|
|
3
3
|
const SOURCE = /\.(tsx?|jsx?|mjs)$/;
|
|
4
4
|
export function autoClientMessagesPlugin(options = {}) {
|
|
5
|
+
const opts = {
|
|
6
|
+
onDynamic: "fallback",
|
|
7
|
+
fallbackNamespaces: [],
|
|
8
|
+
...options,
|
|
9
|
+
};
|
|
5
10
|
let last = "";
|
|
6
11
|
const run = () => {
|
|
7
|
-
const manifest = scanProject({ ...
|
|
12
|
+
const manifest = scanProject({ ...opts, root: opts.root ?? process.cwd() });
|
|
8
13
|
for (const d of manifest.dynamicCalls)
|
|
9
14
|
console.warn(`[cloudflare-next-intl] dynamic useTranslations: ${d.file}:${d.line} ${d.text}`);
|
|
10
|
-
if (
|
|
15
|
+
if (opts.strict && manifest.dynamicCalls.length > 0)
|
|
11
16
|
throw new Error("[cloudflare-next-intl] Dynamic useTranslations namespaces found. Use literals, union types, or fallbackNamespaces with onDynamic: \"fallback\".");
|
|
12
17
|
console.log(manifest.namespaces === true
|
|
13
18
|
? `[cloudflare-next-intl] client messages: sending all (root or dynamic access) from ${manifest.scannedFiles} files`
|
package/dist/src/vite/plugin.js
CHANGED
|
@@ -55,7 +55,7 @@ export function cloudflareNextIntl(options = {}) {
|
|
|
55
55
|
? { root: options.root, ...options.autoImageLoader }
|
|
56
56
|
: { root: options.root }));
|
|
57
57
|
}
|
|
58
|
-
if (options.autoClientMessages) {
|
|
58
|
+
if (options.autoClientMessages !== false) {
|
|
59
59
|
plugins.push(autoClientMessagesPlugin(typeof options.autoClientMessages === "object"
|
|
60
60
|
? { root: options.root, ...options.autoClientMessages }
|
|
61
61
|
: { root: options.root }));
|