i18next-cli 1.24.0 → 1.24.1

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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.24.1](https://github.com/i18next/i18next-cli/compare/v1.24.0...v1.24.1) - 2025-11-12
9
+
10
+ - Windows fix for new **CLI:** command `rename-key`
11
+
8
12
  ## [1.24.0](https://github.com/i18next/i18next-cli/compare/v1.23.6...v1.24.0) - 2025-11-12
9
13
 
10
14
  - **CLI:** Introduced the `rename-key` command for safely refactoring translation keys across your entire codebase. This new command updates both source files and translation JSON files atomically, automatically handling namespaces, plurals, and multiple locales. [109](https://github.com/i18next/i18next-cli/issues/109)
package/dist/cjs/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var e=require("commander"),o=require("chokidar"),t=require("glob"),n=require("minimatch"),i=require("chalk"),r=require("./config.js"),a=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),d=require("./init.js"),g=require("./linter.js"),f=require("./status.js"),p=require("./locize.js"),m=require("./rename-key.js");const y=new e.Command;y.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.24.0"),y.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),y.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async e=>{try{const t=y.opts().config,i=await r.ensureConfig(t),a=async()=>{const o=await c.runExtractor(i,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:!!e.syncPrimary});return e.ci&&!o?(console.log("✅ No files were updated."),process.exit(0)):e.ci&&o&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),o};if(await a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.extract.input),t=h(i.extract.ignore),r=w(i.extract.output),c=[...t,...r].filter(Boolean),s=e.filter(e=>!c.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),y.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,o)=>{const t=y.opts().config;let n=await r.loadConfig(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await a.detectConfig();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=e}await f.runStatus(n,{detail:e,namespace:o.namespace})}),y.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const t=y.opts().config,i=await r.ensureConfig(t),a=()=>s.runTypesGenerator(i);if(await a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.types?.input||[]),t=[...h(i.extract?.ignore)].filter(Boolean),r=e.filter(e=>!t.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}),y.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=y.opts().config,o=await r.ensureConfig(e);await l.runSyncer(o)}),y.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await u.runMigrator(e)}),y.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d.runInit),y.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async e=>{const t=y.opts().config,c=async()=>{let e=await r.loadConfig(t);if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await a.detectConfig();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=o}await g.runLinterCli(e)};if(await c(),e.watch){console.log("\nWatching for changes...");const e=await r.loadConfig(t);if(e?.extract?.input){const t=await x(e.extract.input),i=[...h(e.extract.ignore),...w(e.extract.output)].filter(Boolean),r=t.filter(e=>!i.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}}),y.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async e=>{const o=y.opts().config,t=await r.ensureConfig(o);await p.runLocizeSync(t,e)}),y.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const o=y.opts().config,t=await r.ensureConfig(o);await p.runLocizeDownload(t,e)}),y.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const o=y.opts().config,t=await r.ensureConfig(o);await p.runLocizeMigrate(t,e)}),y.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(e,o,t)=>{try{const n=y.opts().config,a=await r.ensureConfig(n),c=await m.runRenameKey(a,e,o,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(e=>console.error(` - ${e}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((e,o)=>e+o.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${e}"`))}catch(e){console.error(i.red("Error renaming key:"),e),process.exit(1)}}),y.parse(process.argv);const h=e=>Array.isArray(e)?e:e?[e]:[],w=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],x=async(e=[])=>{const o=h(e),n=await Promise.all(o.map(e=>t.glob(e||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
2
+ "use strict";var e=require("commander"),o=require("chokidar"),t=require("glob"),n=require("minimatch"),i=require("chalk"),r=require("./config.js"),a=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),d=require("./init.js"),g=require("./linter.js"),f=require("./status.js"),p=require("./locize.js"),m=require("./rename-key.js");const y=new e.Command;y.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.24.1"),y.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),y.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async e=>{try{const t=y.opts().config,i=await r.ensureConfig(t),a=async()=>{const o=await c.runExtractor(i,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:!!e.syncPrimary});return e.ci&&!o?(console.log("✅ No files were updated."),process.exit(0)):e.ci&&o&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),o};if(await a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.extract.input),t=h(i.extract.ignore),r=w(i.extract.output),c=[...t,...r].filter(Boolean),s=e.filter(e=>!c.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),y.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,o)=>{const t=y.opts().config;let n=await r.loadConfig(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await a.detectConfig();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=e}await f.runStatus(n,{detail:e,namespace:o.namespace})}),y.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const t=y.opts().config,i=await r.ensureConfig(t),a=()=>s.runTypesGenerator(i);if(await a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.types?.input||[]),t=[...h(i.extract?.ignore)].filter(Boolean),r=e.filter(e=>!t.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}),y.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=y.opts().config,o=await r.ensureConfig(e);await l.runSyncer(o)}),y.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await u.runMigrator(e)}),y.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d.runInit),y.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async e=>{const t=y.opts().config,c=async()=>{let e=await r.loadConfig(t);if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await a.detectConfig();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=o}await g.runLinterCli(e)};if(await c(),e.watch){console.log("\nWatching for changes...");const e=await r.loadConfig(t);if(e?.extract?.input){const t=await x(e.extract.input),i=[...h(e.extract.ignore),...w(e.extract.output)].filter(Boolean),r=t.filter(e=>!i.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}}),y.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async e=>{const o=y.opts().config,t=await r.ensureConfig(o);await p.runLocizeSync(t,e)}),y.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const o=y.opts().config,t=await r.ensureConfig(o);await p.runLocizeDownload(t,e)}),y.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const o=y.opts().config,t=await r.ensureConfig(o);await p.runLocizeMigrate(t,e)}),y.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(e,o,t)=>{try{const n=y.opts().config,a=await r.ensureConfig(n),c=await m.runRenameKey(a,e,o,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(e=>console.error(` - ${e}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((e,o)=>e+o.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${e}"`))}catch(e){console.error(i.red("Error renaming key:"),e),process.exit(1)}}),y.parse(process.argv);const h=e=>Array.isArray(e)?e:e?[e]:[],w=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],x=async(e=[])=>{const o=h(e),n=await Promise.all(o.map(e=>t.glob(e||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
@@ -1 +1 @@
1
- "use strict";var e=require("glob"),t=require("node:fs/promises"),n=require("./utils/logger.js"),r=require("./utils/file-utils.js"),o=require("node:path"),a=require("./utils/nested-object.js"),i=require("./utils/funnel-msg-tracker.js"),s=require("chalk");function c(e,t){const n=t.extract.nsSeparator??":";if(n&&e.includes(n)){const[t,...r]=e.split(n);return{namespace:t,key:r.join(n),fullKey:e}}return{namespace:t.extract.defaultNS||"translation",key:e,fullKey:e}}async function l(e,t,n,r){return function(e,t,n,r){let o=0,a=e;const i=r.extract.nsSeparator??":",s=e=>i&&e.includes(String(i))?n.fullKey:n.key,c=r.extract.functions||["t","*.t"],l=[];for(const e of c)if(e.startsWith("*.")){const n=u(e.substring(1));l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${u(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${u(t.key)}\\1`,"g"),original:t.key})}else{const n=u(e);l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${u(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${u(t.key)}\\1`,"g"),original:t.key})}for(const{pattern:e,original:t}of l)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>{o++;const r=e.match(/^(\w+(?:\.\w+)*)\(/);return r?`${r[1]}(${t}${n}${t}`:e})}const f=[{pattern:new RegExp(`i18nKey=(['"\`])${u(t.fullKey)}\\1`,"g"),original:t.fullKey},{pattern:new RegExp(`i18nKey=(['"\`])${u(t.key)}\\1`,"g"),original:t.key}];for(const{pattern:e,original:t}of f)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>(o++,`i18nKey=${t}${n}${t}`))}return{newCode:a,changes:o}}(e,t,n,r)}function u(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function f(e,t,n){if(!1===n)return void delete e[t];const r=t.split(String(n));let o=e;for(let e=0;e<r.length-1;e++){if(!o[r[e]])return;o=o[r[e]]}delete o[r[r.length-1]]}exports.runRenameKey=async function(u,g,p,y={},d=new n.ConsoleLogger){const{dryRun:w=!1}=y,h=function(e,t){if(!e||!e.trim())return{valid:!1,error:"Old key cannot be empty"};if(!t||!t.trim())return{valid:!1,error:"New key cannot be empty"};if(e===t)return{valid:!1,error:"Old and new keys are identical"};return{valid:!0}}(g,p);if(!h.valid)return{success:!1,sourceFiles:[],translationFiles:[],error:h.error};const $=c(g,u),m=c(p,u),k=await async function(e,t){const n=[];for(const i of t.locales){const s=r.getOutputPath(t.extract.output,i,e.namespace),c=o.resolve(process.cwd(),s);try{const o=await r.loadTranslationFile(c);if(o){const r=t.extract.keySeparator??".";void 0!==a.getNestedValue(o,e.key,r)&&n.push(`${i}:${e.fullKey}`)}}catch{}}return n}(m,u);if(k.length>0)return{success:!1,sourceFiles:[],translationFiles:[],conflicts:k,error:"Target key already exists in translation files"};d.info(`🔍 Scanning for usages of "${g}"...`);const x=await async function(n,r,o,a,i){const s=["node_modules/**"],c=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[],u=await e.glob(o.extract.input,{ignore:[...s,...c],cwd:process.cwd()}),f=[];for(const e of u){const s=await t.readFile(e,"utf-8"),{newCode:c,changes:u}=await l(s,n,r,o);u>0&&(a||await t.writeFile(e,c,"utf-8"),f.push({path:e,changes:u}),i.info(` ${a?"(dry-run) ":""}✓ ${e} (${u} ${1===u?"change":"changes"})`))}f.length>0&&i.info(`\n📝 Source file changes: ${f.length} file${1===f.length?"":"s"}`);return f}($,m,u,w,d),F=await async function(e,n,i,s,c){const l=[],u=i.extract.keySeparator??".";for(const g of i.locales){const p=r.getOutputPath(i.extract.output,g,e.namespace),y=o.resolve(process.cwd(),p);try{const o=await r.loadTranslationFile(y);if(!o)continue;const g=a.getNestedValue(o,e.key,u);if(void 0===g)continue;if(f(o,e.key,u),a.setNestedValue(o,n.key,g,u),!s){const e=r.serializeTranslationFile(o,i.extract.outputFormat,i.extract.indentation);await t.writeFile(y,e,"utf-8")}l.push({path:y,updated:!0}),c.info(` ${s?"(dry-run) ":""}✓ ${y}`)}catch(e){}}l.length>0&&c.info(`\n📦 Translation file updates: ${l.length} file${1===l.length?"":"s"}`);return l}($,m,u,w,d),K=x.reduce((e,t)=>e+t.changes,0);return!w&&K>0?(d.info("\n✨ Successfully renamed key!"),d.info(` Old: "${g}"`),d.info(` New: "${p}"`),await async function(){if(!await i.shouldShowFunnel("rename-key"))return;return console.log(s.yellow.bold("\n💡 Tip: Managing translations across multiple projects?")),console.log(" With locize, you can rename, move, and copy translation keys directly"),console.log(" in the web interface—no CLI needed. Perfect for collaboration with"),console.log(" translators and managing complex refactoring across namespaces."),console.log(` Learn more: ${s.cyan("https://www.locize.com/docs/how-can-a-segment-key-be-copied-moved-or-renamed")}`),i.recordFunnelShown("rename-key")}()):0===K&&d.info(`\n⚠️ No usages found for "${g}"`),{success:!0,sourceFiles:x,translationFiles:F}};
1
+ "use strict";var e=require("glob"),t=require("node:fs/promises"),n=require("./utils/logger.js"),r=require("./utils/file-utils.js"),o=require("node:path"),a=require("./utils/nested-object.js"),i=require("./utils/funnel-msg-tracker.js"),s=require("chalk");function c(e,t){const n=t.extract.nsSeparator??":";if(n&&e.includes(n)){const[t,...r]=e.split(n);return{namespace:t,key:r.join(n),fullKey:e}}return{namespace:t.extract.defaultNS||"translation",key:e,fullKey:e}}async function l(e,t,n,r){return function(e,t,n,r){let o=0,a=e;const i=r.extract.nsSeparator??":",s=e=>i&&e.includes(String(i))?n.fullKey:n.key,c=r.extract.functions||["t","*.t"],l=[];for(const e of c)if(e.startsWith("*.")){const n=u(e.substring(1));l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${u(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${u(t.key)}\\1`,"g"),original:t.key})}else{const n=u(e);l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${u(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${u(t.key)}\\1`,"g"),original:t.key})}for(const{pattern:e,original:t}of l)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>{o++;const r=e.match(/^(\w+(?:\.\w+)*)\(/);return r?`${r[1]}(${t}${n}${t}`:e})}const f=[{pattern:new RegExp(`i18nKey=(['"\`])${u(t.fullKey)}\\1`,"g"),original:t.fullKey},{pattern:new RegExp(`i18nKey=(['"\`])${u(t.key)}\\1`,"g"),original:t.key}];for(const{pattern:e,original:t}of f)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>(o++,`i18nKey=${t}${n}${t}`))}return{newCode:a,changes:o}}(e,t,n,r)}function u(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function f(e,t,n){if(!1===n)return void delete e[t];const r=t.split(String(n));let o=e;for(let e=0;e<r.length-1;e++){if(!o[r[e]])return;o=o[r[e]]}delete o[r[r.length-1]]}exports.runRenameKey=async function(u,g,p,y={},d=new n.ConsoleLogger){const{dryRun:w=!1}=y,h=function(e,t){if(!e||!e.trim())return{valid:!1,error:"Old key cannot be empty"};if(!t||!t.trim())return{valid:!1,error:"New key cannot be empty"};if(e===t)return{valid:!1,error:"Old and new keys are identical"};return{valid:!0}}(g,p);if(!h.valid)return{success:!1,sourceFiles:[],translationFiles:[],error:h.error};const $=c(g,u),m=c(p,u),k=await async function(e,t){const n=[];for(const i of t.locales){const s=r.getOutputPath(t.extract.output,i,e.namespace),c=o.resolve(process.cwd(),s);try{const o=await r.loadTranslationFile(c);if(o){const r=t.extract.keySeparator??".";void 0!==a.getNestedValue(o,e.key,r)&&n.push(`${i}:${e.fullKey}`)}}catch{}}return n}(m,u);if(k.length>0)return{success:!1,sourceFiles:[],translationFiles:[],conflicts:k,error:"Target key already exists in translation files"};d.info(`🔍 Scanning for usages of "${g}"...`);const x=await async function(n,r,o,a,i){const s=["node_modules/**"],c=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[],u=Array.isArray(o.extract.input)?o.extract.input:[o.extract.input],f=u.map(e=>e.replace(/\\/g,"/")),g=await e.glob(f,{ignore:[...s,...c],cwd:process.cwd()}),p=[];for(const e of g){const s=await t.readFile(e,"utf-8"),{newCode:c,changes:u}=await l(s,n,r,o);u>0&&(a||await t.writeFile(e,c,"utf-8"),p.push({path:e,changes:u}),i.info(` ${a?"(dry-run) ":""}✓ ${e} (${u} ${1===u?"change":"changes"})`))}p.length>0&&i.info(`\n📝 Source file changes: ${p.length} file${1===p.length?"":"s"}`);return p}($,m,u,w,d),F=await async function(e,n,i,s,c){const l=[],u=i.extract.keySeparator??".";for(const g of i.locales){const p=r.getOutputPath(i.extract.output,g,e.namespace),y=o.resolve(process.cwd(),p);try{const o=await r.loadTranslationFile(y);if(!o)continue;const g=a.getNestedValue(o,e.key,u);if(void 0===g)continue;if(f(o,e.key,u),a.setNestedValue(o,n.key,g,u),!s){const e=r.serializeTranslationFile(o,i.extract.outputFormat,i.extract.indentation);await t.writeFile(y,e,"utf-8")}l.push({path:y,updated:!0}),c.info(` ${s?"(dry-run) ":""}✓ ${y}`)}catch(e){}}l.length>0&&c.info(`\n📦 Translation file updates: ${l.length} file${1===l.length?"":"s"}`);return l}($,m,u,w,d),K=x.reduce((e,t)=>e+t.changes,0);return!w&&K>0?(d.info("\n✨ Successfully renamed key!"),d.info(` Old: "${g}"`),d.info(` New: "${p}"`),await async function(){if(!await i.shouldShowFunnel("rename-key"))return;return console.log(s.yellow.bold("\n💡 Tip: Managing translations across multiple projects?")),console.log(" With locize, you can rename, move, and copy translation keys directly"),console.log(" in the web interface—no CLI needed. Perfect for collaboration with"),console.log(" translators and managing complex refactoring across namespaces."),console.log(` Learn more: ${s.cyan("https://www.locize.com/docs/how-can-a-segment-key-be-copied-moved-or-renamed")}`),i.recordFunnelShown("rename-key")}()):0===K&&d.info(`\n⚠️ No usages found for "${g}"`),{success:!0,sourceFiles:x,translationFiles:F}};
package/dist/esm/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{Command as o}from"commander";import e from"chokidar";import{glob as t}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as f}from"./migrator.js";import{runInit as m}from"./init.js";import{runLinterCli as d}from"./linter.js";import{runStatus as g}from"./status.js";import{runLocizeSync as u,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";import{runRenameKey as w}from"./rename-key.js";const x=new o;x.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.24.0"),x.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),x.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async o=>{try{const t=x.opts().config,i=await a(t),r=async()=>{const e=await s(i,{isWatchMode:!!o.watch,isDryRun:!!o.dryRun,syncPrimaryWithDefaults:!!o.syncPrimary});return o.ci&&!e?(console.log("✅ No files were updated."),process.exit(0)):o.ci&&e&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),e};if(await r(),o.watch){console.log("\nWatching for changes...");const o=await z(i.extract.input),t=j(i.extract.ignore),a=k(i.extract.output),c=[...t,...a].filter(Boolean),s=o.filter(o=>!c.some(e=>n(o,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}catch(o){console.error("Error running extractor:",o),process.exit(1)}}),x.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(o,e)=>{const t=x.opts().config;let n=await r(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=o}await g(n,{detail:o,namespace:e.namespace})}),x.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async o=>{const t=x.opts().config,i=await a(t),r=()=>l(i);if(await r(),o.watch){console.log("\nWatching for changes...");const o=await z(i.types?.input||[]),t=[...j(i.extract?.ignore)].filter(Boolean),a=o.filter(o=>!t.some(e=>n(o,e,{dot:!0})));e.watch(a,{persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}),x.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const o=x.opts().config,e=await a(o);await p(e)}),x.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async o=>{await f(o)}),x.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(m),x.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async o=>{const t=x.opts().config,a=async()=>{let o=await r(t);if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await c();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),o=e}await d(o)};if(await a(),o.watch){console.log("\nWatching for changes...");const o=await r(t);if(o?.extract?.input){const t=await z(o.extract.input),i=[...j(o.extract.ignore),...k(o.extract.output)].filter(Boolean),r=t.filter(o=>!i.some(e=>n(o,e,{dot:!0})));e.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}}),x.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async o=>{const e=x.opts().config,t=await a(e);await u(t,o)}),x.command("locize-download").description("Download all translations from your locize project.").action(async o=>{const e=x.opts().config,t=await a(e);await y(t,o)}),x.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async o=>{const e=x.opts().config,t=await a(e);await h(t,o)}),x.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(o,e,t)=>{try{const n=x.opts().config,r=await a(n),c=await w(r,o,e,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(o=>console.error(` - ${o}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((o,e)=>o+e.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${o}"`))}catch(o){console.error(i.red("Error renaming key:"),o),process.exit(1)}}),x.parse(process.argv);const j=o=>Array.isArray(o)?o:o?[o]:[],k=o=>o&&"string"==typeof o?[o.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(o=[])=>{const e=j(o),n=await Promise.all(e.map(o=>t(o||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
2
+ import{Command as o}from"commander";import e from"chokidar";import{glob as t}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as f}from"./migrator.js";import{runInit as m}from"./init.js";import{runLinterCli as d}from"./linter.js";import{runStatus as g}from"./status.js";import{runLocizeSync as u,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";import{runRenameKey as w}from"./rename-key.js";const x=new o;x.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.24.1"),x.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),x.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async o=>{try{const t=x.opts().config,i=await a(t),r=async()=>{const e=await s(i,{isWatchMode:!!o.watch,isDryRun:!!o.dryRun,syncPrimaryWithDefaults:!!o.syncPrimary});return o.ci&&!e?(console.log("✅ No files were updated."),process.exit(0)):o.ci&&e&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),e};if(await r(),o.watch){console.log("\nWatching for changes...");const o=await z(i.extract.input),t=j(i.extract.ignore),a=k(i.extract.output),c=[...t,...a].filter(Boolean),s=o.filter(o=>!c.some(e=>n(o,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}catch(o){console.error("Error running extractor:",o),process.exit(1)}}),x.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(o,e)=>{const t=x.opts().config;let n=await r(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=o}await g(n,{detail:o,namespace:e.namespace})}),x.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async o=>{const t=x.opts().config,i=await a(t),r=()=>l(i);if(await r(),o.watch){console.log("\nWatching for changes...");const o=await z(i.types?.input||[]),t=[...j(i.extract?.ignore)].filter(Boolean),a=o.filter(o=>!t.some(e=>n(o,e,{dot:!0})));e.watch(a,{persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}),x.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const o=x.opts().config,e=await a(o);await p(e)}),x.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async o=>{await f(o)}),x.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(m),x.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async o=>{const t=x.opts().config,a=async()=>{let o=await r(t);if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await c();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),o=e}await d(o)};if(await a(),o.watch){console.log("\nWatching for changes...");const o=await r(t);if(o?.extract?.input){const t=await z(o.extract.input),i=[...j(o.extract.ignore),...k(o.extract.output)].filter(Boolean),r=t.filter(o=>!i.some(e=>n(o,e,{dot:!0})));e.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}}),x.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async o=>{const e=x.opts().config,t=await a(e);await u(t,o)}),x.command("locize-download").description("Download all translations from your locize project.").action(async o=>{const e=x.opts().config,t=await a(e);await y(t,o)}),x.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async o=>{const e=x.opts().config,t=await a(e);await h(t,o)}),x.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(o,e,t)=>{try{const n=x.opts().config,r=await a(n),c=await w(r,o,e,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(o=>console.error(` - ${o}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((o,e)=>o+e.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${o}"`))}catch(o){console.error(i.red("Error renaming key:"),o),process.exit(1)}}),x.parse(process.argv);const j=o=>Array.isArray(o)?o:o?[o]:[],k=o=>o&&"string"==typeof o?[o.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(o=[])=>{const e=j(o),n=await Promise.all(e.map(o=>t(o||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
@@ -1 +1 @@
1
- import{glob as e}from"glob";import{readFile as t,writeFile as n}from"node:fs/promises";import{ConsoleLogger as r}from"./utils/logger.js";import{getOutputPath as o,loadTranslationFile as a,serializeTranslationFile as i}from"./utils/file-utils.js";import{resolve as s}from"node:path";import{getNestedValue as c,setNestedValue as l}from"./utils/nested-object.js";import{shouldShowFunnel as u,recordFunnelShown as f}from"./utils/funnel-msg-tracker.js";import p from"chalk";async function g(g,m,h,$={},k=new r){const{dryRun:x=!1}=$,K=function(e,t){if(!e||!e.trim())return{valid:!1,error:"Old key cannot be empty"};if(!t||!t.trim())return{valid:!1,error:"New key cannot be empty"};if(e===t)return{valid:!1,error:"Old and new keys are identical"};return{valid:!0}}(m,h);if(!K.valid)return{success:!1,sourceFiles:[],translationFiles:[],error:K.error};const b=y(m,g),v=y(h,g),S=await async function(e,t){const n=[];for(const r of t.locales){const i=o(t.extract.output,r,e.namespace),l=s(process.cwd(),i);try{const o=await a(l);if(o){const a=t.extract.keySeparator??".";void 0!==c(o,e.key,a)&&n.push(`${r}:${e.fullKey}`)}}catch{}}return n}(v,g);if(S.length>0)return{success:!1,sourceFiles:[],translationFiles:[],conflicts:S,error:"Target key already exists in translation files"};k.info(`🔍 Scanning for usages of "${m}"...`);const j=await async function(r,o,a,i,s){const c=["node_modules/**"],l=Array.isArray(a.extract.ignore)?a.extract.ignore:a.extract.ignore?[a.extract.ignore]:[],u=await e(a.extract.input,{ignore:[...c,...l],cwd:process.cwd()}),f=[];for(const e of u){const c=await t(e,"utf-8"),{newCode:l,changes:u}=await d(c,r,o,a);u>0&&(i||await n(e,l,"utf-8"),f.push({path:e,changes:u}),s.info(` ${i?"(dry-run) ":""}✓ ${e} (${u} ${1===u?"change":"changes"})`))}f.length>0&&s.info(`\n📝 Source file changes: ${f.length} file${1===f.length?"":"s"}`);return f}(b,v,g,x,k),F=await async function(e,t,r,u,f){const p=[],g=r.extract.keySeparator??".";for(const y of r.locales){const d=o(r.extract.output,y,e.namespace),m=s(process.cwd(),d);try{const o=await a(m);if(!o)continue;const s=c(o,e.key,g);if(void 0===s)continue;if(w(o,e.key,g),l(o,t.key,s,g),!u){const e=i(o,r.extract.outputFormat,r.extract.indentation);await n(m,e,"utf-8")}p.push({path:m,updated:!0}),f.info(` ${u?"(dry-run) ":""}✓ ${m}`)}catch(e){}}p.length>0&&f.info(`\n📦 Translation file updates: ${p.length} file${1===p.length?"":"s"}`);return p}(b,v,g,x,k),R=j.reduce((e,t)=>e+t.changes,0);return!x&&R>0?(k.info("\n✨ Successfully renamed key!"),k.info(` Old: "${m}"`),k.info(` New: "${h}"`),await async function(){if(!await u("rename-key"))return;return console.log(p.yellow.bold("\n💡 Tip: Managing translations across multiple projects?")),console.log(" With locize, you can rename, move, and copy translation keys directly"),console.log(" in the web interface—no CLI needed. Perfect for collaboration with"),console.log(" translators and managing complex refactoring across namespaces."),console.log(` Learn more: ${p.cyan("https://www.locize.com/docs/how-can-a-segment-key-be-copied-moved-or-renamed")}`),f("rename-key")}()):0===R&&k.info(`\n⚠️ No usages found for "${m}"`),{success:!0,sourceFiles:j,translationFiles:F}}function y(e,t){const n=t.extract.nsSeparator??":";if(n&&e.includes(n)){const[t,...r]=e.split(n);return{namespace:t,key:r.join(n),fullKey:e}}return{namespace:t.extract.defaultNS||"translation",key:e,fullKey:e}}async function d(e,t,n,r){return function(e,t,n,r){let o=0,a=e;const i=r.extract.nsSeparator??":",s=e=>i&&e.includes(String(i))?n.fullKey:n.key,c=r.extract.functions||["t","*.t"],l=[];for(const e of c)if(e.startsWith("*.")){const n=m(e.substring(1));l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${m(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${m(t.key)}\\1`,"g"),original:t.key})}else{const n=m(e);l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${m(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${m(t.key)}\\1`,"g"),original:t.key})}for(const{pattern:e,original:t}of l)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>{o++;const r=e.match(/^(\w+(?:\.\w+)*)\(/);return r?`${r[1]}(${t}${n}${t}`:e})}const u=[{pattern:new RegExp(`i18nKey=(['"\`])${m(t.fullKey)}\\1`,"g"),original:t.fullKey},{pattern:new RegExp(`i18nKey=(['"\`])${m(t.key)}\\1`,"g"),original:t.key}];for(const{pattern:e,original:t}of u)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>(o++,`i18nKey=${t}${n}${t}`))}return{newCode:a,changes:o}}(e,t,n,r)}function m(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function w(e,t,n){if(!1===n)return void delete e[t];const r=t.split(String(n));let o=e;for(let e=0;e<r.length-1;e++){if(!o[r[e]])return;o=o[r[e]]}delete o[r[r.length-1]]}export{g as runRenameKey};
1
+ import{glob as e}from"glob";import{readFile as t,writeFile as n}from"node:fs/promises";import{ConsoleLogger as r}from"./utils/logger.js";import{getOutputPath as o,loadTranslationFile as a,serializeTranslationFile as i}from"./utils/file-utils.js";import{resolve as s}from"node:path";import{getNestedValue as c,setNestedValue as l}from"./utils/nested-object.js";import{shouldShowFunnel as u,recordFunnelShown as f}from"./utils/funnel-msg-tracker.js";import p from"chalk";async function g(g,m,h,$={},k=new r){const{dryRun:x=!1}=$,K=function(e,t){if(!e||!e.trim())return{valid:!1,error:"Old key cannot be empty"};if(!t||!t.trim())return{valid:!1,error:"New key cannot be empty"};if(e===t)return{valid:!1,error:"Old and new keys are identical"};return{valid:!0}}(m,h);if(!K.valid)return{success:!1,sourceFiles:[],translationFiles:[],error:K.error};const b=y(m,g),v=y(h,g),S=await async function(e,t){const n=[];for(const r of t.locales){const i=o(t.extract.output,r,e.namespace),l=s(process.cwd(),i);try{const o=await a(l);if(o){const a=t.extract.keySeparator??".";void 0!==c(o,e.key,a)&&n.push(`${r}:${e.fullKey}`)}}catch{}}return n}(v,g);if(S.length>0)return{success:!1,sourceFiles:[],translationFiles:[],conflicts:S,error:"Target key already exists in translation files"};k.info(`🔍 Scanning for usages of "${m}"...`);const j=await async function(r,o,a,i,s){const c=["node_modules/**"],l=Array.isArray(a.extract.ignore)?a.extract.ignore:a.extract.ignore?[a.extract.ignore]:[],u=Array.isArray(a.extract.input)?a.extract.input:[a.extract.input],f=u.map(e=>e.replace(/\\/g,"/")),p=await e(f,{ignore:[...c,...l],cwd:process.cwd()}),g=[];for(const e of p){const c=await t(e,"utf-8"),{newCode:l,changes:u}=await d(c,r,o,a);u>0&&(i||await n(e,l,"utf-8"),g.push({path:e,changes:u}),s.info(` ${i?"(dry-run) ":""}✓ ${e} (${u} ${1===u?"change":"changes"})`))}g.length>0&&s.info(`\n📝 Source file changes: ${g.length} file${1===g.length?"":"s"}`);return g}(b,v,g,x,k),F=await async function(e,t,r,u,f){const p=[],g=r.extract.keySeparator??".";for(const y of r.locales){const d=o(r.extract.output,y,e.namespace),m=s(process.cwd(),d);try{const o=await a(m);if(!o)continue;const s=c(o,e.key,g);if(void 0===s)continue;if(w(o,e.key,g),l(o,t.key,s,g),!u){const e=i(o,r.extract.outputFormat,r.extract.indentation);await n(m,e,"utf-8")}p.push({path:m,updated:!0}),f.info(` ${u?"(dry-run) ":""}✓ ${m}`)}catch(e){}}p.length>0&&f.info(`\n📦 Translation file updates: ${p.length} file${1===p.length?"":"s"}`);return p}(b,v,g,x,k),R=j.reduce((e,t)=>e+t.changes,0);return!x&&R>0?(k.info("\n✨ Successfully renamed key!"),k.info(` Old: "${m}"`),k.info(` New: "${h}"`),await async function(){if(!await u("rename-key"))return;return console.log(p.yellow.bold("\n💡 Tip: Managing translations across multiple projects?")),console.log(" With locize, you can rename, move, and copy translation keys directly"),console.log(" in the web interface—no CLI needed. Perfect for collaboration with"),console.log(" translators and managing complex refactoring across namespaces."),console.log(` Learn more: ${p.cyan("https://www.locize.com/docs/how-can-a-segment-key-be-copied-moved-or-renamed")}`),f("rename-key")}()):0===R&&k.info(`\n⚠️ No usages found for "${m}"`),{success:!0,sourceFiles:j,translationFiles:F}}function y(e,t){const n=t.extract.nsSeparator??":";if(n&&e.includes(n)){const[t,...r]=e.split(n);return{namespace:t,key:r.join(n),fullKey:e}}return{namespace:t.extract.defaultNS||"translation",key:e,fullKey:e}}async function d(e,t,n,r){return function(e,t,n,r){let o=0,a=e;const i=r.extract.nsSeparator??":",s=e=>i&&e.includes(String(i))?n.fullKey:n.key,c=r.extract.functions||["t","*.t"],l=[];for(const e of c)if(e.startsWith("*.")){const n=m(e.substring(1));l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${m(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\w+${n}\\((['"\`])${m(t.key)}\\1`,"g"),original:t.key})}else{const n=m(e);l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${m(t.fullKey)}\\1`,"g"),original:t.fullKey}),l.push({pattern:new RegExp(`\\b${n}\\((['"\`])${m(t.key)}\\1`,"g"),original:t.key})}for(const{pattern:e,original:t}of l)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>{o++;const r=e.match(/^(\w+(?:\.\w+)*)\(/);return r?`${r[1]}(${t}${n}${t}`:e})}const u=[{pattern:new RegExp(`i18nKey=(['"\`])${m(t.fullKey)}\\1`,"g"),original:t.fullKey},{pattern:new RegExp(`i18nKey=(['"\`])${m(t.key)}\\1`,"g"),original:t.key}];for(const{pattern:e,original:t}of u)if(e.test(a)){const n=s(t);a=a.replace(e,(e,t)=>(o++,`i18nKey=${t}${n}${t}`))}return{newCode:a,changes:o}}(e,t,n,r)}function m(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function w(e,t,n){if(!1===n)return void delete e[t];const r=t.split(String(n));let o=e;for(let e=0;e<r.length-1;e++){if(!o[r[e]])return;o=o[r[e]]}delete o[r[r.length-1]]}export{g as runRenameKey};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.24.0",
3
+ "version": "1.24.1",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.ts CHANGED
@@ -23,7 +23,7 @@ const program = new Command()
23
23
  program
24
24
  .name('i18next-cli')
25
25
  .description('A unified, high-performance i18next CLI.')
26
- .version('1.24.0')
26
+ .version('1.24.1')
27
27
 
28
28
  // new: global config override option
29
29
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)')
package/src/rename-key.ts CHANGED
@@ -196,7 +196,16 @@ async function updateSourceFiles (
196
196
  ? config.extract.ignore
197
197
  : config.extract.ignore ? [config.extract.ignore] : []
198
198
 
199
- const sourceFiles = await glob(config.extract.input, {
199
+ // Normalize input patterns for cross-platform compatibility
200
+ const inputPatterns = Array.isArray(config.extract.input)
201
+ ? config.extract.input
202
+ : [config.extract.input]
203
+
204
+ const normalizedPatterns = inputPatterns.map(pattern =>
205
+ pattern.replace(/\\/g, '/')
206
+ )
207
+
208
+ const sourceFiles = await glob(normalizedPatterns, {
200
209
  ignore: [...defaultIgnore, ...userIgnore],
201
210
  cwd: process.cwd()
202
211
  })