i18next-cli 1.89.0 → 1.90.0

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.
Files changed (44) hide show
  1. package/README.md +46 -7
  2. package/dist/cjs/cli.js +8 -4
  3. package/dist/cjs/config.js +13 -12
  4. package/dist/cjs/extractor/core/extractor.js +1 -3
  5. package/dist/cjs/heuristic-config.js +51 -6
  6. package/dist/cjs/init.js +5 -0
  7. package/dist/cjs/instrumenter/core/instrumenter.js +272 -23
  8. package/dist/cjs/instrumenter/core/key-generator.js +1 -0
  9. package/dist/cjs/instrumenter/core/next-files.js +104 -0
  10. package/dist/cjs/instrumenter/core/transformer.js +97 -73
  11. package/dist/cjs/localize/agent-prompt.js +5 -2
  12. package/dist/cjs/localize/detect.js +1 -0
  13. package/dist/cjs/localize/localize.js +25 -4
  14. package/dist/esm/cli.js +8 -4
  15. package/dist/esm/config.js +13 -12
  16. package/dist/esm/extractor/core/extractor.js +1 -3
  17. package/dist/esm/heuristic-config.js +52 -7
  18. package/dist/esm/init.js +5 -0
  19. package/dist/esm/instrumenter/core/instrumenter.js +273 -24
  20. package/dist/esm/instrumenter/core/key-generator.js +1 -0
  21. package/dist/esm/instrumenter/core/next-files.js +101 -0
  22. package/dist/esm/instrumenter/core/transformer.js +97 -73
  23. package/dist/esm/localize/agent-prompt.js +5 -2
  24. package/dist/esm/localize/detect.js +1 -0
  25. package/dist/esm/localize/localize.js +25 -4
  26. package/package.json +1 -1
  27. package/types/cli.d.ts.map +1 -1
  28. package/types/config.d.ts.map +1 -1
  29. package/types/extractor/core/extractor.d.ts.map +1 -1
  30. package/types/heuristic-config.d.ts.map +1 -1
  31. package/types/init.d.ts.map +1 -1
  32. package/types/instrumenter/core/instrumenter.d.ts.map +1 -1
  33. package/types/instrumenter/core/key-generator.d.ts.map +1 -1
  34. package/types/instrumenter/core/next-files.d.ts +25 -0
  35. package/types/instrumenter/core/next-files.d.ts.map +1 -0
  36. package/types/instrumenter/core/transformer.d.ts +6 -0
  37. package/types/instrumenter/core/transformer.d.ts.map +1 -1
  38. package/types/localize/agent-prompt.d.ts +1 -1
  39. package/types/localize/agent-prompt.d.ts.map +1 -1
  40. package/types/localize/detect.d.ts +2 -0
  41. package/types/localize/detect.d.ts.map +1 -1
  42. package/types/localize/localize.d.ts.map +1 -1
  43. package/types/types.d.ts +39 -0
  44. package/types/types.d.ts.map +1 -1
@@ -1,6 +1,18 @@
1
1
  import MagicString from 'magic-string';
2
2
  import { generateKeyFromContent } from './key-generator.js';
3
3
 
4
+ /** The hook a component gets `t` from, and where `useTranslation`/`useT`/`getT` and `Trans` are imported from. */
5
+ function bindingsFor(next) {
6
+ switch (next?.kind) {
7
+ case 'server': return { hook: 'getT', hookModule: next.serverModule, transModule: 'react-i18next/TransWithoutContext', call: args => `await getT(${args})` };
8
+ // its `t` is a prop: no hook; a <Trans> without context works on both sides
9
+ case 'shared':
10
+ case 'unknown': return { hook: 'useT', hookModule: 'next-i18next/client', transModule: 'react-i18next/TransWithoutContext', call: args => `useT(${args})` };
11
+ case 'client': return { hook: 'useT', hookModule: 'next-i18next/client', transModule: 'next-i18next/client', call: args => `useT(${args})` };
12
+ case 'pages': return { hook: 'useTranslation', hookModule: 'next-i18next/pages', transModule: 'next-i18next/pages', call: args => `useTranslation(${args})` };
13
+ default: return { hook: 'useTranslation', hookModule: 'react-i18next', transModule: 'react-i18next', call: args => `useTranslation(${args})` };
14
+ }
15
+ }
4
16
  /**
5
17
  * Transforms a source file, replacing candidate strings with instrumented code.
6
18
  * Also injects useTranslation() hooks into React function components that
@@ -21,6 +33,10 @@ function transformFile(content, file, candidates, options) {
21
33
  importAdded: false,
22
34
  hookInjected: false
23
35
  };
36
+ const bindings = bindingsFor(options.next);
37
+ // A <Trans> in a Server Component has no React context: it takes `t` and `i18n` from getT()
38
+ // (and in a component that Server and Client Components both render, from its props)
39
+ const transProps = ['server', 'shared', 'unknown'].includes(options.next?.kind ?? '') ? ' t={t} i18n={i18n}' : '';
24
40
  // <Trans> attributes in the quotes the file's JSX attributes use (`title='…'` or `title="…"`)
25
41
  // (a file without quoted attributes: the quotes of its imports)
26
42
  const singleQuoted = (single, double) => Math.sign((content.match(single)?.length ?? 0) - (content.match(double)?.length ?? 0));
@@ -83,7 +99,7 @@ function transformFile(content, file, candidates, options) {
83
99
  // <Trans> works in any render code, a helper outside a component too; without React the text stays
84
100
  if (candidate.type === 'jsx-mixed' && !options.hasReact)
85
101
  continue;
86
- const replacement = buildReplacement(candidate, key, useHookStyle, nsForReplacement, jsxQuote);
102
+ const replacement = buildReplacement(candidate, key, useHookStyle, nsForReplacement, jsxQuote, transProps);
87
103
  if (replacement) {
88
104
  s.overwrite(candidate.offset, candidate.endOffset, replacement);
89
105
  transformCount++;
@@ -92,8 +108,9 @@ function transformFile(content, file, candidates, options) {
92
108
  if (candidate.type === 'jsx-mixed') {
93
109
  hasTransCandidates = true;
94
110
  }
95
- // jsx-mixed candidates use <Trans>, not t(), so they need neither useTranslation nor i18next
96
- if (candidate.type !== 'jsx-mixed') {
111
+ // jsx-mixed candidates use <Trans>, not t(), so they need neither useTranslation nor i18next (but in a
112
+ // Server Component its `t` and `i18n`)
113
+ if (candidate.type !== 'jsx-mixed' || (transProps && candidate.insideComponent)) {
97
114
  if (candidate.insideComponent) {
98
115
  transformedComponents.add(candidate.insideComponent);
99
116
  }
@@ -125,10 +142,6 @@ function transformFile(content, file, candidates, options) {
125
142
  const components = options.components || [];
126
143
  // Inject useTranslation() hooks into affected React components
127
144
  if (options.hasReact && transformedComponents.size > 0) {
128
- // Process components in reverse order of bodyStart to avoid offset shifts
129
- const affectedComponents = components
130
- .filter(c => transformedComponents.has(c.name) && !c.hasUseTranslation)
131
- .sort((a, b) => b.bodyStart - a.bodyStart);
132
145
  const addHookLine = (comp, line) => {
133
146
  const indent = comp.expressionBody ? lineIndent(content, comp.bodyStart) + ' ' : detectIndent(content, comp.bodyStart);
134
147
  if (comp.expressionBody) {
@@ -139,60 +152,58 @@ function transformFile(content, file, candidates, options) {
139
152
  else {
140
153
  s.appendRight(comp.bodyStart + 1, `\n${indent}${line}`);
141
154
  }
155
+ // getT() is awaited: a Server Component becomes async, and `export const metadata = {…}` the function
156
+ // Next.js calls instead, `export async function generateMetadata () { …; return {…} }`
157
+ if (comp.metadataHead) {
158
+ const { start, end, type } = comp.metadataHead;
159
+ // contentOnly: the block that wraps the object starts at `end`, and stays
160
+ s.overwrite(start, end, `async function generateMetadata ()${type ? `: Promise<${type}>` : ''} `, { contentOnly: true });
161
+ }
162
+ else if (options.next?.kind === 'server' && !comp.isAsync && comp.start !== undefined) {
163
+ s.appendLeft(comp.start, 'async ');
164
+ // an async function returns a promise: `(): JSX.Element` becomes `(): Promise<JSX.Element>`
165
+ const type = comp.returnType;
166
+ if (type && !/^Promise\s*</.test(content.slice(type.start, type.end))) {
167
+ s.appendLeft(type.start, 'Promise<');
168
+ s.appendRight(type.end, '>');
169
+ }
170
+ }
142
171
  injections.hookInjected = true;
143
172
  };
144
- for (const comp of affectedComponents) {
173
+ // Components in reverse order of bodyStart to avoid offset shifts
174
+ for (const comp of components.filter(c => transformedComponents.has(c.name)).sort((a, b) => b.bodyStart - a.bodyStart)) {
145
175
  const defaultNS = options.config.extract?.defaultNS ?? 'translation';
146
176
  const nsArg = (options.namespace && options.namespace !== defaultNS) ? `'${options.namespace}'` : '';
147
- // Build destructuring: include `t` if the component has string candidates
148
- // (but not jsx-mixed which use <Trans>),
149
- // include `i18n` if the component has language-change sites.
150
- const needsT = highConfidenceCandidates.some(c => c.insideComponent === comp.name && c.type !== 'jsx-mixed');
151
- const needsI18n = componentsNeedingI18n.has(comp.name);
152
- const parts = [];
153
- if (needsT)
154
- parts.push('t');
155
- if (needsI18n)
156
- parts.push('i18n');
157
- // Skip if component needs neither t nor i18n
158
- // (e.g. component only has jsx-mixed / <Trans> candidates)
159
- if (!needsT && !needsI18n)
177
+ // `t` for its t() calls (and a <Trans> in a Server Component), `i18n` for a language change (and that <Trans>)
178
+ const own = highConfidenceCandidates.filter(c => c.insideComponent === comp.name);
179
+ const needsT = !comp.hasUseTranslation && own.some(c => c.type !== 'jsx-mixed' || transProps);
180
+ const needsI18n = componentsNeedingI18n.has(comp.name) || (!!transProps && !comp.i18nParam && own.some(c => c.type === 'jsx-mixed'));
181
+ const missing = [needsT && 't', needsI18n && !comp.hookPattern?.names.includes('i18n') && 'i18n'].filter(Boolean);
182
+ if (!missing.length)
160
183
  continue;
161
- addHookLine(comp, `const { ${parts.join(', ')} } = useTranslation(${nsArg})`);
162
- }
163
- // For components that already have useTranslation but need i18n added,
164
- // try to upgrade `const { t } = useTranslation(...)` → `const { t, i18n } = useTranslation(...)`
165
- if (componentsNeedingI18n.size > 0) {
166
- const compsWithExistingHook = components.filter(c => componentsNeedingI18n.has(c.name) && c.hasUseTranslation);
167
- for (const comp of compsWithExistingHook) {
168
- // Search for the destructuring pattern within the component body
169
- const bodyText = content.slice(comp.bodyStart, comp.bodyEnd);
170
- // Skip if i18n is already destructured
171
- if (/const\s*\{[^}]*\bi18n\b[^}]*\}\s*=\s*useTranslation/.test(bodyText))
172
- continue;
173
- // Match `{ t }` or `{ t, ... }` in `const { t } = useTranslation`
174
- const hookRe = /const\s*\{\s*t\s*\}\s*=\s*useTranslation/;
175
- const hookMatch = hookRe.exec(bodyText);
176
- if (hookMatch) {
177
- const absStart = comp.bodyStart + hookMatch.index;
178
- const absEnd = absStart + hookMatch[0].length;
179
- const upgraded = hookMatch[0].replace(/\{\s*t\s*\}/, '{ t, i18n }');
180
- s.overwrite(absStart, absEnd, upgraded);
181
- }
182
- else {
183
- // its `t` is a prop or comes from another hook: `i18n` needs a hook of its own
184
- addHookLine(comp, 'const { i18n } = useTranslation()');
185
- }
184
+ // that call gives `t` only to the code after it: a text before it would read `t` before its declaration
185
+ const before = (offset) => offset < comp.hookPattern.statement;
186
+ const usedBefore = comp.hookPattern && (own.some(c => before(c.offset)) ||
187
+ languageChangeSites.some(site => site.insideComponent === comp.name && before(site.callStart)));
188
+ if (comp.hookPattern && !usedBefore && (comp.hasUseTranslation || !comp.hookPattern.names.includes('t'))) {
189
+ // it calls a translation hook already (`const { i18n } = useT('ns')`): that call gives them, from its
190
+ // namespace (`{ t, i18n }`)
191
+ if (missing.includes('t'))
192
+ s.appendLeft(comp.hookPattern.first, 't, ');
193
+ if (missing.includes('i18n'))
194
+ s.appendRight(comp.hookPattern.last, ', i18n');
195
+ }
196
+ else {
197
+ addHookLine(comp, `const { ${missing.join(', ')} } = ${bindings.call(missing.includes('t') ? nsArg : '')}`);
186
198
  }
187
199
  }
188
200
  }
189
201
  // Add import statements
190
- addImportStatements(s, content, {
202
+ addImportStatements(s, content, [
191
203
  // only for a hook injected here: a component with a `t` of its own (a prop) needs none
192
- needsUseTranslation: injections.hookInjected,
193
- needsI18next: hasNonComponentCandidates || !options.hasReact,
194
- needsTrans: hasTransCandidates && options.hasReact
195
- }, options.imports);
204
+ ...(injections.hookInjected ? [{ name: bindings.hook, module: bindings.hookModule }] : []),
205
+ ...(hasTransCandidates && options.hasReact ? [{ name: 'Trans', module: bindings.transModule }] : [])
206
+ ], hasNonComponentCandidates || !options.hasReact, options.imports);
196
207
  injections.importAdded = true;
197
208
  }
198
209
  // Warn when i18next.t() is used in React projects (translations may not be loaded yet)
@@ -224,7 +235,7 @@ function transformFile(content, file, candidates, options) {
224
235
  * @param useHookStyle - If true, uses t() (from useTranslation hook); otherwise uses i18next.t()
225
236
  * @param namespace - Optional namespace (only set when different from defaultNS)
226
237
  */
227
- function buildReplacement(candidate, key, useHookStyle, namespace, jsxQuote = '"') {
238
+ function buildReplacement(candidate, key, useHookStyle, namespace, jsxQuote = '"', transProps = '') {
228
239
  const tFunc = useHookStyle ? 't' : 'i18next.t';
229
240
  const escapedContent = escapeString(candidate.content);
230
241
  // ── Plural form: t('key', { defaultValue_zero: '…', …, count: expr }) ──
@@ -275,7 +286,7 @@ function buildReplacement(candidate, key, useHookStyle, namespace, jsxQuote = '"
275
286
  return `{${tCall}}`;
276
287
  case 'jsx-mixed': {
277
288
  const nsAttr = namespace ? ` ns=${jsxQuote}${namespace}${jsxQuote}` : '';
278
- return `<Trans i18nKey=${jsxQuote}${key}${jsxQuote}${nsAttr}>${candidate.content}</Trans>`;
289
+ return `<Trans i18nKey=${jsxQuote}${key}${jsxQuote}${nsAttr}${transProps}>${candidate.content}</Trans>`;
279
290
  }
280
291
  case 'template-literal':
281
292
  case 'string-literal':
@@ -333,33 +344,33 @@ function detectIndent(content, braceOffset) {
333
344
  return ' ';
334
345
  }
335
346
  /**
336
- * Adds necessary import statements (useTranslation, Trans, and/or i18next).
347
+ * Adds the import statements the rewrite needs: the named imports `needed` (a hook, `Trans`), each from its module
348
+ * (added to an import of that module the file has), and `i18next` for `i18next.t()`.
337
349
  */
338
- function addImportStatements(s, content, needs, imports) {
350
+ function addImportStatements(s, content, needed, needsI18next, imports) {
339
351
  let importStatement = '';
340
352
  const imported = (moduleName) => imports
341
353
  ? imports.some(i => i.source === moduleName) || new RegExp(`require\\(['"]${moduleName}['"]\\)`).test(content)
342
354
  : hasImport(content, moduleName);
343
355
  // A name the file imports already, from any module (`useTranslation` re-exported by a shared package)
344
356
  const bound = (name) => !!imports?.some(i => i.locals?.includes(name));
345
- // Build a combined react-i18next import
346
- const reactI18nextImports = [];
347
- if (needs.needsUseTranslation && !bound('useTranslation'))
348
- reactI18nextImports.push('useTranslation');
349
- if (needs.needsTrans && !bound('Trans'))
350
- reactI18nextImports.push('Trans');
351
- if (reactI18nextImports.length > 0) {
352
- if (!imported('react-i18next')) {
353
- importStatement += `import { ${reactI18nextImports.join(', ')} } from 'react-i18next'\n`;
357
+ const byModule = new Map();
358
+ for (const { name, module } of needed) {
359
+ if (!bound(name))
360
+ byModule.set(module, [...(byModule.get(module) ?? []), name]);
361
+ }
362
+ for (const [module, names] of byModule) {
363
+ if (!imported(module)) {
364
+ importStatement += `import { ${names.join(', ')} } from '${module}'\n`;
354
365
  }
355
366
  else {
356
- // react-i18next is already imported — augment with any missing named exports
357
- const existing = imports?.find(i => i.source === 'react-i18next');
358
- augmentReactI18nextImport(s, content, reactI18nextImports, existing?.start ?? 0);
367
+ // the module is imported already: augment it with the missing named exports
368
+ const existing = imports?.find(i => i.source === module);
369
+ augmentNamedImport(s, content, module, names, existing?.start ?? 0);
359
370
  }
360
371
  }
361
372
  // `i18next.t()` needs that name: with the AST, an import of i18next under another name does not count
362
- if (needs.needsI18next && (imports ? !bound('i18next') : !imported('i18next'))) {
373
+ if (needsI18next && (imports ? !bound('i18next') : !imported('i18next'))) {
363
374
  importStatement += "import i18next from 'i18next'\n";
364
375
  }
365
376
  if (!importStatement)
@@ -370,6 +381,13 @@ function addImportStatements(s, content, needs, imports) {
370
381
  if (content.startsWith('#!')) {
371
382
  insertPos = content.indexOf('\n') + 1;
372
383
  }
384
+ // and the directives (`'use client'`), which must stay the first statements
385
+ const directives = DIRECTIVES_RE.exec(content.slice(insertPos));
386
+ if (directives) {
387
+ insertPos += directives[0].length;
388
+ if (content[insertPos - 1] !== '\n')
389
+ importStatement = `\n${importStatement}`;
390
+ }
373
391
  if (imports) {
374
392
  // After the last import declaration's line
375
393
  const lastEnd = Math.max(...imports.map(i => i.end), -1);
@@ -399,6 +417,8 @@ function addImportStatements(s, content, needs, imports) {
399
417
  importStatement = `\n${importStatement}`;
400
418
  s.appendRight(insertPos, importStatement);
401
419
  }
420
+ /** The directive prologue: `'use client'`, `'use strict'` and the like, with the comments around them, to the line end. */
421
+ const DIRECTIVES_RE = /^(?:(?:\s|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*(['"])use [\w ]+\1;?[^\S\n]*(?:\/\/[^\n]*)?(?:\n|$))+/;
402
422
  /**
403
423
  * Returns the offset just past the end of the import statement that begins at
404
424
  * `start`, handling multi-line imports with `{ ... }` clauses. The statement
@@ -447,21 +467,25 @@ function findImportStatementEnd(content, start) {
447
467
  return content.length;
448
468
  }
449
469
  /**
450
- * Augments an existing `import { ... } from 'react-i18next'` with any missing
470
+ * Augments an existing `import { ... } from '<module>'` with any missing
451
471
  * named exports (e.g. adds `Trans` when only `useTranslation` is imported).
472
+ * A module imported without braces (`import i18n from …`) gets its own import.
452
473
  */
453
- function augmentReactI18nextImport(s, content, needed, from = 0) {
454
- const importRegex = /import\s*\{([^}]*)\}\s*from\s*['"]react-i18next['"]/g;
474
+ function augmentNamedImport(s, content, module, needed, from = 0) {
475
+ const quoted = module.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
476
+ const importRegex = new RegExp(`import\\s*\\{([^}]*)\\}\\s*from\\s*['"]${quoted}['"]`, 'g');
455
477
  importRegex.lastIndex = from;
456
478
  const importMatch = importRegex.exec(content);
457
- if (!importMatch)
479
+ if (!importMatch) {
480
+ s.prependLeft(from, `import { ${needed.join(', ')} } from '${module}'\n`);
458
481
  return;
482
+ }
459
483
  const existingImports = importMatch[1].split(',').map(x => x.trim()).filter(Boolean);
460
484
  const toAdd = needed.filter(n => !existingImports.includes(n));
461
485
  if (toAdd.length === 0)
462
486
  return;
463
487
  const newImports = [...existingImports, ...toAdd].join(', ');
464
- const newImportStatement = `import { ${newImports} } from 'react-i18next'`;
488
+ const newImportStatement = `import { ${newImports} } from '${module}'`;
465
489
  const matchStart = importMatch.index;
466
490
  const matchEnd = matchStart + importMatch[0].length;
467
491
  s.overwrite(matchStart, matchEnd, newImportStatement);
@@ -50,8 +50,11 @@ all commands.
50
50
  for future agent sessions.
51
51
  3. Instrument: run \`npx i18next-cli instrument --dry-run\` and review the
52
52
  planned changes; then \`npx i18next-cli instrument\` to apply. Inspect the
53
- git diff carefully: fix any t() wrapping inside Next.js *server components*
54
- (add 'use client' or refactor to a server-side t() pattern). Commit.
53
+ git diff carefully and the warnings it prints. In a Next.js app it writes
54
+ next-i18next's calls (await getT() in Server Components, useT() in Client
55
+ Components); texts it left (components that Server and Client Components
56
+ both render, texts outside components) are listed: move them or give the
57
+ component a t prop. If it printed next-i18next setup steps, do them. Commit.
55
58
  4. Extract: run \`npx i18next-cli extract\`. Verify the locale JSON files were
56
59
  written (check the extract.output path in the config). If the developer
57
60
  chose repository files only: translate the extracted keys yourself or
@@ -47,6 +47,7 @@ async function detectStack(findInitFile) {
47
47
  initFile: await findInitFile(),
48
48
  hasAppRouter,
49
49
  hasParaglide,
50
+ usesNextI18next: framework === 'next' && (has('next-i18next') || !(has('i18next') || has('react-i18next'))),
50
51
  };
51
52
  }
52
53
  /** File extensions associated with frameworks the instrumenter cannot transform natively. */
@@ -134,12 +134,33 @@ function printCompleteness(completeness) {
134
134
  console.log(styleText(color, ` ${locale}: ${translated}/${total} (${pct}%)`));
135
135
  }
136
136
  }
137
- function printEpilogue(config) {
137
+ function printEpilogue(config, nextApp = false) {
138
138
  const projectId = config.locize?.projectId || '<your-project-id>';
139
139
  console.log(styleText('green', '\n✅ Done. Your app is localized.'));
140
140
  console.log(styleText('cyan', '\nYour AI translations come with confidence scores; low-confidence ones are flagged for review in Locize.'));
141
141
  console.log('\nOptional — switch to CDN delivery so translation fixes go live without redeploying your app:');
142
142
  console.log(styleText('cyan', ' npm install i18next-locize-backend'));
143
+ if (nextApp) {
144
+ // next-i18next takes the backend in its config (and, for the browser, in I18nProvider's `use`: see the docs)
145
+ console.log(styleText('gray', `
146
+ // in your next-i18next config (i18n.config):
147
+ import LocizeBackend from 'i18next-locize-backend'
148
+
149
+ export default defineConfig({
150
+ // ...
151
+ use: [LocizeBackend],
152
+ i18nextOptions: {
153
+ backend: {
154
+ projectId: '${projectId}',
155
+ version: 'latest', // no apiKey in production!
156
+ },
157
+ },
158
+ })
159
+ `));
160
+ console.log('Docs: https://github.com/i18next/next-i18next#i18next-locize-backend');
161
+ console.log('Your current setup (local translation files) keeps working either way; run `i18next-cli locize-download` in CI to refresh the files.');
162
+ return;
163
+ }
143
164
  console.log(styleText('gray', `
144
165
  // in your i18n init file:
145
166
  import LocizeBackend from 'i18next-locize-backend'
@@ -264,8 +285,8 @@ async function runLocalize(options = {}, configPath) {
264
285
  if (!proceed)
265
286
  skipInstrument = true;
266
287
  }
267
- if (stack.hasAppRouter) {
268
- warn("Next.js App Router detected: instrument injects useTranslation(), which is client-only. Review the diff for server components — add 'use client' or switch those to a server-side t() pattern.");
288
+ if (stack.usesNextI18next) {
289
+ warn('Next.js: instrument writes next-i18next calls, await getT() in Server Components and useT() in Client Components. Review the diff and the texts it lists as left.');
269
290
  }
270
291
  if (!skipInstrument) {
271
292
  const results = await runInstrumenter(config, {
@@ -466,7 +487,7 @@ async function runLocalize(options = {}, configPath) {
466
487
  else if (completeness.length > 0) {
467
488
  ok('All languages translated and downloaded.');
468
489
  }
469
- printEpilogue(config);
490
+ printEpilogue(config, stack.usesNextI18next);
470
491
  }
471
492
 
472
493
  export { runLocalize };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.89.0",
3
+ "version": "1.90.0",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAqBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAkiB7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAqBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAqiB7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAc9D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAEhF;AAgCD;;;;;GAKG;AACH,wBAAsB,UAAU,CAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CA+CjI;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8B5H;AAyBD;;;GAGG;AACH,wBAAsB,kBAAkB,IAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB3E"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAc9D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAEhF;AAgCD;;;;;GAKG;AACH,wBAAsB,UAAU,CAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CA+CjI;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8B5H;AA0BD;;;GAGG;AACH,wBAAsB,kBAAkB,IAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB3E"}
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/extractor.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAO5G,OAAO,EAAE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,EAAE,WAAW,EACxB,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,MAAM,GAAE,MAA4B,EACpC,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,IAAI,CAAC,CA4Df;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,OAAO,CAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE,uBAA+B,EAAE,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAO1K"}
@@ -1 +1 @@
1
- {"version":3,"file":"heuristic-config.d.ts","sourceRoot":"","sources":["../src/heuristic-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AA+CtD;;;;;;GAMG;AACH,wBAAsB,YAAY,IAAK,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CA6DnF"}
1
+ {"version":3,"file":"heuristic-config.d.ts","sourceRoot":"","sources":["../src/heuristic-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAyFtD;;;;;;GAMG;AACH,wBAAsB,YAAY,IAAK,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CAyDnF"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AA+DA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,WAAW;IAC1B,qFAAqF;IACrF,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,0GAA0G;IAC1G,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kLAAkL;IAClL,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;IACtC,kHAAkH;IAClH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IACtB,iGAAiG;IACjG,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,wBAAsB,OAAO,CAAE,OAAO,GAAE,WAAgB,iBAuPvD"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AA+DA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,WAAW;IAC1B,qFAAqF;IACrF,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,0GAA0G;IAC1G,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kLAAkL;IAClL,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;IACtC,kHAAkH;IAClH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IACtB,iGAAiG;IACjG,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,wBAAsB,OAAO,CAAE,OAAO,GAAE,WAAgB,iBA4PvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"instrumenter.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/core/instrumenter.ts"],"names":[],"mappings":"A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s3ED;;GAEG;AACH,wBAAsB,mBAAmB,IAAK,OAAO,CAAC,OAAO,CAAC,CAG7D;AAID,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,CAAA;AA6B/E;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,IAAK,OAAO,CAAC,kBAAkB,CAAC,CAwB7E;AAED;;GAEG;AACH,wBAAsB,wBAAwB,IAAK,OAAO,CAAC,OAAO,CAAC,CAOlE;AAwBD;;;;;;GAMG;AACH,wBAAsB,wBAAwB,IAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxE;AAgZD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,eAAe,EAAE,EAC7B,MAAM,EAAE,oBAAoB,EAC5B,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,IAAI,CAAC,CAoDf"}
@@ -1 +1 @@
1
- {"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/core/key-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAwB/D;AAKD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzB,GAAG,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1C,2GAA2G;IAC3G,OAAO,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9C;AAKD;;GAEG;AACH,wBAAgB,iBAAiB,IAAK,WAAW,CAsChD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAWhD"}
1
+ {"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/core/key-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAyB/D;AAKD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzB,GAAG,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1C,2GAA2G;IAC3G,OAAO,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9C;AAKD;;GAEG;AACH,wBAAgB,iBAAiB,IAAK,WAAW,CAsChD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAWhD"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Where a file of a Next.js app renders, for next-i18next: `server` for Server Components (`await getT()`),
3
+ * `client` for Client Components of the App Router (`useT()`), `pages` for the Pages Router (`useTranslation()`
4
+ * from `next-i18next/pages`), `shared` for a file that Server and Client Components both import, where neither works,
5
+ * `unknown` for a file of an App Router app that no route imports (as far as its imports resolve).
6
+ */
7
+ export type NextFileKind = 'server' | 'client' | 'pages' | 'shared' | 'unknown';
8
+ /** A file's path in the project, `/`-separated, without a leading `src/`: `app/page.tsx`, `pages/api/hello.js`. */
9
+ export declare function projectPath(file: string, cwd?: string): string;
10
+ /**
11
+ * Classifies the files of a Next.js app by the components that render them, from the import graph: a file under
12
+ * `app/` is a Server Component unless it says `'use client'`; a `'use client'` file and all it imports are Client
13
+ * Components; a file under `pages/` and all it imports render with the Pages Router. Imports resolve relative,
14
+ * through the tsconfig `paths`, from the project root (a `baseUrl` import, `components/Card`) and with the `.js`
15
+ * of an ESM import for a `.ts` file; only the given files count.
16
+ *
17
+ * @param contents - The files' contents by path (relative to `cwd` or absolute)
18
+ * @returns The kind of each file and the files it imports, by the paths they were given with; a file nothing
19
+ * reaches is `unknown` (`pages` in an app without `app/`)
20
+ */
21
+ export declare function classifyNextFiles(contents: Map<string, string>, cwd?: string): Promise<{
22
+ kinds: Map<string, NextFileKind>;
23
+ imports: Map<string, string[]>;
24
+ }>;
25
+ //# sourceMappingURL=next-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-files.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/core/next-files.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;AA0B/E,mHAAmH;AACnH,wBAAgB,WAAW,CAAE,IAAI,EAAE,MAAM,EAAE,GAAG,SAAgB,GAAG,MAAM,CAEtE;AAQD;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,SAAgB,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAqD1K"}
@@ -1,4 +1,5 @@
1
1
  import type { I18nextToolkitConfig, CandidateString, TransformResult, ComponentBoundary, ImportDeclarationSpan, LanguageChangeSite, MemoHookSpan, PluralHelperImport } from '../../types.js';
2
+ import type { NextFileKind } from './next-files.js';
2
3
  interface TransformerOptions {
3
4
  isDryRun?: boolean;
4
5
  hasReact: boolean;
@@ -19,6 +20,11 @@ interface TransformerOptions {
19
20
  memoHooks?: MemoHookSpan[];
20
21
  /** The imported plural helpers the candidates call: an import whose every use was rewritten goes */
21
22
  pluralHelperImports?: PluralHelperImport[];
23
+ /** A file of a next-i18next app: where it renders, and the module its Server Components import `getT` from */
24
+ next?: {
25
+ kind: NextFileKind;
26
+ serverModule: string;
27
+ };
22
28
  }
23
29
  /**
24
30
  * Transforms a source file, replacing candidate strings with instrumented code.
@@ -1 +1 @@
1
- {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/core/transformer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAG5L,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,qBAAqB,EAAE,OAAO,CAAA;IAC9B,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAA;IAC7C,6EAA6E;IAC7E,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAA;IAChC,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAA;IAC1C;;;OAGG;IACH,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAA;IACjC,kHAAkH;IAClH,SAAS,CAAC,EAAE,YAAY,EAAE,CAAA;IAC1B,oGAAoG;IACpG,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAA;CAC3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,eAAe,EAAE,EAC7B,OAAO,EAAE,kBAAkB,GAC1B,eAAe,CA0NjB;AAqRD;;GAEG;AACH,wBAAgB,YAAY,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAwB1F"}
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/core/transformer.ts"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: grep for it across the
25
25
  * i18next and Locize repositories before renaming.
26
26
  */
27
- export declare const AGENT_PROMPT = "You are localizing this app with i18next. Locize, the translation management\nservice by the i18next maintainers, is optional: the developer decides in\nstep 2 and nothing Locize-related happens unless they say yes. Execute these\nsteps in order, verifying each before continuing. Use `npx i18next-cli` for\nall commands.\n\n1. Detect: confirm this is a React/Next.js project (check package.json).\n - If Vue/Svelte: install a stack plugin (`i18next-cli-vue` /\n `i18next-cli-plugin-svelte`) and add it to the `plugins` array of\n i18next.config.ts, or write one via the plugin hooks\n (instrumentOnLoad/onLoad) instead of wrapping strings manually.\n - If the app uses inlang Paraglide (`@inlang/paraglide-js`), STOP:\n instrumenting i18next calls would conflict; ask the user how to proceed.\n2. Ask, then configure: if no i18next.config.{ts,js} exists, ask the\n developer one question before anything else: \"Do you want to manage the\n translations with Locize (AI pre-translation with review, CDN delivery\n without redeploying, free plan available), or keep the translation files\n in the repository only?\" Then create the config without the wizard:\n `npx i18next-cli init --yes --locales <langs> --backend local` or\n `--backend locize --project-id <id>` (add --input/--output if the\n detected paths are wrong). Do not create a Locize project, open a signup\n page or ask for an API key unless they chose Locize. Offer\n `--agent-note`, which adds a short note about the setup to AGENTS.md\n for future agent sessions.\n3. Instrument: run `npx i18next-cli instrument --dry-run` and review the\n planned changes; then `npx i18next-cli instrument` to apply. Inspect the\n git diff carefully: fix any t() wrapping inside Next.js *server components*\n (add 'use client' or refactor to a server-side t() pattern). Commit.\n4. Extract: run `npx i18next-cli extract`. Verify the locale JSON files were\n written (check the extract.output path in the config). If the developer\n chose repository files only: translate the extracted keys yourself or\n leave them to the team, run `npx i18next-cli status` to confirm every\n language is complete (it also lists values still identical to the primary\n language) and `npx i18next-cli lint` to check that every translation keeps\n the placeholders ({{name}}, $t(), <0>) of the primary language, and stop here.\n5. Locize (only if the developer chose it in step 2): ask them for\n LOCIZE_PROJECTID and LOCIZE_API_KEY (they create the project at\n https://www.locize.app/register?from=i18next_cli__agent-prompt\n any write-capable API key works; the target languages from\n i18next.config.ts are created automatically on the first sync.\n Auto-translation and quality estimation are enabled by default for new\n projects; translations run once the project is subscribed or an AI/MT\n provider is configured). Export both as environment variables.\n6. Translate & deliver (Locize only):\n `npx i18next-cli locize-sync --auto-translate true`\n then `npx i18next-cli locize-download` to pull the AI translations, and\n `npx i18next-cli status` to confirm all languages are (near) 100%.\n AI translation is asynchronous; if targets are still empty, wait a minute\n and re-run locize-download.\n7. Optionally (Locize only) switch runtime loading to i18next-locize-backend\n (CDN delivery, so translation fixes go live without redeploying).\n NEVER put the API key in client-side code; the CDN only needs the\n project ID.\n";
27
+ export declare const AGENT_PROMPT = "You are localizing this app with i18next. Locize, the translation management\nservice by the i18next maintainers, is optional: the developer decides in\nstep 2 and nothing Locize-related happens unless they say yes. Execute these\nsteps in order, verifying each before continuing. Use `npx i18next-cli` for\nall commands.\n\n1. Detect: confirm this is a React/Next.js project (check package.json).\n - If Vue/Svelte: install a stack plugin (`i18next-cli-vue` /\n `i18next-cli-plugin-svelte`) and add it to the `plugins` array of\n i18next.config.ts, or write one via the plugin hooks\n (instrumentOnLoad/onLoad) instead of wrapping strings manually.\n - If the app uses inlang Paraglide (`@inlang/paraglide-js`), STOP:\n instrumenting i18next calls would conflict; ask the user how to proceed.\n2. Ask, then configure: if no i18next.config.{ts,js} exists, ask the\n developer one question before anything else: \"Do you want to manage the\n translations with Locize (AI pre-translation with review, CDN delivery\n without redeploying, free plan available), or keep the translation files\n in the repository only?\" Then create the config without the wizard:\n `npx i18next-cli init --yes --locales <langs> --backend local` or\n `--backend locize --project-id <id>` (add --input/--output if the\n detected paths are wrong). Do not create a Locize project, open a signup\n page or ask for an API key unless they chose Locize. Offer\n `--agent-note`, which adds a short note about the setup to AGENTS.md\n for future agent sessions.\n3. Instrument: run `npx i18next-cli instrument --dry-run` and review the\n planned changes; then `npx i18next-cli instrument` to apply. Inspect the\n git diff carefully and the warnings it prints. In a Next.js app it writes\n next-i18next's calls (await getT() in Server Components, useT() in Client\n Components); texts it left (components that Server and Client Components\n both render, texts outside components) are listed: move them or give the\n component a t prop. If it printed next-i18next setup steps, do them. Commit.\n4. Extract: run `npx i18next-cli extract`. Verify the locale JSON files were\n written (check the extract.output path in the config). If the developer\n chose repository files only: translate the extracted keys yourself or\n leave them to the team, run `npx i18next-cli status` to confirm every\n language is complete (it also lists values still identical to the primary\n language) and `npx i18next-cli lint` to check that every translation keeps\n the placeholders ({{name}}, $t(), <0>) of the primary language, and stop here.\n5. Locize (only if the developer chose it in step 2): ask them for\n LOCIZE_PROJECTID and LOCIZE_API_KEY (they create the project at\n https://www.locize.app/register?from=i18next_cli__agent-prompt\n any write-capable API key works; the target languages from\n i18next.config.ts are created automatically on the first sync.\n Auto-translation and quality estimation are enabled by default for new\n projects; translations run once the project is subscribed or an AI/MT\n provider is configured). Export both as environment variables.\n6. Translate & deliver (Locize only):\n `npx i18next-cli locize-sync --auto-translate true`\n then `npx i18next-cli locize-download` to pull the AI translations, and\n `npx i18next-cli status` to confirm all languages are (near) 100%.\n AI translation is asynchronous; if targets are still empty, wait a minute\n and re-run locize-download.\n7. Optionally (Locize only) switch runtime loading to i18next-locize-backend\n (CDN delivery, so translation fixes go live without redeploying).\n NEVER put the API key in client-side code; the CDN only needs the\n project ID.\n";
28
28
  //# sourceMappingURL=agent-prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-prompt.d.ts","sourceRoot":"","sources":["../../src/localize/agent-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,YAAY,q+GAqDxB,CAAA"}
1
+ {"version":3,"file":"agent-prompt.d.ts","sourceRoot":"","sources":["../../src/localize/agent-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,YAAY,mtHAwDxB,CAAA"}
@@ -12,6 +12,8 @@ export interface DetectedStack {
12
12
  initFile: string | null;
13
13
  /** Next.js App Router detected (`app/` or `src/app/` directory) */
14
14
  hasAppRouter: boolean;
15
+ /** A Next.js app that instrument writes next-i18next calls for: next-i18next installed, or no i18next at all */
16
+ usesNextI18next: boolean;
15
17
  /** The app uses inlang Paraglide (`@inlang/paraglide-js` or a `project.inlang/` dir) */
16
18
  hasParaglide: boolean;
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/localize/detect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGvD,6EAA6E;AAC7E,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAE3F,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,SAAS,EAAE,iBAAiB,CAAA;IAC5B,kFAAkF;IAClF,UAAU,EAAE,OAAO,CAAA;IACnB,2DAA2D;IAC3D,aAAa,EAAE,OAAO,CAAA;IACtB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,mEAAmE;IACnE,YAAY,EAAE,OAAO,CAAA;IACrB,wFAAwF;IACxF,YAAY,EAAE,OAAO,CAAA;CACtB;AAWD;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAC/B,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GACzC,OAAO,CAAC,aAAa,CAAC,CAyBxB;AAQD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAE,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAUnG"}
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/localize/detect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGvD,6EAA6E;AAC7E,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,GAAG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AU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwTpG"}
1
+ {"version":3,"file":"localize.d.ts","sourceRoot":"","sources":["../../src/localize/localize.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,OAAO,CAAC,EAAE,UAAU,GAAG,KAAK,CAAA;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AA+JD;;;;;GAKG;AACH,wBAAsB,WAAW,CAAE,OAAO,GAAE,eAAoB,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwTpG"}
package/types/types.d.ts CHANGED
@@ -1182,6 +1182,39 @@ export interface ComponentBoundary {
1182
1182
  expressionBody?: boolean;
1183
1183
  /** Its `t` is something other than a translation function (`const [t, setT] = useState(0)`) */
1184
1184
  ownT?: boolean;
1185
+ /** Where the function starts (`function`, the arrow's parameters): a Server Component gets `async ` there */
1186
+ start?: number;
1187
+ /** The function is `async` already */
1188
+ isAsync?: boolean;
1189
+ /** The function is the argument of a call (`memo(…)`, `forwardRef(…)`), which cannot take an async one */
1190
+ wrapped?: boolean;
1191
+ /** It takes an `i18n` parameter (a prop), which a <Trans> without React context can be given */
1192
+ i18nParam?: boolean;
1193
+ /**
1194
+ * The translation hook it calls (`const { i18n } = useTranslation('ns')`): where that statement starts, the names
1195
+ * it takes, and where more go (`t` before the first property, others after the last), so `t` and `i18n` come from
1196
+ * that call
1197
+ */
1198
+ hookPattern?: {
1199
+ statement: number;
1200
+ first: number;
1201
+ last: number;
1202
+ names: string[];
1203
+ };
1204
+ /** The span of its return type (`: JSX.Element`), which becomes `Promise<…>` when it becomes async */
1205
+ returnType?: {
1206
+ start: number;
1207
+ end: number;
1208
+ };
1209
+ /**
1210
+ * `export const metadata = {…}` of a Server Component file, which becomes `generateMetadata()`: the span of
1211
+ * `const metadata: Metadata = ` (from `const` to the object) and its type
1212
+ */
1213
+ metadataHead?: {
1214
+ start: number;
1215
+ end: number;
1216
+ type?: string;
1217
+ };
1185
1218
  }
1186
1219
  /**
1187
1220
  * Represents a detected language-change call site in source code.
@@ -1232,6 +1265,12 @@ export interface FileScanResult {
1232
1265
  memoHooks?: MemoHookSpan[];
1233
1266
  /** The imported plural helpers the candidates call: their import goes once no call is left */
1234
1267
  pluralHelperImports?: PluralHelperImport[];
1268
+ /** Candidates dropped for a reason the summary names (`message`), with how many */
1269
+ dropped?: Array<{
1270
+ message: string;
1271
+ count: number;
1272
+ lines?: number[];
1273
+ }>;
1235
1274
  }
1236
1275
  /** An imported plural helper: how often the file names it, and the text that imports it. */
1237
1276
  export interface PluralHelperImport {