i18next-cli 1.13.0 → 1.13.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.13.1](https://github.com/i18next/i18next-cli/compare/v1.13.0...v1.13.1) - 2025-10-27
9
+
10
+ - fix: Self Closing Tags are not ignored by linter even when put in ignoredTags [#75](https://github.com/i18next/i18next-cli/issues/75)
11
+
8
12
  ## [1.13.0](https://github.com/i18next/i18next-cli/compare/v1.12.1...v1.13.0) - 2025-10-24
9
13
 
10
14
  - Extract: add support for `defaultNS: false`. When enabled, the extractor will not generate or wrap keys under a namespace and will output a single language JSON with top-level keys (useful for projects that keep translations in a single file per language). Preserves existing behavior when omitted or set to a string. [#73](https://github.com/i18next/i18next-cli/issues/73)
package/README.md CHANGED
@@ -840,6 +840,10 @@ class I18nextExtractionPlugin {
840
840
 
841
841
  This programmatic API gives you the same power as the CLI but with full control over when and how it runs in your build process.
842
842
 
843
+ ## Known plugins
844
+
845
+ - [i18next-cli-plugin-svelte](https://github.com/dreamscached/i18next-cli-plugin-svelte) — a simple plugin to extract translation keys from Svelte components
846
+
843
847
  ---
844
848
 
845
849
  <h3 align="center">Gold Sponsors</h3>
package/dist/cjs/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var e=require("commander"),t=require("chokidar"),n=require("glob"),o=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=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"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.13.0"),m.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 n=await a.ensureConfig(),i=async()=>{const t=await c.runExtractor(n,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:!!e.syncPrimary});return e.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):e.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await i(),e.watch){console.log("\nWatching for changes...");const e=await w(n.extract.input),a=y(n.extract.ignore),r=h(n.extract.output),c=[...a,...r].filter(Boolean),s=e.filter(e=>!c.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),i()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),m.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,t)=>{let n=await a.loadConfig();if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await r.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 p.runStatus(n,{detail:e,namespace:t.namespace})}),m.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 n=await a.ensureConfig(),i=()=>s.runTypesGenerator(n);if(await i(),e.watch){console.log("\nWatching for changes...");const e=await w(n.types?.input||[]),a=[...y(n.extract?.ignore)].filter(Boolean),r=e.filter(e=>!a.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),i()})}}),m.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=await a.ensureConfig();await l.runSyncer(e)}),m.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await u.runMigrator(e)}),m.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d.runInit),m.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 n=async()=>{let e=await a.loadConfig();if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await r.detectConfig();t||(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=t}await g.runLinter(e)};if(await n(),e.watch){console.log("\nWatching for changes...");const e=await a.loadConfig();if(e?.extract?.input){const i=await w(e.extract.input),a=[...y(e.extract.ignore),...h(e.extract.output)].filter(Boolean),r=i.filter(e=>!a.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),n()})}}}),m.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 t=await a.ensureConfig();await f.runLocizeSync(t,e)}),m.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const t=await a.ensureConfig();await f.runLocizeDownload(t,e)}),m.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const t=await a.ensureConfig();await f.runLocizeMigrate(t,e)}),m.parse(process.argv);const y=e=>Array.isArray(e)?e:e?[e]:[],h=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],w=async(e=[])=>{const t=y(e),o=await Promise.all(t.map(e=>n.glob(e||"",{nodir:!0})));return Array.from(new Set(o.flat()))};
2
+ "use strict";var e=require("commander"),t=require("chokidar"),n=require("glob"),o=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=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"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.13.1"),m.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 n=await a.ensureConfig(),i=async()=>{const t=await c.runExtractor(n,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:!!e.syncPrimary});return e.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):e.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await i(),e.watch){console.log("\nWatching for changes...");const e=await w(n.extract.input),a=y(n.extract.ignore),r=h(n.extract.output),c=[...a,...r].filter(Boolean),s=e.filter(e=>!c.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),i()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),m.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,t)=>{let n=await a.loadConfig();if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await r.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 p.runStatus(n,{detail:e,namespace:t.namespace})}),m.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 n=await a.ensureConfig(),i=()=>s.runTypesGenerator(n);if(await i(),e.watch){console.log("\nWatching for changes...");const e=await w(n.types?.input||[]),a=[...y(n.extract?.ignore)].filter(Boolean),r=e.filter(e=>!a.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),i()})}}),m.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=await a.ensureConfig();await l.runSyncer(e)}),m.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await u.runMigrator(e)}),m.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d.runInit),m.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 n=async()=>{let e=await a.loadConfig();if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await r.detectConfig();t||(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=t}await g.runLinter(e)};if(await n(),e.watch){console.log("\nWatching for changes...");const e=await a.loadConfig();if(e?.extract?.input){const i=await w(e.extract.input),a=[...y(e.extract.ignore),...h(e.extract.output)].filter(Boolean),r=i.filter(e=>!a.some(t=>o.minimatch(e,t,{dot:!0})));t.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),n()})}}}),m.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 t=await a.ensureConfig();await f.runLocizeSync(t,e)}),m.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const t=await a.ensureConfig();await f.runLocizeDownload(t,e)}),m.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const t=await a.ensureConfig();await f.runLocizeMigrate(t,e)}),m.parse(process.argv);const y=e=>Array.isArray(e)?e:e?[e]:[],h=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],w=async(e=[])=>{const t=y(e),o=await Promise.all(t.map(e=>n.glob(e||"",{nodir:!0})));return Array.from(new Set(o.flat()))};
@@ -1 +1 @@
1
- "use strict";var e=require("glob"),t=require("node:fs/promises"),r=require("@swc/core"),n=require("chalk"),s=require("ora");const o=e=>/^(https|http|\/\/|^\/)/.test(e);function i(e,t,r){const n=[],s=[],i=e=>t.substring(0,e).split("\n").length,a=r.extract.transComponents||["Trans"],c=r.extract.ignoredTags||[],l=new Set([...a,"script","style","code",...c]),u=r.extract.ignoredAttributes||[],f=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...u]),p=(e,t)=>{if(!e||"object"!=typeof e)return;const r=[...t,e];if("JSXText"===e.type){if(!r.some(e=>{if("JSXElement"!==e.type)return!1;const t=e.opening?.name?.value;return l.has(t)})){const t=e.value.trim();t&&t.length>1&&"..."!==t&&!o(t)&&isNaN(Number(t))&&!t.startsWith("{{")&&s.push(e)}}if("StringLiteral"===e.type){const t=r[r.length-2];if("JSXAttribute"===t?.type&&!f.has(t.name.value)){const t=e.value.trim();t&&"..."!==t&&!o(t)&&isNaN(Number(t))&&s.push(e)}}for(const t of Object.keys(e)){if("span"===t)continue;const n=e[t];Array.isArray(n)?n.forEach(e=>p(e,r)):n&&"object"==typeof n&&p(n,r)}};p(e,[]);let g=0;for(const e of s){const r=e.raw??e.value,s=t.indexOf(r,g);s>-1&&(n.push({text:e.value.trim(),line:i(s)}),g=s+r.length)}return n}exports.runLinter=async function(o){const a=s("Analyzing source files...\n").start();try{const s=["node_modules/**"],c=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[],l=await e.glob(o.extract.input,{ignore:[...s,...c]});let u=0;const f=new Map;for(const e of l){const n=await t.readFile(e,"utf-8"),s=i(await r.parse(n,{syntax:"typescript",tsx:!0,decorators:!0}),n,o);s.length>0&&(u+=s.length,f.set(e,s))}if(u>0){a.fail(n.red.bold(`Linter found ${u} potential issues.`));for(const[e,t]of f.entries())console.log(n.yellow(`\n${e}`)),t.forEach(({text:e,line:t})=>{console.log(` ${n.gray(`${t}:`)} ${n.red("Error:")} Found hardcoded string: "${e}"`)});process.exit(1)}else a.succeed(n.green.bold("No issues found."))}catch(e){a.fail(n.red("Linter failed to run.")),console.error(e),process.exit(1)}};
1
+ "use strict";var e=require("glob"),t=require("node:fs/promises"),n=require("@swc/core"),r=require("chalk"),o=require("ora");const s=e=>/^(https|http|\/\/|^\/)/.test(e);function i(e,t,n){const r=[],o=[],i=e=>t.substring(0,e).split("\n").length,a=n.extract.transComponents||["Trans"],l=n.extract.ignoredTags||[],c=new Set([...a,"script","style","code",...l]),u=n.extract.ignoredAttributes||[],f=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...u]),p=e=>{if(!e)return null;const t=e.name??e.opening?.name??e.opening?.name;if(!t)return e.opening?.name?p({name:e.opening.name}):null;const n=e=>{if(!e)return null;if("JSXIdentifier"===e.type&&(e.name||e.value))return e.name??e.value;if("Identifier"===e.type&&(e.name||e.value))return e.name??e.value;if("JSXMemberExpression"===e.type){const t=n(e.object),r=n(e.property);return t&&r?`${t}.${r}`:r??t}return e.name??e.value??e.property?.name??e.property?.value??null};return n(t)},g=e=>{for(let t=e.length-1;t>=0;t--){const n=e[t];if(n&&"object"==typeof n&&("JSXElement"===n.type||"JSXOpeningElement"===n.type||"JSXSelfClosingElement"===n.type)){const e=p(n);if(e&&c.has(e))return!0}}return!1},y=(e,t)=>{if(!e||"object"!=typeof e)return;const n=[...t,e];if("JSXText"===e.type){if(!g(n)){const t=e.value.trim();t&&t.length>1&&"..."!==t&&!s(t)&&isNaN(Number(t))&&!t.startsWith("{{")&&o.push(e)}}if("StringLiteral"===e.type){const t=n[n.length-2],r=g(n);if("JSXAttribute"===t?.type&&!f.has(t.name.value)&&!r){const t=e.value.trim();t&&"..."!==t&&!s(t)&&isNaN(Number(t))&&o.push(e)}}for(const t of Object.keys(e)){if("span"===t)continue;const r=e[t];Array.isArray(r)?r.forEach(e=>y(e,n)):r&&"object"==typeof r&&y(r,n)}};y(e,[]);let d=0;for(const e of o){const n=e.raw??e.value,o=t.indexOf(n,d);o>-1&&(r.push({text:e.value.trim(),line:i(o)}),d=o+n.length)}return r}exports.runLinter=async function(s){const a=o("Analyzing source files...\n").start();try{const o=["node_modules/**"],l=Array.isArray(s.extract.ignore)?s.extract.ignore:s.extract.ignore?[s.extract.ignore]:[],c=await e.glob(s.extract.input,{ignore:[...o,...l]});let u=0;const f=new Map;for(const e of c){const r=await t.readFile(e,"utf-8"),o=i(await n.parse(r,{syntax:"typescript",tsx:!0,decorators:!0}),r,s);o.length>0&&(u+=o.length,f.set(e,o))}if(u>0){a.fail(r.red.bold(`Linter found ${u} potential issues.`));for(const[e,t]of f.entries())console.log(r.yellow(`\n${e}`)),t.forEach(({text:e,line:t})=>{console.log(` ${r.gray(`${t}:`)} ${r.red("Error:")} Found hardcoded string: "${e}"`)});process.exit(1)}else a.succeed(r.green.bold("No issues found."))}catch(e){a.fail(r.red("Linter failed to run.")),console.error(e),process.exit(1)}};
package/dist/esm/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{Command as t}from"commander";import e from"chokidar";import{glob as o}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 m}from"./migrator.js";import{runInit as d}from"./init.js";import{runLinter as f}from"./linter.js";import{runStatus as u}from"./status.js";import{runLocizeSync as g,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.13.0"),w.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 t=>{try{const o=await a(),i=async()=>{const e=await s(o,{isWatchMode:!!t.watch,isDryRun:!!t.dryRun,syncPrimaryWithDefaults:!!t.syncPrimary});return t.ci&&!e?(console.log("✅ No files were updated."),process.exit(0)):t.ci&&e&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),e};if(await i(),t.watch){console.log("\nWatching for changes...");const t=await z(o.extract.input),a=x(o.extract.ignore),r=j(o.extract.output),c=[...a,...r].filter(Boolean),s=t.filter(t=>!c.some(e=>n(t,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),i()})}}catch(t){console.error("Error running extractor:",t),process.exit(1)}}),w.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(t,e)=>{let o=await r();if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await c();t||(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=t}await u(o,{detail:t,namespace:e.namespace})}),w.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 t=>{const o=await a(),i=()=>l(o);if(await i(),t.watch){console.log("\nWatching for changes...");const t=await z(o.types?.input||[]),a=[...x(o.extract?.ignore)].filter(Boolean),r=t.filter(t=>!a.some(e=>n(t,e,{dot:!0})));e.watch(r,{persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),i()})}}),w.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const t=await a();await p(t)}),w.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async t=>{await m(t)}),w.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d),w.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 t=>{const o=async()=>{let t=await r();if(!t){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!")),t=e}await f(t)};if(await o(),t.watch){console.log("\nWatching for changes...");const t=await r();if(t?.extract?.input){const i=await z(t.extract.input),a=[...x(t.extract.ignore),...j(t.extract.output)].filter(Boolean),r=i.filter(t=>!a.some(e=>n(t,e,{dot:!0})));e.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),o()})}}}),w.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 t=>{const e=await a();await g(e,t)}),w.command("locize-download").description("Download all translations from your locize project.").action(async t=>{const e=await a();await y(e,t)}),w.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async t=>{const e=await a();await h(e,t)}),w.parse(process.argv);const x=t=>Array.isArray(t)?t:t?[t]:[],j=t=>t&&"string"==typeof t?[t.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(t=[])=>{const e=x(t),n=await Promise.all(e.map(t=>o(t||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
2
+ import{Command as t}from"commander";import e from"chokidar";import{glob as o}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 m}from"./migrator.js";import{runInit as d}from"./init.js";import{runLinter as f}from"./linter.js";import{runStatus as u}from"./status.js";import{runLocizeSync as g,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.13.1"),w.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 t=>{try{const o=await a(),i=async()=>{const e=await s(o,{isWatchMode:!!t.watch,isDryRun:!!t.dryRun,syncPrimaryWithDefaults:!!t.syncPrimary});return t.ci&&!e?(console.log("✅ No files were updated."),process.exit(0)):t.ci&&e&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),e};if(await i(),t.watch){console.log("\nWatching for changes...");const t=await z(o.extract.input),a=x(o.extract.ignore),r=j(o.extract.output),c=[...a,...r].filter(Boolean),s=t.filter(t=>!c.some(e=>n(t,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),i()})}}catch(t){console.error("Error running extractor:",t),process.exit(1)}}),w.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(t,e)=>{let o=await r();if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await c();t||(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=t}await u(o,{detail:t,namespace:e.namespace})}),w.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 t=>{const o=await a(),i=()=>l(o);if(await i(),t.watch){console.log("\nWatching for changes...");const t=await z(o.types?.input||[]),a=[...x(o.extract?.ignore)].filter(Boolean),r=t.filter(t=>!a.some(e=>n(t,e,{dot:!0})));e.watch(r,{persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),i()})}}),w.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const t=await a();await p(t)}),w.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async t=>{await m(t)}),w.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(d),w.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 t=>{const o=async()=>{let t=await r();if(!t){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!")),t=e}await f(t)};if(await o(),t.watch){console.log("\nWatching for changes...");const t=await r();if(t?.extract?.input){const i=await z(t.extract.input),a=[...x(t.extract.ignore),...j(t.extract.output)].filter(Boolean),r=i.filter(t=>!a.some(e=>n(t,e,{dot:!0})));e.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),o()})}}}),w.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 t=>{const e=await a();await g(e,t)}),w.command("locize-download").description("Download all translations from your locize project.").action(async t=>{const e=await a();await y(e,t)}),w.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async t=>{const e=await a();await h(e,t)}),w.parse(process.argv);const x=t=>Array.isArray(t)?t:t?[t]:[],j=t=>t&&"string"==typeof t?[t.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(t=[])=>{const e=x(t),n=await Promise.all(e.map(t=>o(t||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
@@ -1 +1 @@
1
- import{glob as t}from"glob";import{readFile as e}from"node:fs/promises";import{parse as r}from"@swc/core";import o from"chalk";import n from"ora";async function s(s){const i=n("Analyzing source files...\n").start();try{const n=["node_modules/**"],c=Array.isArray(s.extract.ignore)?s.extract.ignore:s.extract.ignore?[s.extract.ignore]:[],l=await t(s.extract.input,{ignore:[...n,...c]});let f=0;const u=new Map;for(const t of l){const o=await e(t,"utf-8"),n=a(await r(o,{syntax:"typescript",tsx:!0,decorators:!0}),o,s);n.length>0&&(f+=n.length,u.set(t,n))}if(f>0){i.fail(o.red.bold(`Linter found ${f} potential issues.`));for(const[t,e]of u.entries())console.log(o.yellow(`\n${t}`)),e.forEach(({text:t,line:e})=>{console.log(` ${o.gray(`${e}:`)} ${o.red("Error:")} Found hardcoded string: "${t}"`)});process.exit(1)}else i.succeed(o.green.bold("No issues found."))}catch(t){i.fail(o.red("Linter failed to run.")),console.error(t),process.exit(1)}}const i=t=>/^(https|http|\/\/|^\/)/.test(t);function a(t,e,r){const o=[],n=[],s=t=>e.substring(0,t).split("\n").length,a=r.extract.transComponents||["Trans"],c=r.extract.ignoredTags||[],l=new Set([...a,"script","style","code",...c]),f=r.extract.ignoredAttributes||[],u=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...f]),p=(t,e)=>{if(!t||"object"!=typeof t)return;const r=[...e,t];if("JSXText"===t.type){if(!r.some(t=>{if("JSXElement"!==t.type)return!1;const e=t.opening?.name?.value;return l.has(e)})){const e=t.value.trim();e&&e.length>1&&"..."!==e&&!i(e)&&isNaN(Number(e))&&!e.startsWith("{{")&&n.push(t)}}if("StringLiteral"===t.type){const e=r[r.length-2];if("JSXAttribute"===e?.type&&!u.has(e.name.value)){const e=t.value.trim();e&&"..."!==e&&!i(e)&&isNaN(Number(e))&&n.push(t)}}for(const e of Object.keys(t)){if("span"===e)continue;const o=t[e];Array.isArray(o)?o.forEach(t=>p(t,r)):o&&"object"==typeof o&&p(o,r)}};p(t,[]);let g=0;for(const t of n){const r=t.raw??t.value,n=e.indexOf(r,g);n>-1&&(o.push({text:t.value.trim(),line:s(n)}),g=n+r.length)}return o}export{s as runLinter};
1
+ import{glob as e}from"glob";import{readFile as t}from"node:fs/promises";import{parse as n}from"@swc/core";import r from"chalk";import o from"ora";async function s(s){const i=o("Analyzing source files...\n").start();try{const o=["node_modules/**"],l=Array.isArray(s.extract.ignore)?s.extract.ignore:s.extract.ignore?[s.extract.ignore]:[],c=await e(s.extract.input,{ignore:[...o,...l]});let f=0;const u=new Map;for(const e of c){const r=await t(e,"utf-8"),o=a(await n(r,{syntax:"typescript",tsx:!0,decorators:!0}),r,s);o.length>0&&(f+=o.length,u.set(e,o))}if(f>0){i.fail(r.red.bold(`Linter found ${f} potential issues.`));for(const[e,t]of u.entries())console.log(r.yellow(`\n${e}`)),t.forEach(({text:e,line:t})=>{console.log(` ${r.gray(`${t}:`)} ${r.red("Error:")} Found hardcoded string: "${e}"`)});process.exit(1)}else i.succeed(r.green.bold("No issues found."))}catch(e){i.fail(r.red("Linter failed to run.")),console.error(e),process.exit(1)}}const i=e=>/^(https|http|\/\/|^\/)/.test(e);function a(e,t,n){const r=[],o=[],s=e=>t.substring(0,e).split("\n").length,a=n.extract.transComponents||["Trans"],l=n.extract.ignoredTags||[],c=new Set([...a,"script","style","code",...l]),f=n.extract.ignoredAttributes||[],u=new Set(["className","key","id","style","href","i18nKey","defaults","type","target",...f]),p=e=>{if(!e)return null;const t=e.name??e.opening?.name??e.opening?.name;if(!t)return e.opening?.name?p({name:e.opening.name}):null;const n=e=>{if(!e)return null;if("JSXIdentifier"===e.type&&(e.name||e.value))return e.name??e.value;if("Identifier"===e.type&&(e.name||e.value))return e.name??e.value;if("JSXMemberExpression"===e.type){const t=n(e.object),r=n(e.property);return t&&r?`${t}.${r}`:r??t}return e.name??e.value??e.property?.name??e.property?.value??null};return n(t)},m=e=>{for(let t=e.length-1;t>=0;t--){const n=e[t];if(n&&"object"==typeof n&&("JSXElement"===n.type||"JSXOpeningElement"===n.type||"JSXSelfClosingElement"===n.type)){const e=p(n);if(e&&c.has(e))return!0}}return!1},y=(e,t)=>{if(!e||"object"!=typeof e)return;const n=[...t,e];if("JSXText"===e.type){if(!m(n)){const t=e.value.trim();t&&t.length>1&&"..."!==t&&!i(t)&&isNaN(Number(t))&&!t.startsWith("{{")&&o.push(e)}}if("StringLiteral"===e.type){const t=n[n.length-2],r=m(n);if("JSXAttribute"===t?.type&&!u.has(t.name.value)&&!r){const t=e.value.trim();t&&"..."!==t&&!i(t)&&isNaN(Number(t))&&o.push(e)}}for(const t of Object.keys(e)){if("span"===t)continue;const r=e[t];Array.isArray(r)?r.forEach(e=>y(e,n)):r&&"object"==typeof r&&y(r,n)}};y(e,[]);let g=0;for(const e of o){const n=e.raw??e.value,o=t.indexOf(n,g);o>-1&&(r.push({text:e.value.trim(),line:s(o)}),g=o+n.length)}return r}export{s as runLinter};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.ts CHANGED
@@ -22,7 +22,7 @@ const program = new Command()
22
22
  program
23
23
  .name('i18next-cli')
24
24
  .description('A unified, high-performance i18next CLI.')
25
- .version('1.13.0')
25
+ .version('1.13.1')
26
26
 
27
27
  program
28
28
  .command('extract')
package/src/linter.ts CHANGED
@@ -143,6 +143,46 @@ function findHardcodedStrings (ast: any, code: string, config: I18nextToolkitCon
143
143
  const customIgnoredAttributes = config.extract.ignoredAttributes || []
144
144
  const ignoredAttributes = new Set([...defaultIgnoredAttributes, ...customIgnoredAttributes])
145
145
 
146
+ // Helper: robustly extract a JSX element name from different node shapes
147
+ const extractJSXName = (node: any): string | null => {
148
+ if (!node) return null
149
+ // node might be JSXOpeningElement / JSXSelfClosingElement (has .name)
150
+ const nameNode = node.name ?? node.opening?.name ?? node.opening?.name
151
+ if (!nameNode) {
152
+ // maybe this node is a full JSXElement with opening.name
153
+ if (node.opening?.name) return extractJSXName({ name: node.opening.name })
154
+ return null
155
+ }
156
+
157
+ const fromIdentifier = (n: any): string | null => {
158
+ if (!n) return null
159
+ if (n.type === 'JSXIdentifier' && (n.name || n.value)) return (n.name ?? n.value)
160
+ if (n.type === 'Identifier' && (n.name || n.value)) return (n.name ?? n.value)
161
+ if (n.type === 'JSXMemberExpression') {
162
+ const object = fromIdentifier(n.object)
163
+ const property = fromIdentifier(n.property)
164
+ return object && property ? `${object}.${property}` : (property ?? object)
165
+ }
166
+ // fallback attempts
167
+ return n.name ?? n.value ?? n.property?.name ?? n.property?.value ?? null
168
+ }
169
+
170
+ return fromIdentifier(nameNode)
171
+ }
172
+
173
+ // Helper: return true if any JSX ancestor is in the ignored tags set
174
+ const isWithinIgnoredElement = (ancestors: any[]): boolean => {
175
+ for (let i = ancestors.length - 1; i >= 0; i--) {
176
+ const an = ancestors[i]
177
+ if (!an || typeof an !== 'object') continue
178
+ if (an.type === 'JSXElement' || an.type === 'JSXOpeningElement' || an.type === 'JSXSelfClosingElement') {
179
+ const name = extractJSXName(an)
180
+ if (name && allIgnoredTags.has(name)) return true
181
+ }
182
+ }
183
+ return false
184
+ }
185
+
146
186
  // --- PHASE 1: Collect all potentially problematic nodes ---
147
187
  const walk = (node: any, ancestors: any[]) => {
148
188
  if (!node || typeof node !== 'object') return
@@ -150,11 +190,7 @@ function findHardcodedStrings (ast: any, code: string, config: I18nextToolkitCon
150
190
  const currentAncestors = [...ancestors, node]
151
191
 
152
192
  if (node.type === 'JSXText') {
153
- const isIgnored = currentAncestors.some(ancestorNode => {
154
- if (ancestorNode.type !== 'JSXElement') return false
155
- const elementName = ancestorNode.opening?.name?.value
156
- return allIgnoredTags.has(elementName)
157
- })
193
+ const isIgnored = isWithinIgnoredElement(currentAncestors)
158
194
 
159
195
  if (!isIgnored) {
160
196
  const text = node.value.trim()
@@ -167,7 +203,10 @@ function findHardcodedStrings (ast: any, code: string, config: I18nextToolkitCon
167
203
 
168
204
  if (node.type === 'StringLiteral') {
169
205
  const parent = currentAncestors[currentAncestors.length - 2]
170
- if (parent?.type === 'JSXAttribute' && !ignoredAttributes.has(parent.name.value)) {
206
+ // Determine whether this attribute is inside any ignored element (handles nested Trans etc.)
207
+ const insideIgnored = isWithinIgnoredElement(currentAncestors)
208
+
209
+ if (parent?.type === 'JSXAttribute' && !ignoredAttributes.has(parent.name.value) && !insideIgnored) {
171
210
  const text = node.value.trim()
172
211
  // Filter out: empty strings, URLs, numbers, and ellipsis
173
212
  if (text && text !== '...' && !isUrlOrPath(text) && isNaN(Number(text))) {