i18next-cli 1.39.1 → 1.39.3

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.1'); // This string is replaced with the actual version at build time by rollup
31
+ .version('1.39.3'); // 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
@@ -220,6 +220,54 @@ function replaceKeyWithRegex(code, oldParts, newParts, config) {
220
220
  const replacementKey = newParts.key;
221
221
  return match.replace(new RegExp(escapeRegex(oldParts.key)), replacementKey);
222
222
  });
223
+ // Then match bare key (no namespace in source)
224
+ // If moving from defaultNS to another, and call is t('key') with no options, add ns option
225
+ const regexKeyWithParen = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.key)}\\1\\s*\\)`, 'g');
226
+ newCode = newCode.replace(regexKeyWithParen, (match, quote) => {
227
+ if (oldParts.namespace && newParts.namespace &&
228
+ oldParts.namespace !== newParts.namespace &&
229
+ config.extract.defaultNS === oldParts.namespace) {
230
+ changes++;
231
+ return match.replace(new RegExp(`(['"\`])${escapeRegex(oldParts.key)}\\1\\s*\\)`), `${quote}${newParts.key}${quote}, { ns: '${newParts.namespace}' })`);
232
+ }
233
+ else if (oldParts.namespace && newParts.namespace &&
234
+ oldParts.namespace !== newParts.namespace &&
235
+ config.extract.defaultNS === newParts.namespace) {
236
+ // If moving from a namespaced key to defaultNS, update t('key', { ns: 'oldNs' }) to t('key')
237
+ // Remove the ns option if it matches the defaultNS
238
+ // This is handled below in the ns option replacement
239
+ // But also handle t('key', { ns: 'defaultNS' }) -> t('key')
240
+ // See below for explicit ns option removal
241
+ // No action here, handled below
242
+ return match;
243
+ }
244
+ else {
245
+ changes++;
246
+ const replacementKey = newParts.key;
247
+ return match.replace(new RegExp(escapeRegex(oldParts.key)), replacementKey);
248
+ }
249
+ });
250
+ // Remove ns option if moving to defaultNS
251
+ if (oldParts.namespace && newParts.namespace &&
252
+ oldParts.namespace !== newParts.namespace &&
253
+ config.extract.defaultNS === newParts.namespace) {
254
+ // t('key', { ns: 'oldNs' }) -> t('key')
255
+ const nsRegexToDefault = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.key)}\\1\\s*,\\s*\\{([^}]*)\\bns\\s*:\\s*(['"\`])${escapeRegex(oldParts.namespace)}\\3([^}]*)\\}\\s*\\)`, 'g');
256
+ newCode = newCode.replace(nsRegexToDefault, (match, keyQ, beforeNs, nsQ, afterNs) => {
257
+ changes++;
258
+ // Remove the ns property and any trailing comma if present
259
+ // Remove possible preceding/trailing commas and whitespace
260
+ let obj = beforeNs + afterNs;
261
+ obj = obj.replace(/,?\s*$/, '');
262
+ obj = obj.replace(/^\s*,?/, '');
263
+ if (obj.trim()) {
264
+ return `${prefix}(${keyQ}${newParts.key}${keyQ}, {${obj}})`;
265
+ }
266
+ else {
267
+ return `${prefix}(${keyQ}${newParts.key}${keyQ})`;
268
+ }
269
+ });
270
+ }
223
271
  // Handle ns option in options object: fn('key', { ns: 'oldNs', ... })
224
272
  if (oldParts.namespace && newParts.namespace && oldParts.namespace !== newParts.namespace) {
225
273
  // We want to change only when key matches and ns value equals oldParts.namespace
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.1'); // This string is replaced with the actual version at build time by rollup
29
+ .version('1.39.3'); // 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
@@ -218,6 +218,54 @@ function replaceKeyWithRegex(code, oldParts, newParts, config) {
218
218
  const replacementKey = newParts.key;
219
219
  return match.replace(new RegExp(escapeRegex(oldParts.key)), replacementKey);
220
220
  });
221
+ // Then match bare key (no namespace in source)
222
+ // If moving from defaultNS to another, and call is t('key') with no options, add ns option
223
+ const regexKeyWithParen = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.key)}\\1\\s*\\)`, 'g');
224
+ newCode = newCode.replace(regexKeyWithParen, (match, quote) => {
225
+ if (oldParts.namespace && newParts.namespace &&
226
+ oldParts.namespace !== newParts.namespace &&
227
+ config.extract.defaultNS === oldParts.namespace) {
228
+ changes++;
229
+ return match.replace(new RegExp(`(['"\`])${escapeRegex(oldParts.key)}\\1\\s*\\)`), `${quote}${newParts.key}${quote}, { ns: '${newParts.namespace}' })`);
230
+ }
231
+ else if (oldParts.namespace && newParts.namespace &&
232
+ oldParts.namespace !== newParts.namespace &&
233
+ config.extract.defaultNS === newParts.namespace) {
234
+ // If moving from a namespaced key to defaultNS, update t('key', { ns: 'oldNs' }) to t('key')
235
+ // Remove the ns option if it matches the defaultNS
236
+ // This is handled below in the ns option replacement
237
+ // But also handle t('key', { ns: 'defaultNS' }) -> t('key')
238
+ // See below for explicit ns option removal
239
+ // No action here, handled below
240
+ return match;
241
+ }
242
+ else {
243
+ changes++;
244
+ const replacementKey = newParts.key;
245
+ return match.replace(new RegExp(escapeRegex(oldParts.key)), replacementKey);
246
+ }
247
+ });
248
+ // Remove ns option if moving to defaultNS
249
+ if (oldParts.namespace && newParts.namespace &&
250
+ oldParts.namespace !== newParts.namespace &&
251
+ config.extract.defaultNS === newParts.namespace) {
252
+ // t('key', { ns: 'oldNs' }) -> t('key')
253
+ const nsRegexToDefault = new RegExp(`${prefix}\\s*\\(\\s*(['"\`])${escapeRegex(oldParts.key)}\\1\\s*,\\s*\\{([^}]*)\\bns\\s*:\\s*(['"\`])${escapeRegex(oldParts.namespace)}\\3([^}]*)\\}\\s*\\)`, 'g');
254
+ newCode = newCode.replace(nsRegexToDefault, (match, keyQ, beforeNs, nsQ, afterNs) => {
255
+ changes++;
256
+ // Remove the ns property and any trailing comma if present
257
+ // Remove possible preceding/trailing commas and whitespace
258
+ let obj = beforeNs + afterNs;
259
+ obj = obj.replace(/,?\s*$/, '');
260
+ obj = obj.replace(/^\s*,?/, '');
261
+ if (obj.trim()) {
262
+ return `${prefix}(${keyQ}${newParts.key}${keyQ}, {${obj}})`;
263
+ }
264
+ else {
265
+ return `${prefix}(${keyQ}${newParts.key}${keyQ})`;
266
+ }
267
+ });
268
+ }
221
269
  // Handle ns option in options object: fn('key', { ns: 'oldNs', ... })
222
270
  if (oldParts.namespace && newParts.namespace && oldParts.namespace !== newParts.namespace) {
223
271
  // We want to change only when key matches and ns value equals oldParts.namespace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.39.1",
3
+ "version": "1.39.3",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {