i18next-cli 1.39.8 → 1.39.9

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/dist/cjs/cli.js CHANGED
@@ -28,7 +28,7 @@ const program = new commander.Command();
28
28
  program
29
29
  .name('i18next-cli')
30
30
  .description('A unified, high-performance i18next CLI.')
31
- .version('1.39.8'); // This string is replaced with the actual version at build time by rollup
31
+ .version('1.39.9'); // This string is replaced with the actual version at build time by rollup
32
32
  // new: global config override option
33
33
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
34
34
  program
@@ -350,7 +350,34 @@ function replaceKeyWithRegex(code, oldParts, newParts, config, namespaceKeyMap)
350
350
  });
351
351
  }
352
352
  //
353
- // 3) fullKey (explicitly namespaced string in call): only when user supplied a namespaced target
353
+ // 3a) Replace occurrences where the call uses an explicitly namespaced string
354
+ // literal like t('ns:key') while the CLI rename was invoked with the
355
+ // key without namespace (oldKey='key'). Example: defaultNS = 'ns1',
356
+ // source contains t('ns1:key'), and user called runRenameKey('key', 'key2').
357
+ // We should update 'ns1:key' -> 'ns1:key2' or to a new namespace if the
358
+ // target includes an explicit namespace.
359
+ //
360
+ // Only update explicit "ns:oldKey" string literals when the key name itself
361
+ // is changing. If only the namespace is changing but the key name stays
362
+ // identical (e.g. `key` -> `ns2:key`) we should NOT rewrite explicit
363
+ // `t('ns1:key')` occurrences — keep their explicit namespace intact.
364
+ if (oldParts.namespace && newParts.key !== oldParts.key) {
365
+ // ensure ns separator is a string for regex building (default ':')
366
+ const nsSepStr = nsSeparator === false ? ':' : String(nsSeparator);
367
+ const prefixed = `${escapeRegex(String(oldParts.namespace))}${escapeRegex(nsSepStr)}${escapeRegex(oldParts.key)}`;
368
+ const regexPrefixed = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${prefixed}\\1`, 'g');
369
+ newCode = newCode.replace(regexPrefixed, (match) => {
370
+ changes++;
371
+ // determine replacement: if newParts is explicitly namespaced, use fullKey;
372
+ // otherwise keep the original namespace but swap the key.
373
+ const replacement = newParts.explicitNamespace
374
+ ? newParts.fullKey
375
+ : `${oldParts.namespace}${nsSepStr}${newParts.key}`;
376
+ return match.replace(`${oldParts.namespace}${nsSepStr}${oldParts.key}`, replacement);
377
+ });
378
+ }
379
+ //
380
+ // 3b) fullKey (explicitly namespaced string in call): only when user supplied a namespaced target
354
381
  //
355
382
  if (oldParts.fullKey && oldParts.explicitNamespace) {
356
383
  const regexFull = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.fullKey)}\\1`, 'g');
package/dist/esm/cli.js CHANGED
@@ -26,7 +26,7 @@ const program = new Command();
26
26
  program
27
27
  .name('i18next-cli')
28
28
  .description('A unified, high-performance i18next CLI.')
29
- .version('1.39.8'); // This string is replaced with the actual version at build time by rollup
29
+ .version('1.39.9'); // This string is replaced with the actual version at build time by rollup
30
30
  // new: global config override option
31
31
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
32
32
  program
@@ -348,7 +348,34 @@ function replaceKeyWithRegex(code, oldParts, newParts, config, namespaceKeyMap)
348
348
  });
349
349
  }
350
350
  //
351
- // 3) fullKey (explicitly namespaced string in call): only when user supplied a namespaced target
351
+ // 3a) Replace occurrences where the call uses an explicitly namespaced string
352
+ // literal like t('ns:key') while the CLI rename was invoked with the
353
+ // key without namespace (oldKey='key'). Example: defaultNS = 'ns1',
354
+ // source contains t('ns1:key'), and user called runRenameKey('key', 'key2').
355
+ // We should update 'ns1:key' -> 'ns1:key2' or to a new namespace if the
356
+ // target includes an explicit namespace.
357
+ //
358
+ // Only update explicit "ns:oldKey" string literals when the key name itself
359
+ // is changing. If only the namespace is changing but the key name stays
360
+ // identical (e.g. `key` -> `ns2:key`) we should NOT rewrite explicit
361
+ // `t('ns1:key')` occurrences — keep their explicit namespace intact.
362
+ if (oldParts.namespace && newParts.key !== oldParts.key) {
363
+ // ensure ns separator is a string for regex building (default ':')
364
+ const nsSepStr = nsSeparator === false ? ':' : String(nsSeparator);
365
+ const prefixed = `${escapeRegex(String(oldParts.namespace))}${escapeRegex(nsSepStr)}${escapeRegex(oldParts.key)}`;
366
+ const regexPrefixed = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${prefixed}\\1`, 'g');
367
+ newCode = newCode.replace(regexPrefixed, (match) => {
368
+ changes++;
369
+ // determine replacement: if newParts is explicitly namespaced, use fullKey;
370
+ // otherwise keep the original namespace but swap the key.
371
+ const replacement = newParts.explicitNamespace
372
+ ? newParts.fullKey
373
+ : `${oldParts.namespace}${nsSepStr}${newParts.key}`;
374
+ return match.replace(`${oldParts.namespace}${nsSepStr}${oldParts.key}`, replacement);
375
+ });
376
+ }
377
+ //
378
+ // 3b) fullKey (explicitly namespaced string in call): only when user supplied a namespaced target
352
379
  //
353
380
  if (oldParts.fullKey && oldParts.explicitNamespace) {
354
381
  const regexFull = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.fullKey)}\\1`, 'g');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.39.8",
3
+ "version": "1.39.9",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {