i18next-cli 1.12.1 → 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,14 @@ 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
+
12
+ ## [1.13.0](https://github.com/i18next/i18next-cli/compare/v1.12.1...v1.13.0) - 2025-10-24
13
+
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)
15
+
8
16
  ## [1.12.1](https://github.com/i18next/i18next-cli/compare/v1.12.0...v1.12.1) - 2025-10-23
9
17
 
10
18
  - try to improve linter for spread operator usage [#72](https://github.com/i18next/i18next-cli/issues/72)
package/README.md CHANGED
@@ -338,7 +338,7 @@ export default defineConfig({
338
338
  ignoredTags: ['pre'],
339
339
 
340
340
  // Namespace and key configuration
341
- defaultNS: 'translation',
341
+ defaultNS: 'translation', // If set to false it will not generate any namespace, useful if i.e. the output is a single language json with 1 namespace (and no nesting).
342
342
  nsSeparator: ':',
343
343
  keySeparator: '.', // Or `false` to disable nesting and use flat keys
344
344
  contextSeparator: '_',
@@ -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.12.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()))};
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("node:path"),t=require("glob"),s=require("../../utils/nested-object.js"),r=require("../../utils/file-utils.js"),n=require("../../utils/default-value.js");function a(e){const t=`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(t)}function o(e,t){if("object"!=typeof e||null===e||Array.isArray(e))return e;const s={},r=t?.extract?.pluralSeparator??"_",n=["zero","one","two","few","many","other"],a=n.map(e=>`ordinal${r}${e}`),l=Object.keys(e).sort((e,t)=>{const s=e=>{for(const t of a)if(e.endsWith(`${r}${t}`)){return{base:e.slice(0,-(r.length+t.length)),form:t,isOrdinal:!0,isPlural:!0,fullKey:e}}for(const t of n)if(e.endsWith(`${r}${t}`)){return{base:e.slice(0,-(r.length+t.length)),form:t,isOrdinal:!1,isPlural:!0,fullKey:e}}return{base:e,form:"",isOrdinal:!1,isPlural:!1,fullKey:e}},o=s(e),l=s(t);if(o.isPlural&&l.isPlural){const e=o.base.localeCompare(l.base,void 0,{sensitivity:"base"});if(0!==e)return e;if(o.isOrdinal!==l.isOrdinal)return o.isOrdinal?1:-1;const t=o.isOrdinal?a:n,s=t.indexOf(o.form),r=t.indexOf(l.form);return-1!==s&&-1!==r?s-r:o.form.localeCompare(l.form)}const i=e.localeCompare(t,void 0,{sensitivity:"base"});return 0===i?e.localeCompare(t,void 0,{sensitivity:"case"}):i});for(const r of l)s[r]=o(e[r],t);return s}function l(e,t,r,a,l,i,c,u=!1){const{keySeparator:f=".",sort:d=!0,removeUnusedKeys:p=!0,primaryLanguage:g,defaultValue:y="",pluralSeparator:h="_",contextSeparator:m="_"}=r.extract,x=new Set;try{const e=new Intl.PluralRules(a,{type:"cardinal"}),t=new Intl.PluralRules(a,{type:"ordinal"});e.resolvedOptions().pluralCategories.forEach(e=>x.add(e)),t.resolvedOptions().pluralCategories.forEach(e=>x.add(`ordinal_${e}`))}catch(e){const t=new Intl.PluralRules(g||"en",{type:"cardinal"}),s=new Intl.PluralRules(g||"en",{type:"ordinal"});t.resolvedOptions().pluralCategories.forEach(e=>x.add(e)),s.resolvedOptions().pluralCategories.forEach(e=>x.add(`ordinal_${e}`))}const O=e.filter(({key:e,hasCount:t,isOrdinal:s})=>{if(i.some(t=>t.test(e)))return!1;if(!t)return!0;const r=e.split(h);if(s&&r.includes("ordinal")){const e=r[r.length-1];return x.has(`ordinal_${e}`)}if(t){const e=r[r.length-1];return x.has(e)}return!0});let v=p?{}:JSON.parse(JSON.stringify(t));const w=s.getNestedKeys(t,f??".");for(const e of w)if(i.some(t=>t.test(e))){const r=s.getNestedValue(t,e,f??".");s.setNestedValue(v,e,r,f??".")}if(p){const e=s.getNestedKeys(t,f??".");for(const r of e){const e=r.split(h);if("zero"===e[e.length-1]){const n=e.slice(0,-1).join(h);if(O.some(({key:e})=>e.split(h).slice(0,-1).join(h)===n)){const e=s.getNestedValue(t,r,f??".");s.setNestedValue(v,r,e,f??".")}}}}for(const{key:e,defaultValue:r,explicitDefault:o}of O){const i=s.getNestedValue(t,e,f??"."),d=!O.some(t=>t.key.startsWith(`${e}${f}`)&&t.key!==e),p="object"==typeof i&&null!==i&&(c.has(e)||!r||r===e),x="object"==typeof i&&null!==i&&d&&!c.has(e)&&!p;if(p){s.setNestedValue(v,e,i,f??".");continue}let w;if(void 0===i||x)if(a===g)if(u){const t=r&&(r===e||e!==r&&(e.startsWith(r+h)||e.startsWith(r+m)));w=r&&!t?r:n.resolveDefaultValue(y,e,l,a,r)}else w=r||e;else w=n.resolveDefaultValue(y,e,l,a,r);else if(a===g&&u){const t=r&&(r===e||e!==r&&(e.startsWith(r+h)||e.startsWith(r+m)));w=(e.includes(h)||e.includes(m))&&!o?i:r&&!t?r:i}else w=i;s.setNestedValue(v,e,w,f??".")}if(!0===d)return o(v,r);if("function"==typeof d){const e={},t=Object.keys(v),s=new Map;for(const e of O){const t=!1===f?e.key:e.key.split(f)[0];s.has(t)||s.set(t,e)}t.sort((e,t)=>{if("function"==typeof d){const r=s.get(e),n=s.get(t);if(r&&n)return d(r,n)}return e.localeCompare(t,void 0,{sensitivity:"base"})});for(const s of t)e[s]=o(v[s],r);v=e}return v}exports.getTranslations=async function(s,n,o,{syncPrimaryWithDefaults:i=!1}={}){o.extract.primaryLanguage||=o.locales[0]||"en",o.extract.secondaryLanguages||=o.locales.filter(e=>e!==o?.extract?.primaryLanguage);const c=o.extract.defaultNS??"translation",u=[...o.extract.preservePatterns||[]],f=o.extract.indentation??2;for(const e of n)u.push(`${e}.*`);const d=u.map(a),p=new Map;for(const e of s.values()){const t=e.ns||c;p.has(t)||p.set(t,[]),p.get(t).push(e)}const g=[],y=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[];for(const s of o.locales){if(o.extract.mergeNamespaces||!o.extract.output.includes("{{namespace}}")){const t={},a=r.getOutputPath(o.extract.output,s),c=e.resolve(process.cwd(),a),u=await r.loadTranslationFile(c)||{},y=new Set([...p.keys(),...Object.keys(u)]);for(const e of y){const r=p.get(e)||[],a=u[e]||{};t[e]=l(r,a,o,s,e,d,n,i)}const h=JSON.stringify(u,null,f),m=JSON.stringify(t,null,f);g.push({path:c,updated:m!==h,newTranslations:t,existingTranslations:u})}else{const a=new Set(p.keys()),c=r.getOutputPath(o.extract.output,s,"*"),u=await t.glob(c,{ignore:y});for(const t of u)a.add(e.basename(t,e.extname(t)));for(const t of a){const a=p.get(t)||[],c=r.getOutputPath(o.extract.output,s,t),u=e.resolve(process.cwd(),c),y=await r.loadTranslationFile(u)||{},h=l(a,y,o,s,t,d,n,i),m=JSON.stringify(y,null,f),x=JSON.stringify(h,null,f);g.push({path:u,updated:x!==m,newTranslations:h,existingTranslations:y})}}}return g};
1
+ "use strict";var e=require("node:path"),t=require("glob"),s=require("../../utils/nested-object.js"),r=require("../../utils/file-utils.js"),n=require("../../utils/default-value.js");function a(e){const t=`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(t)}function o(e,t){if("object"!=typeof e||null===e||Array.isArray(e))return e;const s={},r=t?.extract?.pluralSeparator??"_",n=["zero","one","two","few","many","other"],a=n.map(e=>`ordinal${r}${e}`),l=Object.keys(e).sort((e,t)=>{const s=e=>{for(const t of a)if(e.endsWith(`${r}${t}`)){return{base:e.slice(0,-(r.length+t.length)),form:t,isOrdinal:!0,isPlural:!0,fullKey:e}}for(const t of n)if(e.endsWith(`${r}${t}`)){return{base:e.slice(0,-(r.length+t.length)),form:t,isOrdinal:!1,isPlural:!0,fullKey:e}}return{base:e,form:"",isOrdinal:!1,isPlural:!1,fullKey:e}},o=s(e),l=s(t);if(o.isPlural&&l.isPlural){const e=o.base.localeCompare(l.base,void 0,{sensitivity:"base"});if(0!==e)return e;if(o.isOrdinal!==l.isOrdinal)return o.isOrdinal?1:-1;const t=o.isOrdinal?a:n,s=t.indexOf(o.form),r=t.indexOf(l.form);return-1!==s&&-1!==r?s-r:o.form.localeCompare(l.form)}const i=e.localeCompare(t,void 0,{sensitivity:"base"});return 0===i?e.localeCompare(t,void 0,{sensitivity:"case"}):i});for(const r of l)s[r]=o(e[r],t);return s}function l(e,t,r,a,l,i=[],c=new Set,u=!1){const{keySeparator:f=".",sort:d=!0,removeUnusedKeys:p=!0,primaryLanguage:g,defaultValue:y="",pluralSeparator:h="_",contextSeparator:m="_"}=r.extract,x=new Set;try{const e=new Intl.PluralRules(a,{type:"cardinal"}),t=new Intl.PluralRules(a,{type:"ordinal"});e.resolvedOptions().pluralCategories.forEach(e=>x.add(e)),t.resolvedOptions().pluralCategories.forEach(e=>x.add(`ordinal_${e}`))}catch(e){const t=new Intl.PluralRules(g||"en",{type:"cardinal"}),s=new Intl.PluralRules(g||"en",{type:"ordinal"});t.resolvedOptions().pluralCategories.forEach(e=>x.add(e)),s.resolvedOptions().pluralCategories.forEach(e=>x.add(`ordinal_${e}`))}const O=e.filter(({key:e,hasCount:t,isOrdinal:s})=>{if(i.some(t=>t.test(e)))return!1;if(!t)return!0;const r=e.split(h);if(s&&r.includes("ordinal")){const e=r[r.length-1];return x.has(`ordinal_${e}`)}if(t){const e=r[r.length-1];return x.has(e)}return!0});let v=p?{}:JSON.parse(JSON.stringify(t));const w=s.getNestedKeys(t,f??".");for(const e of w)if(i.some(t=>t.test(e))){const r=s.getNestedValue(t,e,f??".");s.setNestedValue(v,e,r,f??".")}if(p){const e=s.getNestedKeys(t,f??".");for(const r of e){const e=r.split(h);if("zero"===e[e.length-1]){const n=e.slice(0,-1).join(h);if(O.some(({key:e})=>e.split(h).slice(0,-1).join(h)===n)){const e=s.getNestedValue(t,r,f??".");s.setNestedValue(v,r,e,f??".")}}}}for(const{key:e,defaultValue:o,explicitDefault:i}of O){const d=s.getNestedValue(t,e,f??"."),p=!O.some(t=>t.key.startsWith(`${e}${f}`)&&t.key!==e),x="object"==typeof d&&null!==d&&(c.has(e)||!o||o===e),w="object"==typeof d&&null!==d&&p&&!c.has(e)&&!x;if(x){s.setNestedValue(v,e,d,f??".");continue}let N;if(void 0===d||w)if(a===g)if(u){const t=o&&(o===e||e!==o&&(e.startsWith(o+h)||e.startsWith(o+m)));N=o&&!t?o:n.resolveDefaultValue(y,e,l||r?.extract?.defaultNS||"translation",a,o)}else N=o||e;else N=n.resolveDefaultValue(y,e,l||r?.extract?.defaultNS||"translation",a,o);else if(a===g&&u){const t=o&&(o===e||e!==o&&(e.startsWith(o+h)||e.startsWith(o+m)));N=(e.includes(h)||e.includes(m))&&!i?d:o&&!t?o:d}else N=d;s.setNestedValue(v,e,N,f??".")}if(!0===d)return o(v,r);if("function"==typeof d){const e={},t=Object.keys(v),s=new Map;for(const e of O){const t=!1===f?e.key:e.key.split(f)[0];s.has(t)||s.set(t,e)}t.sort((e,t)=>{if("function"==typeof d){const r=s.get(e),n=s.get(t);if(r&&n)return d(r,n)}return e.localeCompare(t,void 0,{sensitivity:"base"})});for(const s of t)e[s]=o(v[s],r);v=e}return v}exports.getTranslations=async function(s,n,o,{syncPrimaryWithDefaults:i=!1}={}){o.extract.primaryLanguage||=o.locales[0]||"en",o.extract.secondaryLanguages||=o.locales.filter(e=>e!==o?.extract?.primaryLanguage);const c=[...o.extract.preservePatterns||[]],u=o.extract.indentation??2;for(const e of n)c.push(`${e}.*`);const f=c.map(a),d="__no_namespace__",p=new Map;for(const e of s.values()){const t=e.nsIsImplicit&&!1===o.extract.defaultNS?d:String(e.ns??o.extract.defaultNS??"translation");p.has(t)||p.set(t,[]),p.get(t).push(e)}const g=[],y=Array.isArray(o.extract.ignore)?o.extract.ignore:o.extract.ignore?[o.extract.ignore]:[];for(const s of o.locales){if(o.extract.mergeNamespaces||!o.extract.output.includes("{{namespace}}")){const t={},a=r.getOutputPath(o.extract.output,s),c=e.resolve(process.cwd(),a),y=await r.loadTranslationFile(c)||{},h=new Set([...p.keys(),...Object.keys(y)]);for(const e of h){const r=p.get(e)||[];if(e===d){const e=l(r,y,o,s,void 0,f,n,i);Object.assign(t,e)}else{const a=y[e]||{};t[e]=l(r,a,o,s,e,f,n,i)}}const m=JSON.stringify(y,null,u),x=JSON.stringify(t,null,u);g.push({path:c,updated:x!==m,newTranslations:t,existingTranslations:y})}else{const a=new Set(p.keys()),c=r.getOutputPath(o.extract.output,s,"*"),d=await t.glob(c,{ignore:y});for(const t of d)a.add(e.basename(t,e.extname(t)));for(const t of a){const a=p.get(t)||[],c=r.getOutputPath(o.extract.output,s,t),d=e.resolve(process.cwd(),c),y=await r.loadTranslationFile(d)||{},h=l(a,y,o,s,t,f,n,i),m=JSON.stringify(y,null,u),x=JSON.stringify(h,null,u);g.push({path:d,updated:x!==m,newTranslations:h,existingTranslations:y})}}}return g};
@@ -1 +1 @@
1
- "use strict";exports.createPluginContext=function(e,t,a,u){return{addKey:t=>{const a=`${t.ns??"translation"}:${t.key}`,u=t.defaultValue??t.key,l=e.get(a);if(l){const n=l.defaultValue===l.key||l.hasCount&&l.defaultValue&&l.key.includes("_")&&l.key.startsWith(l.defaultValue),s=u===t.key;n&&!s&&e.set(a,{...t,defaultValue:u})}else e.set(a,{...t,defaultValue:u})},config:Object.freeze({...a,plugins:[...t]}),logger:u,getVarFromScope:()=>{}}},exports.initializePlugins=async function(e){for(const t of e)await(t.setup?.())};
1
+ "use strict";exports.createPluginContext=function(t,e,a,n){return{addKey:e=>{const n=!1===e.ns?void 0:e.ns,s=n??a.extract?.defaultNS??"translation",l=void 0===n,i=`${String(s)}:${e.key}`,u=e.defaultValue??e.key,o=t.get(i);if(o){const n=o.defaultValue===o.key||o.hasCount&&o.defaultValue&&o.key.includes("_")&&o.key.startsWith(o.defaultValue),r=u===e.key;n&&!r&&t.set(i,{...e,ns:s||a.extract?.defaultNS||"translation",nsIsImplicit:l,defaultValue:u})}else t.set(i,{...e,ns:s||a.extract?.defaultNS||"translation",nsIsImplicit:l,defaultValue:u})},config:Object.freeze({...a,plugins:[...e]}),logger:n,getVarFromScope:()=>{}}},exports.initializePlugins=async function(t){for(const e of t)await(e.setup?.())};
@@ -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)}};
@@ -1 +1 @@
1
- "use strict";var e=require("chalk"),o=require("ora"),a=require("node:path"),t=require("./extractor/core/key-finder.js"),s=require("./utils/nested-object.js"),n=require("./utils/file-utils.js"),l=require("./utils/funnel-msg-tracker.js");function r(o,a,t){const s=t>0?Math.round(a/t*100):100,n=c(s);console.log(`${e.bold(o)}: ${n} ${s}% (${a}/${t})`)}function c(o){const a=Math.floor(o/100*20),t=20-a;return`[${e.green("".padStart(a,"■"))}${"".padStart(t,"□")}]`}async function i(){if(await l.shouldShowFunnel("status"))return console.log(e.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${e.cyan("npx i18next-cli locize-migrate")} to get started.`),l.recordFunnelShown("status")}exports.runStatus=async function(l,u={}){l.extract.primaryLanguage||=l.locales[0]||"en",l.extract.secondaryLanguages||=l.locales.filter(e=>e!==l?.extract?.primaryLanguage);const y=o("Analyzing project localization status...\n").start();try{const o=await async function(e){e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(o=>o!==e?.extract?.primaryLanguage);const{allKeys:o}=await t.findKeys(e),{secondaryLanguages:l,keySeparator:r=".",defaultNS:c="translation",mergeNamespaces:i=!1,pluralSeparator:u="_"}=e.extract,y=new Map;for(const e of o.values()){const o=e.ns||c;y.has(o)||y.set(o,[]),y.get(o).push(e)}const d={totalBaseKeys:o.size,keysByNs:y,locales:new Map};for(const o of l){let t=0,l=0;const c=new Map,g=i?await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,o)))||{}:null;for(const[d,f]of y.entries()){const y=i?g?.[d]||{}:await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,o,d)))||{};let p=0,$=0;const m=[];for(const{key:e,hasCount:a,isOrdinal:t}of f)if(a){const a=t?"ordinal":"cardinal",n=new Intl.PluralRules(o,{type:a}).resolvedOptions().pluralCategories;for(const o of n){$++;const a=t?`${e}${u}ordinal${u}${o}`:`${e}${u}${o}`,n=!!s.getNestedValue(y,a,r??".");n&&p++,m.push({key:a,isTranslated:n})}}else{$++;const o=!!s.getNestedValue(y,e,r??".");o&&p++,m.push({key:e,isTranslated:o})}c.set(d,{totalKeys:$,translatedKeys:p,keyDetails:m}),t+=p,l+=$}d.locales.set(o,{totalKeys:l,totalTranslated:t,namespaces:c})}return d}(l);y.succeed("Analysis complete."),await async function(o,a,t){t.detail?await async function(o,a,t,s){if(t===a.extract.primaryLanguage)return void console.log(e.yellow(`Locale "${t}" is the primary language. All keys are considered present.`));if(!a.locales.includes(t))return void console.error(e.red(`Error: Locale "${t}" is not defined in your configuration.`));const n=o.locales.get(t);if(!n)return void console.error(e.red(`Error: Locale "${t}" is not a valid secondary language.`));console.log(e.bold(`\nKey Status for "${e.cyan(t)}":`));const l=Array.from(o.keysByNs.values()).flat().length;r("Overall",n.totalTranslated,n.totalKeys);const c=s?[s]:Array.from(n.namespaces.keys()).sort();for(const o of c){const a=n.namespaces.get(o);a&&(console.log(e.cyan.bold(`\nNamespace: ${o}`)),r("Namespace Progress",a.translatedKeys,a.totalKeys),a.keyDetails.forEach(({key:o,isTranslated:a})=>{const t=a?e.green("✓"):e.red("✗");console.log(` ${t} ${o}`)}))}const u=l-n.totalTranslated;u>0?console.log(e.yellow.bold(`\nSummary: Found ${u} missing translations for "${t}".`)):console.log(e.green.bold(`\nSummary: 🎉 All keys are translated for "${t}".`));await i()}(o,a,t.detail,t.namespace):t.namespace?await async function(o,a,t){const s=o.keysByNs.get(t);if(!s)return void console.error(e.red(`Error: Namespace "${t}" was not found in your source code.`));console.log(e.cyan.bold(`\nStatus for Namespace: "${t}"`)),console.log("------------------------");for(const[e,a]of o.locales.entries()){const o=a.namespaces.get(t);if(o){const a=o.totalKeys>0?Math.round(o.translatedKeys/o.totalKeys*100):100,t=c(a);console.log(`- ${e}: ${t} ${a}% (${o.translatedKeys}/${o.totalKeys} keys)`)}}await i()}(o,0,t.namespace):await async function(o,a){const{primaryLanguage:t}=a.extract;console.log(e.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${e.bold(o.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${e.bold(o.keysByNs.size)}`),console.log(`🌍 Locales: ${e.bold(a.locales.join(", "))}`),console.log(`✅ Primary Language: ${e.bold(t)}`),console.log("\nTranslation Progress:");for(const[e,a]of o.locales.entries()){const o=a.totalKeys>0?Math.round(a.totalTranslated/a.totalKeys*100):100,t=c(o);console.log(`- ${e}: ${t} ${o}% (${a.totalTranslated}/${a.totalKeys} keys)`)}await i()}(o,a)}(o,l,u)}catch(e){y.fail("Failed to generate status report."),console.error(e)}};
1
+ "use strict";var e=require("chalk"),o=require("ora"),a=require("node:path"),t=require("./extractor/core/key-finder.js"),s=require("./utils/nested-object.js"),n=require("./utils/file-utils.js"),l=require("./utils/funnel-msg-tracker.js");function r(o,a,t){const s=t>0?Math.round(a/t*100):100,n=c(s);console.log(`${e.bold(o)}: ${n} ${s}% (${a}/${t})`)}function c(o){const a=Math.floor(o/100*20),t=20-a;return`[${e.green("".padStart(a,"■"))}${"".padStart(t,"□")}]`}async function i(){if(await l.shouldShowFunnel("status"))return console.log(e.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${e.cyan("npx i18next-cli locize-migrate")} to get started.`),l.recordFunnelShown("status")}exports.runStatus=async function(l,u={}){l.extract.primaryLanguage||=l.locales[0]||"en",l.extract.secondaryLanguages||=l.locales.filter(e=>e!==l?.extract?.primaryLanguage);const y=o("Analyzing project localization status...\n").start();try{const o=await async function(e){e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(o=>o!==e?.extract?.primaryLanguage);const{allKeys:o}=await t.findKeys(e),{secondaryLanguages:l,keySeparator:r=".",defaultNS:c="translation",mergeNamespaces:i=!1,pluralSeparator:u="_"}=e.extract,y=new Map;for(const e of o.values()){const o=e.ns||c||"translation";y.has(o)||y.set(o,[]),y.get(o).push(e)}const d={totalBaseKeys:o.size,keysByNs:y,locales:new Map};for(const o of l){let t=0,l=0;const c=new Map,g=i?await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,o)))||{}:null;for(const[d,f]of y.entries()){const y=i?g?.[d]||{}:await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,o,d)))||{};let p=0,$=0;const m=[];for(const{key:e,hasCount:a,isOrdinal:t}of f)if(a){const a=t?"ordinal":"cardinal",n=new Intl.PluralRules(o,{type:a}).resolvedOptions().pluralCategories;for(const o of n){$++;const a=t?`${e}${u}ordinal${u}${o}`:`${e}${u}${o}`,n=!!s.getNestedValue(y,a,r??".");n&&p++,m.push({key:a,isTranslated:n})}}else{$++;const o=!!s.getNestedValue(y,e,r??".");o&&p++,m.push({key:e,isTranslated:o})}c.set(d,{totalKeys:$,translatedKeys:p,keyDetails:m}),t+=p,l+=$}d.locales.set(o,{totalKeys:l,totalTranslated:t,namespaces:c})}return d}(l);y.succeed("Analysis complete."),await async function(o,a,t){t.detail?await async function(o,a,t,s){if(t===a.extract.primaryLanguage)return void console.log(e.yellow(`Locale "${t}" is the primary language. All keys are considered present.`));if(!a.locales.includes(t))return void console.error(e.red(`Error: Locale "${t}" is not defined in your configuration.`));const n=o.locales.get(t);if(!n)return void console.error(e.red(`Error: Locale "${t}" is not a valid secondary language.`));console.log(e.bold(`\nKey Status for "${e.cyan(t)}":`));const l=Array.from(o.keysByNs.values()).flat().length;r("Overall",n.totalTranslated,n.totalKeys);const c=s?[s]:Array.from(n.namespaces.keys()).sort();for(const o of c){const a=n.namespaces.get(o);a&&(console.log(e.cyan.bold(`\nNamespace: ${o}`)),r("Namespace Progress",a.translatedKeys,a.totalKeys),a.keyDetails.forEach(({key:o,isTranslated:a})=>{const t=a?e.green("✓"):e.red("✗");console.log(` ${t} ${o}`)}))}const u=l-n.totalTranslated;u>0?console.log(e.yellow.bold(`\nSummary: Found ${u} missing translations for "${t}".`)):console.log(e.green.bold(`\nSummary: 🎉 All keys are translated for "${t}".`));await i()}(o,a,t.detail,t.namespace):t.namespace?await async function(o,a,t){const s=o.keysByNs.get(t);if(!s)return void console.error(e.red(`Error: Namespace "${t}" was not found in your source code.`));console.log(e.cyan.bold(`\nStatus for Namespace: "${t}"`)),console.log("------------------------");for(const[e,a]of o.locales.entries()){const o=a.namespaces.get(t);if(o){const a=o.totalKeys>0?Math.round(o.translatedKeys/o.totalKeys*100):100,t=c(a);console.log(`- ${e}: ${t} ${a}% (${o.translatedKeys}/${o.totalKeys} keys)`)}}await i()}(o,0,t.namespace):await async function(o,a){const{primaryLanguage:t}=a.extract;console.log(e.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${e.bold(o.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${e.bold(o.keysByNs.size)}`),console.log(`🌍 Locales: ${e.bold(a.locales.join(", "))}`),console.log(`✅ Primary Language: ${e.bold(t)}`),console.log("\nTranslation Progress:");for(const[e,a]of o.locales.entries()){const o=a.totalKeys>0?Math.round(a.totalTranslated/a.totalKeys*100):100,t=c(o);console.log(`- ${e}: ${t} ${o}% (${a.totalTranslated}/${a.totalKeys} keys)`)}await i()}(o,a)}(o,l,u)}catch(e){y.fail("Failed to generate status report."),console.error(e)}};
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.12.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()))};
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{resolve as t,basename as e,extname as r}from"node:path";import{glob as s}from"glob";import{getNestedKeys as n,getNestedValue as o,setNestedValue as a}from"../../utils/nested-object.js";import{getOutputPath as i,loadTranslationFile as l}from"../../utils/file-utils.js";import{resolveDefaultValue as c}from"../../utils/default-value.js";function f(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function u(t,e){if("object"!=typeof t||null===t||Array.isArray(t))return t;const r={},s=e?.extract?.pluralSeparator??"_",n=["zero","one","two","few","many","other"],o=n.map(t=>`ordinal${s}${t}`),a=Object.keys(t).sort((t,e)=>{const r=t=>{for(const e of o)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!0,isPlural:!0,fullKey:t}}for(const e of n)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!1,isPlural:!0,fullKey:t}}return{base:t,form:"",isOrdinal:!1,isPlural:!1,fullKey:t}},a=r(t),i=r(e);if(a.isPlural&&i.isPlural){const t=a.base.localeCompare(i.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(a.isOrdinal!==i.isOrdinal)return a.isOrdinal?1:-1;const e=a.isOrdinal?o:n,r=e.indexOf(a.form),s=e.indexOf(i.form);return-1!==r&&-1!==s?r-s:a.form.localeCompare(i.form)}const l=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===l?t.localeCompare(e,void 0,{sensitivity:"case"}):l});for(const s of a)r[s]=u(t[s],e);return r}function p(t,e,r,s,i,l,f,p=!1){const{keySeparator:d=".",sort:y=!0,removeUnusedKeys:g=!0,primaryLanguage:m,defaultValue:h="",pluralSeparator:x="_",contextSeparator:O="_"}=r.extract,w=new Set;try{const t=new Intl.PluralRules(s,{type:"cardinal"}),e=new Intl.PluralRules(s,{type:"ordinal"});t.resolvedOptions().pluralCategories.forEach(t=>w.add(t)),e.resolvedOptions().pluralCategories.forEach(t=>w.add(`ordinal_${t}`))}catch(t){const e=new Intl.PluralRules(m||"en",{type:"cardinal"}),r=new Intl.PluralRules(m||"en",{type:"ordinal"});e.resolvedOptions().pluralCategories.forEach(t=>w.add(t)),r.resolvedOptions().pluralCategories.forEach(t=>w.add(`ordinal_${t}`))}const v=t.filter(({key:t,hasCount:e,isOrdinal:r})=>{if(l.some(e=>e.test(t)))return!1;if(!e)return!0;const s=t.split(x);if(r&&s.includes("ordinal")){const t=s[s.length-1];return w.has(`ordinal_${t}`)}if(e){const t=s[s.length-1];return w.has(t)}return!0});let b=g?{}:JSON.parse(JSON.stringify(e));const $=n(e,d??".");for(const t of $)if(l.some(e=>e.test(t))){const r=o(e,t,d??".");a(b,t,r,d??".")}if(g){const t=n(e,d??".");for(const r of t){const t=r.split(x);if("zero"===t[t.length-1]){const s=t.slice(0,-1).join(x);if(v.some(({key:t})=>t.split(x).slice(0,-1).join(x)===s)){const t=o(e,r,d??".");a(b,r,t,d??".")}}}}for(const{key:t,defaultValue:r,explicitDefault:n}of v){const l=o(e,t,d??"."),u=!v.some(e=>e.key.startsWith(`${t}${d}`)&&e.key!==t),y="object"==typeof l&&null!==l&&(f.has(t)||!r||r===t),g="object"==typeof l&&null!==l&&u&&!f.has(t)&&!y;if(y){a(b,t,l,d??".");continue}let w;if(void 0===l||g)if(s===m)if(p){const e=r&&(r===t||t!==r&&(t.startsWith(r+x)||t.startsWith(r+O)));w=r&&!e?r:c(h,t,i,s,r)}else w=r||t;else w=c(h,t,i,s,r);else if(s===m&&p){const e=r&&(r===t||t!==r&&(t.startsWith(r+x)||t.startsWith(r+O)));w=(t.includes(x)||t.includes(O))&&!n?l:r&&!e?r:l}else w=l;a(b,t,w,d??".")}if(!0===y)return u(b,r);if("function"==typeof y){const t={},e=Object.keys(b),s=new Map;for(const t of v){const e=!1===d?t.key:t.key.split(d)[0];s.has(e)||s.set(e,t)}e.sort((t,e)=>{if("function"==typeof y){const r=s.get(t),n=s.get(e);if(r&&n)return y(r,n)}return t.localeCompare(e,void 0,{sensitivity:"base"})});for(const s of e)t[s]=u(b[s],r);b=t}return b}async function d(n,o,a,{syncPrimaryWithDefaults:c=!1}={}){a.extract.primaryLanguage||=a.locales[0]||"en",a.extract.secondaryLanguages||=a.locales.filter(t=>t!==a?.extract?.primaryLanguage);const u=a.extract.defaultNS??"translation",d=[...a.extract.preservePatterns||[]],y=a.extract.indentation??2;for(const t of o)d.push(`${t}.*`);const g=d.map(f),m=new Map;for(const t of n.values()){const e=t.ns||u;m.has(e)||m.set(e,[]),m.get(e).push(t)}const h=[],x=Array.isArray(a.extract.ignore)?a.extract.ignore:a.extract.ignore?[a.extract.ignore]:[];for(const n of a.locales){if(a.extract.mergeNamespaces||!a.extract.output.includes("{{namespace}}")){const e={},r=i(a.extract.output,n),s=t(process.cwd(),r),f=await l(s)||{},u=new Set([...m.keys(),...Object.keys(f)]);for(const t of u){const r=m.get(t)||[],s=f[t]||{};e[t]=p(r,s,a,n,t,g,o,c)}const d=JSON.stringify(f,null,y),x=JSON.stringify(e,null,y);h.push({path:s,updated:x!==d,newTranslations:e,existingTranslations:f})}else{const f=new Set(m.keys()),u=i(a.extract.output,n,"*"),d=await s(u,{ignore:x});for(const t of d)f.add(e(t,r(t)));for(const e of f){const r=m.get(e)||[],s=i(a.extract.output,n,e),f=t(process.cwd(),s),u=await l(f)||{},d=p(r,u,a,n,e,g,o,c),x=JSON.stringify(u,null,y),O=JSON.stringify(d,null,y);h.push({path:f,updated:O!==x,newTranslations:d,existingTranslations:u})}}}return h}export{d as getTranslations};
1
+ import{resolve as t,basename as e,extname as r}from"node:path";import{glob as s}from"glob";import{getNestedKeys as n,getNestedValue as o,setNestedValue as a}from"../../utils/nested-object.js";import{getOutputPath as i,loadTranslationFile as l}from"../../utils/file-utils.js";import{resolveDefaultValue as c}from"../../utils/default-value.js";function f(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function u(t,e){if("object"!=typeof t||null===t||Array.isArray(t))return t;const r={},s=e?.extract?.pluralSeparator??"_",n=["zero","one","two","few","many","other"],o=n.map(t=>`ordinal${s}${t}`),a=Object.keys(t).sort((t,e)=>{const r=t=>{for(const e of o)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!0,isPlural:!0,fullKey:t}}for(const e of n)if(t.endsWith(`${s}${e}`)){return{base:t.slice(0,-(s.length+e.length)),form:e,isOrdinal:!1,isPlural:!0,fullKey:t}}return{base:t,form:"",isOrdinal:!1,isPlural:!1,fullKey:t}},a=r(t),i=r(e);if(a.isPlural&&i.isPlural){const t=a.base.localeCompare(i.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(a.isOrdinal!==i.isOrdinal)return a.isOrdinal?1:-1;const e=a.isOrdinal?o:n,r=e.indexOf(a.form),s=e.indexOf(i.form);return-1!==r&&-1!==s?r-s:a.form.localeCompare(i.form)}const l=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===l?t.localeCompare(e,void 0,{sensitivity:"case"}):l});for(const s of a)r[s]=u(t[s],e);return r}function p(t,e,r,s,i,l=[],f=new Set,p=!1){const{keySeparator:d=".",sort:y=!0,removeUnusedKeys:g=!0,primaryLanguage:m,defaultValue:h="",pluralSeparator:x="_",contextSeparator:O="_"}=r.extract,w=new Set;try{const t=new Intl.PluralRules(s,{type:"cardinal"}),e=new Intl.PluralRules(s,{type:"ordinal"});t.resolvedOptions().pluralCategories.forEach(t=>w.add(t)),e.resolvedOptions().pluralCategories.forEach(t=>w.add(`ordinal_${t}`))}catch(t){const e=new Intl.PluralRules(m||"en",{type:"cardinal"}),r=new Intl.PluralRules(m||"en",{type:"ordinal"});e.resolvedOptions().pluralCategories.forEach(t=>w.add(t)),r.resolvedOptions().pluralCategories.forEach(t=>w.add(`ordinal_${t}`))}const S=t.filter(({key:t,hasCount:e,isOrdinal:r})=>{if(l.some(e=>e.test(t)))return!1;if(!e)return!0;const s=t.split(x);if(r&&s.includes("ordinal")){const t=s[s.length-1];return w.has(`ordinal_${t}`)}if(e){const t=s[s.length-1];return w.has(t)}return!0});let v=g?{}:JSON.parse(JSON.stringify(e));const b=n(e,d??".");for(const t of b)if(l.some(e=>e.test(t))){const r=o(e,t,d??".");a(v,t,r,d??".")}if(g){const t=n(e,d??".");for(const r of t){const t=r.split(x);if("zero"===t[t.length-1]){const s=t.slice(0,-1).join(x);if(S.some(({key:t})=>t.split(x).slice(0,-1).join(x)===s)){const t=o(e,r,d??".");a(v,r,t,d??".")}}}}for(const{key:t,defaultValue:n,explicitDefault:l}of S){const u=o(e,t,d??"."),y=!S.some(e=>e.key.startsWith(`${t}${d}`)&&e.key!==t),g="object"==typeof u&&null!==u&&(f.has(t)||!n||n===t),w="object"==typeof u&&null!==u&&y&&!f.has(t)&&!g;if(g){a(v,t,u,d??".");continue}let b;if(void 0===u||w)if(s===m)if(p){const e=n&&(n===t||t!==n&&(t.startsWith(n+x)||t.startsWith(n+O)));b=n&&!e?n:c(h,t,i||r?.extract?.defaultNS||"translation",s,n)}else b=n||t;else b=c(h,t,i||r?.extract?.defaultNS||"translation",s,n);else if(s===m&&p){const e=n&&(n===t||t!==n&&(t.startsWith(n+x)||t.startsWith(n+O)));b=(t.includes(x)||t.includes(O))&&!l?u:n&&!e?n:u}else b=u;a(v,t,b,d??".")}if(!0===y)return u(v,r);if("function"==typeof y){const t={},e=Object.keys(v),s=new Map;for(const t of S){const e=!1===d?t.key:t.key.split(d)[0];s.has(e)||s.set(e,t)}e.sort((t,e)=>{if("function"==typeof y){const r=s.get(t),n=s.get(e);if(r&&n)return y(r,n)}return t.localeCompare(e,void 0,{sensitivity:"base"})});for(const s of e)t[s]=u(v[s],r);v=t}return v}async function d(n,o,a,{syncPrimaryWithDefaults:c=!1}={}){a.extract.primaryLanguage||=a.locales[0]||"en",a.extract.secondaryLanguages||=a.locales.filter(t=>t!==a?.extract?.primaryLanguage);const u=[...a.extract.preservePatterns||[]],d=a.extract.indentation??2;for(const t of o)u.push(`${t}.*`);const y=u.map(f),g="__no_namespace__",m=new Map;for(const t of n.values()){const e=t.nsIsImplicit&&!1===a.extract.defaultNS?g:String(t.ns??a.extract.defaultNS??"translation");m.has(e)||m.set(e,[]),m.get(e).push(t)}const h=[],x=Array.isArray(a.extract.ignore)?a.extract.ignore:a.extract.ignore?[a.extract.ignore]:[];for(const n of a.locales){if(a.extract.mergeNamespaces||!a.extract.output.includes("{{namespace}}")){const e={},r=i(a.extract.output,n),s=t(process.cwd(),r),f=await l(s)||{},u=new Set([...m.keys(),...Object.keys(f)]);for(const t of u){const r=m.get(t)||[];if(t===g){const t=p(r,f,a,n,void 0,y,o,c);Object.assign(e,t)}else{const s=f[t]||{};e[t]=p(r,s,a,n,t,y,o,c)}}const x=JSON.stringify(f,null,d),O=JSON.stringify(e,null,d);h.push({path:s,updated:O!==x,newTranslations:e,existingTranslations:f})}else{const f=new Set(m.keys()),u=i(a.extract.output,n,"*"),g=await s(u,{ignore:x});for(const t of g)f.add(e(t,r(t)));for(const e of f){const r=m.get(e)||[],s=i(a.extract.output,n,e),f=t(process.cwd(),s),u=await l(f)||{},g=p(r,u,a,n,e,y,o,c),x=JSON.stringify(u,null,d),O=JSON.stringify(g,null,d);h.push({path:f,updated:O!==x,newTranslations:g,existingTranslations:u})}}}return h}export{d as getTranslations};
@@ -1 +1 @@
1
- async function e(e){for(const t of e)await(t.setup?.())}function t(e,t,a,u){return{addKey:t=>{const a=`${t.ns??"translation"}:${t.key}`,u=t.defaultValue??t.key,l=e.get(a);if(l){const n=l.defaultValue===l.key||l.hasCount&&l.defaultValue&&l.key.includes("_")&&l.key.startsWith(l.defaultValue),s=u===t.key;n&&!s&&e.set(a,{...t,defaultValue:u})}else e.set(a,{...t,defaultValue:u})},config:Object.freeze({...a,plugins:[...t]}),logger:u,getVarFromScope:()=>{}}}export{t as createPluginContext,e as initializePlugins};
1
+ async function t(t){for(const e of t)await(e.setup?.())}function e(t,e,a,n){return{addKey:e=>{const n=!1===e.ns?void 0:e.ns,l=n??a.extract?.defaultNS??"translation",s=void 0===n,u=`${String(l)}:${e.key}`,i=e.defaultValue??e.key,o=t.get(u);if(o){const n=o.defaultValue===o.key||o.hasCount&&o.defaultValue&&o.key.includes("_")&&o.key.startsWith(o.defaultValue),f=i===e.key;n&&!f&&t.set(u,{...e,ns:l||a.extract?.defaultNS||"translation",nsIsImplicit:s,defaultValue:i})}else t.set(u,{...e,ns:l||a.extract?.defaultNS||"translation",nsIsImplicit:s,defaultValue:i})},config:Object.freeze({...a,plugins:[...e]}),logger:n,getVarFromScope:()=>{}}}export{e as createPluginContext,t as initializePlugins};
@@ -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};
@@ -1 +1 @@
1
- import o from"chalk";import e from"ora";import{resolve as a}from"node:path";import{findKeys as t}from"./extractor/core/key-finder.js";import{getNestedValue as s}from"./utils/nested-object.js";import{loadTranslationFile as n,getOutputPath as l}from"./utils/file-utils.js";import{shouldShowFunnel as r,recordFunnelShown as c}from"./utils/funnel-msg-tracker.js";async function i(r,c={}){r.extract.primaryLanguage||=r.locales[0]||"en",r.extract.secondaryLanguages||=r.locales.filter(o=>o!==r?.extract?.primaryLanguage);const i=e("Analyzing project localization status...\n").start();try{const e=await async function(o){o.extract.primaryLanguage||=o.locales[0]||"en",o.extract.secondaryLanguages||=o.locales.filter(e=>e!==o?.extract?.primaryLanguage);const{allKeys:e}=await t(o),{secondaryLanguages:r,keySeparator:c=".",defaultNS:i="translation",mergeNamespaces:y=!1,pluralSeparator:u="_"}=o.extract,d=new Map;for(const o of e.values()){const e=o.ns||i;d.has(e)||d.set(e,[]),d.get(e).push(o)}const g={totalBaseKeys:e.size,keysByNs:d,locales:new Map};for(const e of r){let t=0,r=0;const i=new Map,f=y?await n(a(process.cwd(),l(o.extract.output,e)))||{}:null;for(const[g,p]of d.entries()){const d=y?f?.[g]||{}:await n(a(process.cwd(),l(o.extract.output,e,g)))||{};let m=0,$=0;const w=[];for(const{key:o,hasCount:a,isOrdinal:t}of p)if(a){const a=t?"ordinal":"cardinal",n=new Intl.PluralRules(e,{type:a}).resolvedOptions().pluralCategories;for(const e of n){$++;const a=t?`${o}${u}ordinal${u}${e}`:`${o}${u}${e}`,n=!!s(d,a,c??".");n&&m++,w.push({key:a,isTranslated:n})}}else{$++;const e=!!s(d,o,c??".");e&&m++,w.push({key:o,isTranslated:e})}i.set(g,{totalKeys:$,translatedKeys:m,keyDetails:w}),t+=m,r+=$}g.locales.set(e,{totalKeys:r,totalTranslated:t,namespaces:i})}return g}(r);i.succeed("Analysis complete."),await async function(e,a,t){t.detail?await async function(e,a,t,s){if(t===a.extract.primaryLanguage)return void console.log(o.yellow(`Locale "${t}" is the primary language. All keys are considered present.`));if(!a.locales.includes(t))return void console.error(o.red(`Error: Locale "${t}" is not defined in your configuration.`));const n=e.locales.get(t);if(!n)return void console.error(o.red(`Error: Locale "${t}" is not a valid secondary language.`));console.log(o.bold(`\nKey Status for "${o.cyan(t)}":`));const l=Array.from(e.keysByNs.values()).flat().length;y("Overall",n.totalTranslated,n.totalKeys);const r=s?[s]:Array.from(n.namespaces.keys()).sort();for(const e of r){const a=n.namespaces.get(e);a&&(console.log(o.cyan.bold(`\nNamespace: ${e}`)),y("Namespace Progress",a.translatedKeys,a.totalKeys),a.keyDetails.forEach(({key:e,isTranslated:a})=>{const t=a?o.green("✓"):o.red("✗");console.log(` ${t} ${e}`)}))}const c=l-n.totalTranslated;c>0?console.log(o.yellow.bold(`\nSummary: Found ${c} missing translations for "${t}".`)):console.log(o.green.bold(`\nSummary: 🎉 All keys are translated for "${t}".`));await d()}(e,a,t.detail,t.namespace):t.namespace?await async function(e,a,t){const s=e.keysByNs.get(t);if(!s)return void console.error(o.red(`Error: Namespace "${t}" was not found in your source code.`));console.log(o.cyan.bold(`\nStatus for Namespace: "${t}"`)),console.log("------------------------");for(const[o,a]of e.locales.entries()){const e=a.namespaces.get(t);if(e){const a=e.totalKeys>0?Math.round(e.translatedKeys/e.totalKeys*100):100,t=u(a);console.log(`- ${o}: ${t} ${a}% (${e.translatedKeys}/${e.totalKeys} keys)`)}}await d()}(e,0,t.namespace):await async function(e,a){const{primaryLanguage:t}=a.extract;console.log(o.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${o.bold(e.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${o.bold(e.keysByNs.size)}`),console.log(`🌍 Locales: ${o.bold(a.locales.join(", "))}`),console.log(`✅ Primary Language: ${o.bold(t)}`),console.log("\nTranslation Progress:");for(const[o,a]of e.locales.entries()){const e=a.totalKeys>0?Math.round(a.totalTranslated/a.totalKeys*100):100,t=u(e);console.log(`- ${o}: ${t} ${e}% (${a.totalTranslated}/${a.totalKeys} keys)`)}await d()}(e,a)}(e,r,c)}catch(o){i.fail("Failed to generate status report."),console.error(o)}}function y(e,a,t){const s=t>0?Math.round(a/t*100):100,n=u(s);console.log(`${o.bold(e)}: ${n} ${s}% (${a}/${t})`)}function u(e){const a=Math.floor(e/100*20),t=20-a;return`[${o.green("".padStart(a,"■"))}${"".padStart(t,"□")}]`}async function d(){if(await r("status"))return console.log(o.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${o.cyan("npx i18next-cli locize-migrate")} to get started.`),c("status")}export{i as runStatus};
1
+ import o from"chalk";import e from"ora";import{resolve as a}from"node:path";import{findKeys as t}from"./extractor/core/key-finder.js";import{getNestedValue as s}from"./utils/nested-object.js";import{loadTranslationFile as n,getOutputPath as l}from"./utils/file-utils.js";import{shouldShowFunnel as r,recordFunnelShown as c}from"./utils/funnel-msg-tracker.js";async function i(r,c={}){r.extract.primaryLanguage||=r.locales[0]||"en",r.extract.secondaryLanguages||=r.locales.filter(o=>o!==r?.extract?.primaryLanguage);const i=e("Analyzing project localization status...\n").start();try{const e=await async function(o){o.extract.primaryLanguage||=o.locales[0]||"en",o.extract.secondaryLanguages||=o.locales.filter(e=>e!==o?.extract?.primaryLanguage);const{allKeys:e}=await t(o),{secondaryLanguages:r,keySeparator:c=".",defaultNS:i="translation",mergeNamespaces:y=!1,pluralSeparator:u="_"}=o.extract,d=new Map;for(const o of e.values()){const e=o.ns||i||"translation";d.has(e)||d.set(e,[]),d.get(e).push(o)}const g={totalBaseKeys:e.size,keysByNs:d,locales:new Map};for(const e of r){let t=0,r=0;const i=new Map,f=y?await n(a(process.cwd(),l(o.extract.output,e)))||{}:null;for(const[g,p]of d.entries()){const d=y?f?.[g]||{}:await n(a(process.cwd(),l(o.extract.output,e,g)))||{};let m=0,$=0;const w=[];for(const{key:o,hasCount:a,isOrdinal:t}of p)if(a){const a=t?"ordinal":"cardinal",n=new Intl.PluralRules(e,{type:a}).resolvedOptions().pluralCategories;for(const e of n){$++;const a=t?`${o}${u}ordinal${u}${e}`:`${o}${u}${e}`,n=!!s(d,a,c??".");n&&m++,w.push({key:a,isTranslated:n})}}else{$++;const e=!!s(d,o,c??".");e&&m++,w.push({key:o,isTranslated:e})}i.set(g,{totalKeys:$,translatedKeys:m,keyDetails:w}),t+=m,r+=$}g.locales.set(e,{totalKeys:r,totalTranslated:t,namespaces:i})}return g}(r);i.succeed("Analysis complete."),await async function(e,a,t){t.detail?await async function(e,a,t,s){if(t===a.extract.primaryLanguage)return void console.log(o.yellow(`Locale "${t}" is the primary language. All keys are considered present.`));if(!a.locales.includes(t))return void console.error(o.red(`Error: Locale "${t}" is not defined in your configuration.`));const n=e.locales.get(t);if(!n)return void console.error(o.red(`Error: Locale "${t}" is not a valid secondary language.`));console.log(o.bold(`\nKey Status for "${o.cyan(t)}":`));const l=Array.from(e.keysByNs.values()).flat().length;y("Overall",n.totalTranslated,n.totalKeys);const r=s?[s]:Array.from(n.namespaces.keys()).sort();for(const e of r){const a=n.namespaces.get(e);a&&(console.log(o.cyan.bold(`\nNamespace: ${e}`)),y("Namespace Progress",a.translatedKeys,a.totalKeys),a.keyDetails.forEach(({key:e,isTranslated:a})=>{const t=a?o.green("✓"):o.red("✗");console.log(` ${t} ${e}`)}))}const c=l-n.totalTranslated;c>0?console.log(o.yellow.bold(`\nSummary: Found ${c} missing translations for "${t}".`)):console.log(o.green.bold(`\nSummary: 🎉 All keys are translated for "${t}".`));await d()}(e,a,t.detail,t.namespace):t.namespace?await async function(e,a,t){const s=e.keysByNs.get(t);if(!s)return void console.error(o.red(`Error: Namespace "${t}" was not found in your source code.`));console.log(o.cyan.bold(`\nStatus for Namespace: "${t}"`)),console.log("------------------------");for(const[o,a]of e.locales.entries()){const e=a.namespaces.get(t);if(e){const a=e.totalKeys>0?Math.round(e.translatedKeys/e.totalKeys*100):100,t=u(a);console.log(`- ${o}: ${t} ${a}% (${e.translatedKeys}/${e.totalKeys} keys)`)}}await d()}(e,0,t.namespace):await async function(e,a){const{primaryLanguage:t}=a.extract;console.log(o.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${o.bold(e.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${o.bold(e.keysByNs.size)}`),console.log(`🌍 Locales: ${o.bold(a.locales.join(", "))}`),console.log(`✅ Primary Language: ${o.bold(t)}`),console.log("\nTranslation Progress:");for(const[o,a]of e.locales.entries()){const e=a.totalKeys>0?Math.round(a.totalTranslated/a.totalKeys*100):100,t=u(e);console.log(`- ${o}: ${t} ${e}% (${a.totalTranslated}/${a.totalKeys} keys)`)}await d()}(e,a)}(e,r,c)}catch(o){i.fail("Failed to generate status report."),console.error(o)}}function y(e,a,t){const s=t>0?Math.round(a/t*100):100,n=u(s);console.log(`${o.bold(e)}: ${n} ${s}% (${a}/${t})`)}function u(e){const a=Math.floor(e/100*20),t=20-a;return`[${o.green("".padStart(a,"■"))}${"".padStart(t,"□")}]`}async function d(){if(await r("status"))return console.log(o.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${o.cyan("npx i18next-cli locize-migrate")} to get started.`),c("status")}export{i as runStatus};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.12.1",
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.12.1')
25
+ .version('1.13.1')
26
26
 
27
27
  program
28
28
  .command('extract')
@@ -106,9 +106,9 @@ function buildNewTranslationsForNs (
106
106
  existingTranslations: Record<string, any>,
107
107
  config: I18nextToolkitConfig,
108
108
  locale: string,
109
- namespace: string,
110
- preservePatterns: RegExp[],
111
- objectKeys: Set<string>,
109
+ namespace?: string, // optional: undefined indicates "no namespace / top-level file"
110
+ preservePatterns: RegExp[] = [],
111
+ objectKeys: Set<string> = new Set(),
112
112
  syncPrimaryWithDefaults: boolean = false
113
113
  ): Record<string, any> {
114
114
  const {
@@ -243,14 +243,14 @@ function buildNewTranslationsForNs (
243
243
  key.startsWith(defaultValue + contextSeparator)))
244
244
  )
245
245
 
246
- valueToSet = (defaultValue && !isDerivedDefault) ? defaultValue : resolveDefaultValue(emptyDefaultValue, key, namespace, locale, defaultValue)
246
+ valueToSet = (defaultValue && !isDerivedDefault) ? defaultValue : resolveDefaultValue(emptyDefaultValue, key, namespace || config?.extract?.defaultNS || 'translation', locale, defaultValue)
247
247
  } else {
248
248
  // syncPrimaryWithDefaults is false - use original behavior
249
249
  valueToSet = defaultValue || key
250
250
  }
251
251
  } else {
252
252
  // For secondary languages, always use empty string
253
- valueToSet = resolveDefaultValue(emptyDefaultValue, key, namespace, locale, defaultValue)
253
+ valueToSet = resolveDefaultValue(emptyDefaultValue, key, namespace || config?.extract?.defaultNS || 'translation', locale, defaultValue)
254
254
  }
255
255
  } else {
256
256
  // Existing value exists - decide whether to preserve or sync
@@ -366,7 +366,6 @@ export async function getTranslations (
366
366
  ): Promise<TranslationResult[]> {
367
367
  config.extract.primaryLanguage ||= config.locales[0] || 'en'
368
368
  config.extract.secondaryLanguages ||= config.locales.filter((l: string) => l !== config?.extract?.primaryLanguage)
369
- const defaultNS = config.extract.defaultNS ?? 'translation'
370
369
  const patternsToPreserve = [...(config.extract.preservePatterns || [])]
371
370
  const indentation = config.extract.indentation ?? 2
372
371
 
@@ -376,12 +375,18 @@ export async function getTranslations (
376
375
  }
377
376
  const preservePatterns = patternsToPreserve.map(globToRegex)
378
377
 
379
- // Group keys by namespace
378
+ // Group keys by namespace. If the plugin recorded the namespace as implicit
379
+ // (nsIsImplicit) AND the user set defaultNS === false we treat those keys
380
+ // as "no namespace" (will be merged at top-level). Otherwise use the stored
381
+ // namespace (internally we keep implicit keys as 'translation').
382
+ const NO_NS_TOKEN = '__no_namespace__'
380
383
  const keysByNS = new Map<string, ExtractedKey[]>()
381
- for (const key of keys.values()) {
382
- const ns = key.ns || defaultNS
383
- if (!keysByNS.has(ns)) keysByNS.set(ns, [])
384
- keysByNS.get(ns)!.push(key)
384
+ for (const k of keys.values()) {
385
+ const nsKey = (k.nsIsImplicit && config.extract.defaultNS === false)
386
+ ? NO_NS_TOKEN
387
+ : String(k.ns ?? (config.extract.defaultNS ?? 'translation'))
388
+ if (!keysByNS.has(nsKey)) keysByNS.set(nsKey, [])
389
+ keysByNS.get(nsKey)!.push(k)
385
390
  }
386
391
 
387
392
  const results: TranslationResult[] = []
@@ -401,12 +406,17 @@ export async function getTranslations (
401
406
  const existingMergedFile = await loadTranslationFile(fullPath) || {}
402
407
 
403
408
  // The namespaces to process are from new keys AND the keys of the existing merged file
404
- const namespacesToProcess = new Set([...keysByNS.keys(), ...Object.keys(existingMergedFile)])
405
-
406
- for (const ns of namespacesToProcess) {
407
- const nsKeys = keysByNS.get(ns) || []
408
- const existingTranslations = existingMergedFile[ns] || {}
409
- newMergedTranslations[ns] = buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, ns, preservePatterns, objectKeys, syncPrimaryWithDefaults)
409
+ const namespacesToProcess = new Set<string>([...keysByNS.keys(), ...Object.keys(existingMergedFile)])
410
+ for (const nsKey of namespacesToProcess) {
411
+ const nsKeys = keysByNS.get(nsKey) || []
412
+ if (nsKey === NO_NS_TOKEN) {
413
+ // keys without namespace -> merged into top-level of the merged file
414
+ const built = buildNewTranslationsForNs(nsKeys, existingMergedFile, config, locale, undefined, preservePatterns, objectKeys, syncPrimaryWithDefaults)
415
+ Object.assign(newMergedTranslations, built)
416
+ } else {
417
+ const existingTranslations = existingMergedFile[nsKey] || {}
418
+ newMergedTranslations[nsKey] = buildNewTranslationsForNs(nsKeys, existingTranslations, config, locale, nsKey, preservePatterns, objectKeys, syncPrimaryWithDefaults)
419
+ }
410
420
  }
411
421
 
412
422
  const oldContent = JSON.stringify(existingMergedFile, null, indentation)
@@ -123,7 +123,7 @@ export class CallExpressionHandler {
123
123
  // Loop through each key found (could be one or more) and process it
124
124
  for (let i = 0; i < keysToProcess.length; i++) {
125
125
  let key = keysToProcess[i]
126
- let ns: string | undefined
126
+ let ns: string | false | undefined
127
127
 
128
128
  // Determine namespace (explicit ns > ns:key > scope ns > default)
129
129
  // See https://www.i18next.com/overview/api#getfixedt
@@ -410,7 +410,7 @@ export class CallExpressionHandler {
410
410
  * @param options - object expression options
411
411
  * @param isOrdinal - isOrdinal flag
412
412
  */
413
- private handlePluralKeys (key: string, ns: string | undefined, options: ObjectExpression, isOrdinal: boolean, defaultValueFromCall?: string, explicitDefaultFromSource?: boolean): void {
413
+ private handlePluralKeys (key: string, ns: string | false | undefined, options: ObjectExpression, isOrdinal: boolean, defaultValueFromCall?: string, explicitDefaultFromSource?: boolean): void {
414
414
  try {
415
415
  const type = isOrdinal ? 'ordinal' : 'cardinal'
416
416
 
@@ -53,7 +53,7 @@ export function extractKeysFromComments (
53
53
  continue // Skip keys that match preserve patterns
54
54
  }
55
55
 
56
- let ns: string | undefined
56
+ let ns: string | false | undefined
57
57
  const remainder = text.slice(match.index + match[0].length)
58
58
 
59
59
  const defaultValue = parseDefaultValueFromComment(remainder)
@@ -158,7 +158,7 @@ export function extractKeysFromComments (
158
158
  function generatePluralKeys (
159
159
  key: string,
160
160
  defaultValue: string,
161
- ns: string | undefined,
161
+ ns: string | false | undefined,
162
162
  pluginContext: PluginContext,
163
163
  config: I18nextToolkitConfig,
164
164
  isOrdinal = false
@@ -211,7 +211,7 @@ function generatePluralKeys (
211
211
  function generateContextPluralKeys (
212
212
  key: string,
213
213
  defaultValue: string,
214
- ns: string | undefined,
214
+ ns: string | false | undefined,
215
215
  context: string,
216
216
  pluginContext: PluginContext,
217
217
  config: I18nextToolkitConfig,
@@ -271,7 +271,7 @@ export class JSXHandler {
271
271
  * @param isOrdinal - Whether to generate ordinal plural forms
272
272
  * @param optionsNode - Optional tOptions object expression for plural-specific defaults
273
273
  */
274
- private generatePluralKeysForTrans (key: string, defaultValue: string | undefined, ns: string | undefined, isOrdinal: boolean, optionsNode?: ObjectExpression, explicitDefaultFromSource?: boolean): void {
274
+ private generatePluralKeysForTrans (key: string, defaultValue: string | undefined, ns: string | false | undefined, isOrdinal: boolean, optionsNode?: ObjectExpression, explicitDefaultFromSource?: boolean): void {
275
275
  try {
276
276
  const type = isOrdinal ? 'ordinal' : 'cardinal'
277
277
  const pluralCategories = new Intl.PluralRules(this.config.extract?.primaryLanguage, { type }).resolvedOptions().pluralCategories
@@ -47,8 +47,16 @@ export function createPluginContext (allKeys: Map<string, ExtractedKey>, plugins
47
47
 
48
48
  return {
49
49
  addKey: (keyInfo: ExtractedKey) => {
50
- // Use namespace in the unique map key to avoid collisions across namespaces
51
- const uniqueKey = `${keyInfo.ns ?? 'translation'}:${keyInfo.key}`
50
+ // Normalize boolean `false` namespace -> undefined (meaning "no explicit ns")
51
+ const explicitNs = keyInfo.ns === false ? undefined : keyInfo.ns
52
+ // Internally prefer 'translation' as the logical namespace when none was specified.
53
+ // Record whether the namespace was implicit so the output generator can
54
+ // special-case config.extract.defaultNS === false.
55
+ const storedNs = explicitNs ?? (config.extract?.defaultNS ?? 'translation')
56
+ const nsIsImplicit = explicitNs === undefined
57
+ const nsForKey = String(storedNs)
58
+
59
+ const uniqueKey = `${nsForKey}:${keyInfo.key}`
52
60
  const defaultValue = keyInfo.defaultValue ?? keyInfo.key
53
61
 
54
62
  // Check if key already exists
@@ -68,12 +76,12 @@ export function createPluginContext (allKeys: Map<string, ExtractedKey>, plugins
68
76
 
69
77
  // If existing value is a generic fallback and new value is specific, replace it
70
78
  if (isExistingGenericFallback && !isNewGenericFallback) {
71
- allKeys.set(uniqueKey, { ...keyInfo, defaultValue })
79
+ allKeys.set(uniqueKey, { ...keyInfo, ns: storedNs || config.extract?.defaultNS || 'translation', nsIsImplicit, defaultValue })
72
80
  }
73
81
  // Otherwise keep the existing one
74
82
  } else {
75
83
  // New key, just add it
76
- allKeys.set(uniqueKey, { ...keyInfo, defaultValue })
84
+ allKeys.set(uniqueKey, { ...keyInfo, ns: storedNs || config.extract?.defaultNS || 'translation', nsIsImplicit, defaultValue })
77
85
  }
78
86
  },
79
87
  config: pluginContextConfig,
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))) {
package/src/status.ts CHANGED
@@ -94,7 +94,7 @@ async function generateStatusReport (config: I18nextToolkitConfig): Promise<Stat
94
94
 
95
95
  const keysByNs = new Map<string, ExtractedKey[]>()
96
96
  for (const key of allExtractedKeys.values()) {
97
- const ns = key.ns || defaultNS
97
+ const ns = key.ns || defaultNS || 'translation'
98
98
  if (!keysByNs.has(ns)) keysByNs.set(ns, [])
99
99
  keysByNs.get(ns)!.push(key)
100
100
  }
package/src/types.ts CHANGED
@@ -36,8 +36,11 @@ export interface I18nextToolkitConfig {
36
36
  /** Output path template with placeholders: {{language}} for locale, {{namespace}} for namespace */
37
37
  output: string;
38
38
 
39
- /** Default namespace when none is specified (default: 'translation') */
40
- defaultNS?: string;
39
+ /**
40
+ * Default namespace when none is specified (default: 'translation').
41
+ * Set to false will not generate any namespace, useful if i.e. the output is a single language json with 1 namespace (and no nesting).
42
+ */
43
+ defaultNS?: string | false;
41
44
 
42
45
  /** Separator for nested keys, or false for flat keys (default: '.') */
43
46
  keySeparator?: string | false | null;
@@ -293,7 +296,14 @@ export interface ExtractedKey {
293
296
  defaultValue?: string;
294
297
 
295
298
  /** Namespace this key belongs to */
296
- ns?: string;
299
+ ns?: string | false;
300
+
301
+ /**
302
+ * Whether the namespace was implicit (i.e. no explicit ns on the source).
303
+ * When true and config.extract.defaultNS === false the key should be treated
304
+ * as "no namespace" for output generation (top-level file).
305
+ */
306
+ nsIsImplicit?: boolean;
297
307
 
298
308
  /** Whether this key is used with pluralization (count parameter) */
299
309
  hasCount?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AA2UnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EAAE,uBAA+B,EAAE,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9E,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA8E9B"}
1
+ {"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AA2UnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EAAE,uBAA+B,EAAE,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9E,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAwF9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-manager.d.ts","sourceRoot":"","sources":["../../src/extractor/plugin-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjG;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAItE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CA0CxK"}
1
+ {"version":3,"file":"plugin-manager.d.ts","sourceRoot":"","sources":["../../src/extractor/plugin-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjG;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAItE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAkDxK"}
package/types/types.d.ts CHANGED
@@ -31,8 +31,11 @@ export interface I18nextToolkitConfig {
31
31
  ignore?: string | string[];
32
32
  /** Output path template with placeholders: {{language}} for locale, {{namespace}} for namespace */
33
33
  output: string;
34
- /** Default namespace when none is specified (default: 'translation') */
35
- defaultNS?: string;
34
+ /**
35
+ * Default namespace when none is specified (default: 'translation').
36
+ * Set to false will not generate any namespace, useful if i.e. the output is a single language json with 1 namespace (and no nesting).
37
+ */
38
+ defaultNS?: string | false;
36
39
  /** Separator for nested keys, or false for flat keys (default: '.') */
37
40
  keySeparator?: string | false | null;
38
41
  /** Separator between namespace and key, or false to disable (default: ':') */
@@ -242,7 +245,13 @@ export interface ExtractedKey {
242
245
  /** Default value to use in the primary language */
243
246
  defaultValue?: string;
244
247
  /** Namespace this key belongs to */
245
- ns?: string;
248
+ ns?: string | false;
249
+ /**
250
+ * Whether the namespace was implicit (i.e. no explicit ns on the source).
251
+ * When true and config.extract.defaultNS === false the key should be treated
252
+ * as "no namespace" for output generation (top-level file).
253
+ */
254
+ nsIsImplicit?: boolean;
246
255
  /** Whether this key is used with pluralization (count parameter) */
247
256
  hasCount?: boolean;
248
257
  /** Whether this key is used with ordinal pluralization */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,2DAA2D;IAC3D,OAAO,EAAE;QACP,oEAAoE;QACpE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAEzB,4DAA4D;QAC5D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAE3B,mGAAmG;QACnG,MAAM,EAAE,MAAM,CAAC;QAEf,wEAAwE;QACxE,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB,uEAAuE;QACvE,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;QAErC,8EAA8E;QAC9E,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;QAEpC,oDAAoD;QACpD,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAE1B,mDAAmD;QACnD,eAAe,CAAC,EAAE,MAAM,CAAC;QAEzB,+EAA+E;QAC/E,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAErB,4EAA4E;QAC5E,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAE3B;;;;;WAKG;QACH,mBAAmB,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;YACnC,IAAI,EAAE,MAAM,CAAC;YACb,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,YAAY,CAAC,EAAE,MAAM,CAA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