i18next-cli 1.31.0 → 1.33.0

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/README.md CHANGED
@@ -440,6 +440,27 @@ export default defineConfig({
440
440
  // When true, t('key', { count: 1 }) will only generate 'key' (no _one, _other suffixes)
441
441
  // The count option can still be used for {{count}} interpolation in the translation value
442
442
  disablePlurals: false, // Default: false
443
+
444
+ // Prefix for nested translations.
445
+ // Controls how nested $t(...) calls inside strings are detected.
446
+ // Example: '$t('
447
+ nestingPrefix: '$t(', // Default: '$t('
448
+
449
+ // Suffix for nested translations.
450
+ // Example: ')'
451
+ nestingSuffix: ')', // Default: ')'
452
+
453
+ // Separator for nested translation options.
454
+ // Used to split key vs options inside $t(key, {...}).
455
+ nestingOptionsSeparator: ',', // Default: ','
456
+
457
+ // Interpolation prefix used in defaultValue templates and runtime interpolation.
458
+ // Example: '{{'
459
+ interpolationPrefix: '{{', // Default: '{{'
460
+
461
+ // Interpolation suffix used in defaultValue templates and runtime interpolation.
462
+ // Example: '}}'
463
+ interpolationSuffix: '}}', // Default: '}}'
443
464
  },
444
465
 
445
466
  // options for linter
@@ -473,6 +494,7 @@ export default defineConfig({
473
494
  projectId: 'your-project-id',
474
495
  apiKey: process.env.LOCIZE_API_KEY, // Recommended: use environment variables
475
496
  version: 'latest',
497
+ cdnType: 'standard' // or 'pro'
476
498
  },
477
499
 
478
500
  // Plugin system
package/dist/cjs/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var e=require("commander"),o=require("chokidar"),t=require("glob"),n=require("minimatch"),i=require("chalk"),r=require("./config.js"),a=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti"),require("@croct/json5-parser");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),d=require("./init.js"),g=require("./linter.js"),f=require("./status.js"),p=require("./locize.js"),y=require("./rename-key.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.31.0"),m.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),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.").option("--sync-all","Sync primary language values with default values from code AND clear synced keys in all other locales.").action(async e=>{try{const t=m.opts().config,i=await r.ensureConfig(t),a=async()=>{const o=!!e.syncPrimary||!!e.syncAll,t=await c.runExtractor(i,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:o,syncAll:!!e.syncAll});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 a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.extract.input),t=h(i.extract.ignore),r=w(i.extract.output),c=[...t,...r].filter(Boolean),s=e.filter(e=>!c.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),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,o)=>{const t=m.opts().config;let n=await r.loadConfig(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await a.detectConfig();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=e}await f.runStatus(n,{detail:e,namespace:o.namespace})}),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 t=m.opts().config,i=await r.ensureConfig(t),a=()=>s.runTypesGenerator(i);if(await a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.types?.input||[]),t=[...h(i.extract?.ignore)].filter(Boolean),r=e.filter(e=>!t.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}),m.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=m.opts().config,o=await r.ensureConfig(e);await l.runSyncer(o)}),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 t=m.opts().config,c=async()=>{let e=await r.loadConfig(t);if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await a.detectConfig();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=o}await g.runLinterCli(e)};if(await c(),e.watch){console.log("\nWatching for changes...");const e=await r.loadConfig(t);if(e?.extract?.input){const t=await x(e.extract.input),i=[...h(e.extract.ignore),...w(e.extract.output)].filter(Boolean),r=t.filter(e=>!i.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}}),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 o=m.opts().config,t=await r.ensureConfig(o);await p.runLocizeSync(t,e)}),m.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const o=m.opts().config,t=await r.ensureConfig(o);await p.runLocizeDownload(t,e)}),m.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const o=m.opts().config,t=await r.ensureConfig(o);await p.runLocizeMigrate(t,e)}),m.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(e,o,t)=>{try{const n=m.opts().config,a=await r.ensureConfig(n),c=await y.runRenameKey(a,e,o,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(e=>console.error(` - ${e}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((e,o)=>e+o.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${e}"`))}catch(e){console.error(i.red("Error renaming key:"),e),process.exit(1)}}),m.parse(process.argv);const h=e=>Array.isArray(e)?e:e?[e]:[],w=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],x=async(e=[])=>{const o=h(e),n=await Promise.all(o.map(e=>t.glob(e||"",{nodir:!0})));return Array.from(new Set(n.flat()))};exports.program=m;
2
+ "use strict";var e=require("commander"),o=require("chokidar"),t=require("glob"),n=require("minimatch"),i=require("chalk"),r=require("./config.js"),a=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti"),require("@croct/json5-parser");var s=require("./types-generator.js"),l=require("./syncer.js"),d=require("./migrator.js"),u=require("./init.js"),p=require("./linter.js"),g=require("./status.js"),f=require("./locize.js"),y=require("./rename-key.js");const h=new e.Command;h.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.33.0"),h.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),h.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.").option("--sync-all","Sync primary language values with default values from code AND clear synced keys in all other locales.").action(async e=>{try{const t=h.opts().config,i=await r.ensureConfig(t),a=async()=>{const o=!!e.syncPrimary||!!e.syncAll,t=await c.runExtractor(i,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:o,syncAll:!!e.syncAll});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 a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.extract.input),t=m(i.extract.ignore),r=w(i.extract.output),c=[...t,...r].filter(Boolean),s=e.filter(e=>!c.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),h.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,o)=>{const t=h.opts().config;let n=await r.loadConfig(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await a.detectConfig();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=e}await g.runStatus(n,{detail:e,namespace:o.namespace})}),h.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const t=h.opts().config,i=await r.ensureConfig(t),a=()=>s.runTypesGenerator(i);if(await a(),e.watch){console.log("\nWatching for changes...");const e=await x(i.types?.input||[]),t=[...m(i.extract?.ignore)].filter(Boolean),r=e.filter(e=>!t.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}),h.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=h.opts().config,o=await r.ensureConfig(e);await l.runSyncer(o)}),h.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await d.runMigrator(e)}),h.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(u.runInit),h.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async e=>{const t=h.opts().config,c=async()=>{let e=await r.loadConfig(t);if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await a.detectConfig();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=o}await p.runLinterCli(e)};if(await c(),e.watch){console.log("\nWatching for changes...");const e=await r.loadConfig(t);if(e?.extract?.input){const t=await x(e.extract.input),i=[...m(e.extract.ignore),...w(e.extract.output)].filter(Boolean),r=t.filter(e=>!i.some(o=>n.minimatch(e,o,{dot:!0})));o.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}}),h.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.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async e=>{const o=h.opts().config,t=await r.ensureConfig(o);await f.runLocizeSync(t,e)}),h.command("locize-download").description("Download all translations from your locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async e=>{const o=h.opts().config,t=await r.ensureConfig(o);await f.runLocizeDownload(t,e)}),h.command("locize-migrate").description("Migrate local translation files to a new locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async e=>{const o=h.opts().config,t=await r.ensureConfig(o);await f.runLocizeMigrate(t,e)}),h.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(e,o,t)=>{try{const n=h.opts().config,a=await r.ensureConfig(n),c=await y.runRenameKey(a,e,o,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(e=>console.error(` - ${e}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((e,o)=>e+o.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${e}"`))}catch(e){console.error(i.red("Error renaming key:"),e),process.exit(1)}}),h.parse(process.argv);const m=e=>Array.isArray(e)?e:e?[e]:[],w=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],x=async(e=[])=>{const o=m(e),n=await Promise.all(o.map(e=>t.glob(e||"",{nodir:!0})));return Array.from(new Set(n.flat()))};exports.program=h;
@@ -1 +1 @@
1
- "use strict";var e=require("./ast-utils.js");exports.CallExpressionHandler=class{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,r,n,s,i){this.config=e,this.pluginContext=t,this.logger=r,this.expressionResolver=n,this.getCurrentFile=s,this.getCurrentCode=i}resetSearchIndex(){this.lastSearchIndex=0}getLocationFromNode(e){const t=this.getCurrentCode();let r;if("CallExpression"===e.type&&e.arguments.length>0){const t=e.arguments[0].expression;"StringLiteral"===t.type?r=t.raw??`'${t.value}'`:"TemplateLiteral"===t.type&&(r="`")}if(!r)return;const n=t.indexOf(r,this.lastSearchIndex);if(-1===n)return;this.lastSearchIndex=n+r.length;const s=t.substring(0,n).split("\n");return{line:s.length,column:s[s.length-1].length}}handleCallExpression(t,r){const n=this.getFunctionName(t.callee);if(!n)return;const s=r(n),i=this.config.extract.functions||["t","*.t"];let o=void 0!==s;if(!o)for(const e of i)if(e.startsWith("*.")){if(n.endsWith(e.substring(1))){o=!0;break}}else if(e===n){o=!0;break}if(!o||0===t.arguments.length)return;const{keysToProcess:l,isSelectorAPI:a}=this.handleCallExpressionArgument(t,0);if(0===l.length)return;let u=!1;const c=this.config.extract.pluralSeparator??"_";for(let e=0;e<l.length;e++)l[e].endsWith(`${c}ordinal`)&&(u=!0,l[e]=l[e].slice(0,-8));let p,f;if(t.arguments.length>1){const r=t.arguments[1].expression;"ObjectExpression"===r.type?f=r:"StringLiteral"===r.type?p=r.value:"TemplateLiteral"===r.type&&e.isSimpleTemplateLiteral(r)&&(p=r.quasis[0].cooked)}if(t.arguments.length>2){const e=t.arguments[2].expression;"ObjectExpression"===e.type&&(f=e)}const y=f?e.getObjectPropValue(f,"defaultValue"):void 0,g="string"==typeof y?y:p,h=e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1},d="string"==typeof g||h(f),x=h(f),k=Boolean(x||"string"==typeof g&&!("string"==typeof($=g)&&/{{\s*count\s*}}/.test($)));var $;for(let r=0;r<l.length;r++){const n=l[r];let i,o=l[r];if(f){const t=e.getObjectPropValue(f,"ns");"string"==typeof t&&(i=t)}const c=this.config.extract.nsSeparator??":";if(!i&&c&&o.includes(c)){const e=o.split(c);if(i=e.shift(),o=e.join(c),!o||""===o.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${i}${c}'`);continue}}!i&&s?.defaultNs&&(i=s.defaultNs),i||(i=this.config.extract.defaultNS);let p=o;if(s?.keyPrefix){const e=this.config.extract.keySeparator??".";if(p=!1!==e?s.keyPrefix.endsWith(e)?`${s.keyPrefix}${o}`:`${s.keyPrefix}${e}${o}`:`${s.keyPrefix}${o}`,!1!==e){if(p.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${p}' (keyPrefix: '${s.keyPrefix}', key: '${o}')`);continue}}}const y=r===l.length-1?"string"==typeof g?g:c&&n.includes(c||":")?n:o:o;if(f){const t=e.getObjectPropValueExpression(f,"context"),r=[];if("StringLiteral"===t?.type||"NumericLiteral"===t?.type||"BooleanLiteral"===t?.type){const e=`${t.value}`,n=this.config.extract.contextSeparator??"_";""!==e&&r.push({key:`${p}${n}${e}`,ns:i,defaultValue:y,explicitDefault:d})}else if(t){const e=this.expressionResolver.resolvePossibleContextStringValues(t),n=this.config.extract.contextSeparator??"_";e.length>0&&e.forEach(e=>{r.push({key:`${p}${n}${e}`,ns:i,defaultValue:y,explicitDefault:d})}),r.push({key:p,ns:i,defaultValue:y,explicitDefault:d,keyAcceptingContext:p})}const n=e=>{if(e){if("KeyValueProperty"===e.type&&e.key){if("Identifier"===e.key.type)return e.key.value;if("StringLiteral"===e.key.type)return e.key.value}return"KeyValueProperty"===e.type&&e.value&&"Identifier"===e.value.type?e.key&&"Identifier"===e.key.type?e.key.value:void 0:"ShorthandProperty"!==e.type&&"Identifier"!==e.type||!e.value?e.key&&"string"==typeof e.key?e.key:void 0:e.value}},s=(()=>{if(!f||!Array.isArray(f.properties))return!1;for(const e of f.properties){if("count"===n(e))return!0}return!1})(),o=(()=>{if(!f||!Array.isArray(f.properties))return!1;for(const e of f.properties){if("ordinal"===n(e))return!("KeyValueProperty"!==e.type||!e.value||"BooleanLiteral"!==e.value.type)&&Boolean(e.value.value)}return!1})();if(s||u){try{const e=u?"ordinal":"cardinal",t=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let n=!1;try{const r=new Intl.PluralRules(t,{type:e}).resolvedOptions().pluralCategories;1===r.length&&"other"===r[0]&&(n=!0)}catch{}if(!n){const t=new Set;for(const r of this.config.locales)try{new Intl.PluralRules(r,{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}catch{new Intl.PluralRules("en",{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}const r=Array.from(t).sort();1===r.length&&"other"===r[0]&&(n=!0)}if(n){if(r.length>0)for(const e of r)this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,hasCount:!0,isOrdinal:u});else this.pluginContext.addKey({key:p,ns:i,defaultValue:y,hasCount:!0,isOrdinal:u});continue}}catch(e){}this.config.extract.disablePlurals?r.length>0?r.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:p,ns:i,defaultValue:y,explicitDefault:d}):this.handlePluralKeys(p,i,f,o||u,g,k);continue}if(r.length>0){r.forEach(this.pluginContext.addKey);continue}!0===e.getObjectPropValue(f,"returnObjects")&&this.objectKeys.add(p)}a&&this.objectKeys.add(p);{const e=this.getLocationFromNode(t);this.pluginContext.addKey({key:p,ns:i,defaultValue:y,explicitDefault:d,locations:e?[{file:this.getCurrentFile(),line:e.line,column:e.column}]:void 0})}}}handleCallExpressionArgument(e,t){const r=e.arguments[t].expression,n=[];let s=!1;if("ArrowFunctionExpression"===r.type){const e=this.extractKeyFromSelector(r);e&&(n.push(e),s=!0)}else if("ArrayExpression"===r.type)for(const e of r.elements)e?.expression&&n.push(...this.expressionResolver.resolvePossibleKeyStringValues(e.expression));else n.push(...this.expressionResolver.resolvePossibleKeyStringValues(r));return{keysToProcess:n.filter(e=>!!e),isSelectorAPI:s}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let r=t;const n=[];for(;"MemberExpression"===r.type;){const e=r.property;if("Identifier"===e.type)n.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;n.unshift(e.expression.value)}r=r.object}if(n.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return n.join(t)}return null}handlePluralKeys(t,r,n,s,i,o){try{const l=s?"ordinal":"cardinal",a=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:l});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:l});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}const u=Array.from(a).sort(),c=this.config.extract.pluralSeparator??"_",p=e.getObjectPropValue(n,"defaultValue"),f=e.getObjectPropValue(n,`defaultValue${c}other`),y=e.getObjectPropValue(n,`defaultValue${c}ordinal${c}other`),g=e.getObjectPropValueExpression(n,"context"),h=[];if(g){const e=this.expressionResolver.resolvePossibleContextStringValues(g);if(e.length>0)if("StringLiteral"===g.type)for(const r of e)r.length>0&&h.push({key:t,context:r});else{for(const r of e)r.length>0&&h.push({key:t,context:r});!1!==this.config.extract?.generateBasePluralForms&&h.push({key:t})}else h.push({key:t})}else h.push({key:t});const d=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let x=!1;try{const e=new Intl.PluralRules(d,{type:l}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&(x=!0)}catch{x=!1}if(x||1===u.length&&"other"===u[0]){for(const{key:t,context:l}of h){const a=e.getObjectPropValue(n,`defaultValue${c}other`);let u;u="string"==typeof a?a:"string"==typeof p?p:"string"==typeof i?i:l?`${t}_${l}`:t;const f=this.config.extract.contextSeparator??"_",y=l?`${t}${f}${l}`:t;this.pluginContext.addKey({key:y,ns:r,defaultValue:u,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(o||"string"==typeof a)})}return}for(const{key:l,context:a}of h)for(const g of u){const u=s?`defaultValue${c}ordinal${c}${g}`:`defaultValue${c}${g}`,h=e.getObjectPropValue(n,u);let d,x;if(d="string"==typeof h?h:"one"===g&&"string"==typeof p?p:"one"===g&&"string"==typeof i?i:s&&"string"==typeof y?y:s||"string"!=typeof f?"string"==typeof p?p:"string"==typeof i?i:l:f,a){const e=this.config.extract.contextSeparator??"_";x=s?`${l}${e}${a}${c}ordinal${c}${g}`:`${l}${e}${a}${c}${g}`}else x=s?`${l}${c}ordinal${c}${g}`:`${l}${c}${g}`;this.pluginContext.addKey({key:x,ns:r,defaultValue:d,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(o||"string"==typeof h||"string"==typeof f),keyAcceptingContext:void 0!==a?t:void 0})}}catch(s){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const o=i||e.getObjectPropValue(n,"defaultValue");this.pluginContext.addKey({key:t,ns:r,defaultValue:"string"==typeof o?o:t})}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let r=e;for(;"MemberExpression"===r.type;){if("Identifier"!==r.property.type)return null;t.unshift(r.property.value),r=r.object}if("ThisExpression"===r.type)t.unshift("this");else{if("Identifier"!==r.type)return null;t.unshift(r.value)}return t.join(".")}return null}};
1
+ "use strict";var e=require("./ast-utils.js");const t=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");exports.CallExpressionHandler=class{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,n,r,s,i){this.config=e,this.pluginContext=t,this.logger=n,this.expressionResolver=r,this.getCurrentFile=s,this.getCurrentCode=i}resetSearchIndex(){this.lastSearchIndex=0}getLocationFromNode(e){const t=this.getCurrentCode();let n;if("CallExpression"===e.type&&e.arguments.length>0){const t=e.arguments[0].expression;"StringLiteral"===t.type?n=t.raw??`'${t.value}'`:"TemplateLiteral"===t.type?n="`":"ArrowFunctionExpression"===t.type&&(n="=>")}if(!n)return;const r=t.indexOf(n,this.lastSearchIndex);if(-1===r)return;this.lastSearchIndex=r+n.length;const s=t.substring(0,r).split("\n");return{line:s.length,column:s[s.length-1].length}}handleCallExpression(n,r){const s=this.getFunctionName(n.callee);if(!s)return;const i=r(s),o=this.config.extract.functions||["t","*.t"];let l=void 0!==i;if(!l)for(const e of o)if(e.startsWith("*.")){if(s.endsWith(e.substring(1))){l=!0;break}}else if(e===s){l=!0;break}if(!l||0===n.arguments.length)return;const{keysToProcess:a,isSelectorAPI:c}=this.handleCallExpressionArgument(n,0);if(0===a.length)return;let u=!1;const f=this.config.extract.pluralSeparator??"_";for(let e=0;e<a.length;e++)a[e].endsWith(`${f}ordinal`)&&(u=!0,a[e]=a[e].slice(0,-8));let p,y;if(n.arguments.length>1){const t=n.arguments[1].expression;"ObjectExpression"===t.type?y=t:"StringLiteral"===t.type?p=t.value:"TemplateLiteral"===t.type&&e.isSimpleTemplateLiteral(t)&&(p=t.quasis[0].cooked)}if(n.arguments.length>2){const e=n.arguments[2].expression;"ObjectExpression"===e.type&&(y=e)}const g=y?e.getObjectPropValue(y,"defaultValue"):void 0,h="string"==typeof g?g:p,d=e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1},x="string"==typeof h||d(y),$=d(y),k=Boolean($||"string"==typeof h&&!(e=>{if("string"!=typeof e)return!1;const n=this.config.extract.interpolationPrefix??"{{",r=this.config.extract.interpolationSuffix??"}}";return new RegExp(`${t(n)}\\s*count\\s*${t(r)}`).test(e)})(h));for(let t=0;t<a.length;t++){const r=a[t];let s,o=a[t];if(y){const t=e.getObjectPropValue(y,"ns");"string"==typeof t&&(s=t)}const l=this.config.extract.nsSeparator??":";if(!s&&l&&o.includes(l)){const e=o.split(l);if(s=e.shift(),o=e.join(l),!o||""===o.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${s}${l}'`);continue}}!s&&i?.defaultNs&&(s=i.defaultNs),s||(s=this.config.extract.defaultNS);let f=o;if(i?.keyPrefix){const e=this.config.extract.keySeparator??".";if(f=!1!==e?i.keyPrefix.endsWith(e)?`${i.keyPrefix}${o}`:`${i.keyPrefix}${e}${o}`:`${i.keyPrefix}${o}`,!1!==e){if(f.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${f}' (keyPrefix: '${i.keyPrefix}', key: '${o}')`);continue}}}const p=t===a.length-1?"string"==typeof h?h:l&&r.includes(l||":")?r:o:o;if(y){const t=e.getObjectPropValueExpression(y,"context"),n=[];if("StringLiteral"===t?.type||"NumericLiteral"===t?.type||"BooleanLiteral"===t?.type){const e=`${t.value}`,r=this.config.extract.contextSeparator??"_";""!==e&&n.push({key:`${f}${r}${e}`,ns:s,defaultValue:p,explicitDefault:x})}else if(t){const e=this.expressionResolver.resolvePossibleContextStringValues(t),r=this.config.extract.contextSeparator??"_";e.length>0&&e.forEach(e=>{n.push({key:`${f}${r}${e}`,ns:s,defaultValue:p,explicitDefault:x})}),n.push({key:f,ns:s,defaultValue:p,explicitDefault:x,keyAcceptingContext:f})}const r=e=>{if(e){if("KeyValueProperty"===e.type&&e.key){if("Identifier"===e.key.type)return e.key.value;if("StringLiteral"===e.key.type)return e.key.value}return"KeyValueProperty"===e.type&&e.value&&"Identifier"===e.value.type?e.key&&"Identifier"===e.key.type?e.key.value:void 0:"ShorthandProperty"!==e.type&&"Identifier"!==e.type||!e.value?e.key&&"string"==typeof e.key?e.key:void 0:e.value}},i=(()=>{if(!y||!Array.isArray(y.properties))return!1;for(const e of y.properties){if("count"===r(e))return!0}return!1})(),o=(()=>{if(!y||!Array.isArray(y.properties))return!1;for(const e of y.properties){if("ordinal"===r(e))return!("KeyValueProperty"!==e.type||!e.value||"BooleanLiteral"!==e.value.type)&&Boolean(e.value.value)}return!1})();if(i||u){try{const e=u?"ordinal":"cardinal",t=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let r=!1;try{const n=new Intl.PluralRules(t,{type:e}).resolvedOptions().pluralCategories;1===n.length&&"other"===n[0]&&(r=!0)}catch{}if(!r){const t=new Set;for(const n of this.config.locales)try{new Intl.PluralRules(n,{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}catch{new Intl.PluralRules("en",{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}const n=Array.from(t).sort();1===n.length&&"other"===n[0]&&(r=!0)}if(r){if(n.length>0)for(const e of n)this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,hasCount:!0,isOrdinal:u});else this.pluginContext.addKey({key:f,ns:s,defaultValue:p,hasCount:!0,isOrdinal:u});continue}}catch(e){}this.config.extract.disablePlurals?n.length>0?n.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:f,ns:s,defaultValue:p,explicitDefault:x}):this.handlePluralKeys(f,s,y,o||u,h,k);continue}if(n.length>0){n.forEach(this.pluginContext.addKey);continue}!0===e.getObjectPropValue(y,"returnObjects")&&this.objectKeys.add(f)}c&&this.objectKeys.add(f);{const e=this.getLocationFromNode(n);this.pluginContext.addKey({key:f,ns:s,defaultValue:p,explicitDefault:x,locations:e?[{file:this.getCurrentFile(),line:e.line,column:e.column}]:void 0}),this.extractNestedKeys(f,s)}"string"==typeof h&&this.extractNestedKeys(h,s)}}extractNestedKeys(e,n){if(!e||"string"!=typeof e)return;const r=this.config.extract.nestingPrefix??"$t(",s=this.config.extract.nestingSuffix??")",i=t(r),o=t(s),l=new RegExp(`${i}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${o}`,"g");let a;for(;null!==(a=l.exec(e));)a[1]&&this.processNestedContent(a[1],void 0)}processNestedContent(e,n){let r=e,s="";const i=this.config.extract.nestingOptionsSeparator??",";if(e.indexOf(i)<0)r=e.trim();else{const n=new RegExp(`${t(i)}[ ]*{`),o=e.split(n);if(o.length>1)r=o[0].trim(),s=`{${o.slice(1).join(i+" {")}`;else{const t=e.indexOf(i);r=e.substring(0,t).trim(),s=e.substring(t+1).trim()}}if((r.startsWith("'")&&r.endsWith("'")||r.startsWith('"')&&r.endsWith('"'))&&(r=r.slice(1,-1)),!r)return;let o;const l=this.config.extract.nsSeparator??":";if(l&&r.includes(l)){const e=r.split(l);if(o=e.shift(),r=e.join(l),!r||""===r.trim())return}else o=this.config.extract.defaultNS;let a,c=!1;if(s){/['"]?count['"]?\s*:/.test(s)&&(c=!0);const e=/['"]?context['"]?\s*:\s*(['"])(.*?)\1/.exec(s);e&&(a=e[2])}c||void 0!==a?this.generateNestedPluralKeys(r,o,c,a):this.pluginContext.addKey({key:r,ns:o})}generateNestedPluralKeys(e,t,n,r){try{const s="cardinal";if(!n&&void 0!==r)return this.pluginContext.addKey({key:e,ns:t}),void this.pluginContext.addKey({key:`${e}_${r}`,ns:t});const i=new Set,o=this.config.locales||["en"];for(const e of o)try{const t=new Intl.PluralRules(e,{type:s});t.resolvedOptions().pluralCategories.forEach(e=>i.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:s});t.resolvedOptions().pluralCategories.forEach(e=>i.add(e))}const l=Array.from(i).sort(),a=this.config.extract.pluralSeparator??"_",c=this.config.extract.contextSeparator??"_",u=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let f=!1;try{const e=new Intl.PluralRules(u,{type:s}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&(f=!0)}catch{f=!1}const p=f||1===l.length&&"other"===l[0],y=[];if(void 0!==r?y.push({key:e,context:r}):y.push({key:e}),p){for(const{key:e,context:n}of y){const r=n?`${e}${c}${n}`:e;this.pluginContext.addKey({key:r,ns:t,hasCount:!0})}return}for(const{key:e,context:n}of y)for(const r of l){let s;s=n?`${e}${c}${n}${a}${r}`:`${e}${a}${r}`,this.pluginContext.addKey({key:s,ns:t,hasCount:!0})}}catch(n){this.pluginContext.addKey({key:e,ns:t})}}handleCallExpressionArgument(e,t){const n=e.arguments[t].expression,r=[];let s=!1;if("ArrowFunctionExpression"===n.type){const e=this.extractKeyFromSelector(n);e&&(r.push(e),s=!0)}else if("ArrayExpression"===n.type)for(const e of n.elements)e?.expression&&r.push(...this.expressionResolver.resolvePossibleKeyStringValues(e.expression));else r.push(...this.expressionResolver.resolvePossibleKeyStringValues(n));return{keysToProcess:r.filter(e=>!!e),isSelectorAPI:s}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let n=t;const r=[];for(;"MemberExpression"===n.type;){const e=n.property;if("Identifier"===e.type)r.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;r.unshift(e.expression.value)}n=n.object}if(r.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return r.join(t)}return null}handlePluralKeys(t,n,r,s,i,o){try{const l=s?"ordinal":"cardinal",a=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:l});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:l});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}const c=Array.from(a).sort(),u=this.config.extract.pluralSeparator??"_",f=e.getObjectPropValue(r,"defaultValue"),p=e.getObjectPropValue(r,`defaultValue${u}other`),y=e.getObjectPropValue(r,`defaultValue${u}ordinal${u}other`),g=e.getObjectPropValueExpression(r,"context"),h=[];if(g){const e=this.expressionResolver.resolvePossibleContextStringValues(g);if(e.length>0)if("StringLiteral"===g.type)for(const n of e)n.length>0&&h.push({key:t,context:n});else{for(const n of e)n.length>0&&h.push({key:t,context:n});!1!==this.config.extract?.generateBasePluralForms&&h.push({key:t})}else h.push({key:t})}else h.push({key:t});const d=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let x=!1;try{const e=new Intl.PluralRules(d,{type:l}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&(x=!0)}catch{x=!1}if(x||1===c.length&&"other"===c[0]){for(const{key:t,context:l}of h){const a=e.getObjectPropValue(r,`defaultValue${u}other`);let c;c="string"==typeof a?a:"string"==typeof f?f:"string"==typeof i?i:l?`${t}_${l}`:t;const p=this.config.extract.contextSeparator??"_",y=l?`${t}${p}${l}`:t;this.pluginContext.addKey({key:y,ns:n,defaultValue:c,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(o||"string"==typeof a)})}return}for(const{key:l,context:a}of h)for(const g of c){const c=s?`defaultValue${u}ordinal${u}${g}`:`defaultValue${u}${g}`,h=e.getObjectPropValue(r,c);let d,x;if(d="string"==typeof h?h:"one"===g&&"string"==typeof f?f:"one"===g&&"string"==typeof i?i:s&&"string"==typeof y?y:s||"string"!=typeof p?"string"==typeof f?f:"string"==typeof i?i:l:p,a){const e=this.config.extract.contextSeparator??"_";x=s?`${l}${e}${a}${u}ordinal${u}${g}`:`${l}${e}${a}${u}${g}`}else x=s?`${l}${u}ordinal${u}${g}`:`${l}${u}${g}`;this.pluginContext.addKey({key:x,ns:n,defaultValue:d,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(o||"string"==typeof h||"string"==typeof p),keyAcceptingContext:void 0!==a?t:void 0})}}catch(s){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const o=i||e.getObjectPropValue(r,"defaultValue");this.pluginContext.addKey({key:t,ns:n,defaultValue:"string"==typeof o?o:t})}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let n=e;for(;"MemberExpression"===n.type;){if("Identifier"!==n.property.type)return null;t.unshift(n.property.value),n=n.object}if("ThisExpression"===n.type)t.unshift("this");else{if("Identifier"!==n.type)return null;t.unshift(n.value)}return t.join(".")}return null}};
@@ -1 +1 @@
1
- "use strict";var e=require("./ast-utils.js");function t(t){if(t)return"StringLiteral"===t.type?t.value:"TemplateLiteral"===t.type&&e.isSimpleTemplateLiteral(t)?t.quasis[0].cooked:void 0}function n(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?t(e.value.expression):void 0}exports.extractFromTransComponent=function(i,s){const r=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),o=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),p=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),l=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let a;p||"JSXAttribute"!==l?.type||"JSXExpressionContainer"!==l.value?.type||"ObjectExpression"!==l.value.expression.type||(a=e.getObjectPropValueExpression(l.value.expression,"count"));const c=!!p||!!a,u=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),f="JSXAttribute"===u?.type&&"JSXExpressionContainer"===u.value?.type&&"ObjectExpression"===u.value.expression.type?u.value.expression:void 0,y=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),d=!!y,g=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let x="JSXAttribute"===g?.type&&"JSXExpressionContainer"===g.value?.type?g.value.expression:"JSXAttribute"===g?.type&&"StringLiteral"===g.value?.type?g.value:void 0;const h=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let S;S="JSXAttribute"===h?.type?n(h):void 0,f&&(void 0===S&&(S=e.getObjectPropValue(f,"ns")),void 0===x&&(x=e.getObjectPropValueExpression(f,"context")));const v=function(e,n){if(!e||0===e.length)return"";const i=new Set(n.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),s=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function r(e,n,o=!1,p=!1){if(!e||!e.length)return;const l=p&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let a=0,c=e.length-1;for(;a<=c&&s(e[a]);)a++;for(;c>=a&&s(e[c]);)c--;const u=a<=c?e.slice(a,c+1):[],f=u.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<u.length;e++){const a=u[e];if(a)if("JSXText"!==a.type){if("JSXExpressionContainer"===a.type){if(o&&!f&&a.expression){const e=a.expression.type;if("ObjectExpression"===e)continue;if(void 0!==t(a.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const i=t(a.expression);if(void 0!==i){const t=/^\s*$/.test(i)&&!i.includes("\n"),r=u[e-1],o=u[e+1];if(t){const t=u[e+2];if(o&&"JSXText"===o.type&&s(o)&&t&&("JSXElement"===t.type||"JSXFragment"===t.type)){const t=u[e-1],n=u[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue;const i=!o||"JSXText"===o.type&&!s(o);if(r&&"JSXText"===r.type&&i){const e=n[n.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+a.expression.value;continue}}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue}}n.push(a);continue}if("JSXElement"===a.type){const e=a.opening&&a.opening.name&&"Identifier"===a.opening.name.type?a.opening.name.value:void 0;if(e&&i.has(e)){const o=a.opening&&Array.isArray(a.opening.attributes)&&a.opening.attributes.length>0,c=a.children||[],f=1===c.length&&("JSXText"===c[0]?.type||"JSXExpressionContainer"===c[0]?.type&&void 0!==t(c[0].expression)),y=!c.length,d=f;if(o&&!f)n.push(a),r(a.children||[],n,!0);else if(y)n.push(a);else if(!d){if((a.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===t(e.expression)))n.push(a),r(a.children||[],n,!0);else if("p"===e){const e=(c||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,s=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));return!(n&&i.has(n)&&!s&&(0===r.length||o))}),o=p&&u.some(e=>e&&e!==a&&"JSXText"===e.type&&!s(e));l||p&&e&&!o?(n.push(a),r(a.children||[],n,!0,!1)):r(a.children||[],n,!1,!1)}else r(a.children||[],n,!1,!1)}continue}n.push(a),r(a.children||[],n,!0);continue}"JSXFragment"!==a.type||r(a.children||[],n,o)}else{if(o&&!f)continue;if(o&&s(a))continue;if(s(a)){const t=u[e-1],i=u[e+1];if(t&&("JSXElement"===t.type||"JSXFragment"===t.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=n[n.length-1],r=u[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+a.value;continue}}}if(o&&f&&0===e)continue;n.push(a)}}}const o=[];function p(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==o.indexOf(n))return t;if("JSXText"===n.type&&-1!==o.indexOf(n)){if(s(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}r(e,o,!1,!0);const l=new Set,a=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function c(e,n,r=!1){if(!e||0===e.length)return"";let u="";const f=e=>{if(!e)return-1;if(n&&n.has(e))return n.get(e);if(n)for(const[t,i]of n.entries())try{if(t&&e&&t.span&&e.span&&t.span.start===e.span.start&&t.span.end===e.span.end)return i}catch(e){}return o.indexOf(e)},y=t=>{if(!r)return o.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?s(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let n=0;n<e.length;n++){const d=e[n];if(d){if("JSXText"===d.type){if(s(d))continue;const t=e[n+1],r=e[n-1];if(r&&"JSXElement"===r.type){const t="Identifier"===r.opening?.name?.type?r.opening.name.value:void 0,s=t&&i.has(t),o=0===(r.children||[]).length;if(s&&o&&/^\s*\n\s*/.test(d.value)){const e=d.value.replace(/^\s*\n\s*/,"");if(e){u+=e;continue}continue}if(!s&&/^\s*\n\s*/.test(d.value)){const t=d.value.replace(/^\s*\n\s*/,"");if(t){if(r&&"JSXElement"===r.type&&Array.isArray(r.children)&&0===r.children.length){u+=t;continue}const i=e[n-2];if(i&&"JSXText"===i.type){const e=i.value.replace(/\n\s*$/,""),n=/[A-Za-z0-9]$/.test(e),s=/^[A-Za-z0-9]/.test(t),r=/^[a-z]/.test(t);if(n&&s&&r){u+=t;continue}}u+=" "+t;continue}continue}}if(/\n\s*$/.test(d.value)&&t&&"JSXElement"===t.type){const r=d.value.replace(/\n\s*$/,"");if(r.trim()){const o="Identifier"===t.opening?.name?.type?t.opening.name.value:void 0,p=o&&i.has(o),a=(t.children||[]).length>0,c=/\s\n/.test(d.value),f=e[n+2],y=f&&"JSXText"===f.type&&!s(f)&&/[a-zA-Z0-9]/.test(f.value),g=!!(t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0),x=/^\s/.test(r)&&!/^\n/.test(r),h=r.trim(),S=x?" "+h:h,v=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),$=g&&a&&y&&!(v&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;v&&m&&J&&!c&&!x&&!X&&l.add(t),u+=c||p&&a||!p&&y&&x||b?S+" ":S;continue}}u+=d.value;continue}if("JSXExpressionContainer"===d.type){const e=d.expression;if(!e)continue;const n=t(e);if(void 0!==n)u+=n;else if("Identifier"===e.type)u+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)u+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)u+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)u+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)u+=`{{${e.callee.value}}}`;else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===d.type){const l=r?y(d):void 0;let g;if(d.opening&&d.opening.name&&"Identifier"===d.opening.name.type&&(g=d.opening.name.value),g&&i.has(g)){const y=d.opening&&Array.isArray(d.opening.attributes)&&d.opening.attributes.length>0,x=d.children||[],h=x.length>0,S=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==t(x[0].expression)),v="p"===g;let m=0;if(v&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||S){const t=S?c(x,void 0):"";if(""!==String(t).trim())if(i.has(g)&&"p"!==g)u+=`<${g}>${a(t)}</${g}>`;else if(v&&r&&m>1)u+=`<${g}>${a(t)}</${g}>`;else if(v){const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(t)}</${e}>`}else{const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(t)}</${e}>`}else{const t=e[n-1];t&&"JSXText"===t.type&&/\n\s*$/.test(t.value)&&(u=u.replace(/\s+$/,"")),u+=`<${g} />`}}else if(y&&!S){const e=x,n=r&&void 0!==l?l:f(d);if(p(e)){const s=new Map;let r=0;for(const n of e)if(n&&"JSXElement"===n.type){const e=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(e&&i.has(e)){const e=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,i=n.children||[],o=1===i.length&&("JSXText"===i[0]?.type||"JSXExpressionContainer"===i[0]?.type&&void 0!==t(i[0].expression));!e&&(!i.length||o)||s.set(n,r++)}else s.set(n,r++)}const o=c(e,s.size?s:void 0);u+=`<${n}>${a(o)}</${n}>`}else{const e=new Map;let s=0;for(const n of x)if(n&&"JSXElement"===n.type){const r=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(r&&i.has(r)){const i=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,r=n.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));!i&&(!r.length||o)||e.set(n,s++)}else e.set(n,s++)}const r=c(x,e.size?e:void 0);u+=`<${n}>${a(r)}</${n}>`}}else{const e=o.indexOf(d);if(-1!==e){const n=void 0!==l?l:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==o.indexOf(t))return e;if("JSXText"===t.type&&-1!==o.indexOf(t)){if(s(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===n){const e=c(x,void 0,!1);u+=`<${n}>${a(e)}</${n}>`;continue}const e=new Map;let s=0;for(const n of x)if(n&&"JSXElement"===n.type){const r=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(r&&i.has(r)){const i=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,r=n.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));!i&&(!r.length||o)||e.set(n,s++)}else e.set(n,s++)}const r=c(x,e.size?e:void 0,!1);u+=`<${n}>${a(r)}</${n}>`;continue}const r=new Map;let p=0;for(const e of x)if(e&&"JSXElement"===e.type){const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(n&&i.has(n)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,i=e.children||[],s=1===i.length&&("JSXText"===i[0]?.type||"JSXExpressionContainer"===i[0]?.type&&void 0!==t(i[0].expression));!n&&(!i.length||s)||r.set(e,p++)}else r.set(e,p++)}const f=c(x,r.size>0?r:void 0,!1);u+=`<${n}>${a(f)}</${n}>`}else{const e=c(x,void 0,!1);u+=`<${g}>${a(e)}</${g}>`}}}else{const e=d.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(d),n=c(e,void 0);u+=`<${t}>${a(n)}</${t}>`}else{const t=new Map,n=f(d);let s=0;for(const n of e)if(n&&"JSXElement"===n.type){const e=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(e&&i.has(e)){const e=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,i=n.children||[],r=1===i.length&&"JSXText"===i[0]?.type;!e&&(!i.length||r)||t.set(n,s++)}else t.set(n,s++)}const r=c(e,t.size?t:void 0);u+=`<${n}>${a(r)}</${n}>`}}continue}"JSXFragment"!==d.type||(u+=c(d.children||[]))}}return u}const u=c(e,void 0,!0),f=String(u).replace(/<br \/>\s*\n\s*/g,"<br />"),y=String(f),d=new Set;if(l&&l.size>0)for(let e=0;e<o.length;e++)l.has(o[e])&&d.add(e);let g=String(y);if(d&&d.size>0)for(const e of d)try{g=g.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),g=g.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}g=g.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return d.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),g=g.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return d.has(i)?`${t}<${n}`:`${t} <${n}`}),g=g.replace(/\s*\n\s*/g," "),g=g.replace(/\s+/g," "),g=g.replace(/\s+([,;:!?.])/g,"$1");const x=g.trim();let h=String(x);if(d&&d.size>0)for(const e of d)try{h=h.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),h=h.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<o.length;e++){const t=o[e];if(!t||"JSXElement"!==t.type)continue;const n=o[e-1],i=o[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),p=s.replace(/\n\s*$/,""),l=/[A-Za-z0-9]$/.test(p),a=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(l&&a&&c&&!u&&!f){const t=e;h=h.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function S(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function n(e,t=null){let s="";for(const r of e)if("text"===r.type)s+=r.text;else{const e=r.children.filter(e=>"ph"===e.type),p=e.map(e=>e.idx);if(!(p.length<=1||p.every((e,t)=>0===t||e===p[t-1]+1))){const e=r.children.map(e=>"text"===e.type?e.text:`<${e.idx}>${n(e.children,e.idx)}</${e.idx}>`).join("");s+=`<${r.idx}>${e}</${r.idx}>`;continue}const l=new Map;let a=0;try{const n=o[r.idx];if(n&&n.span){const s=n.span.start,p=n.span.end;let l=-1;for(let e=r.idx+1;e<o.length;e++){const t=o[e];if(t&&t.span&&(t.span.start>=s&&t.span.end<=p&&"JSXElement"===t.type)){l=e;break}}let c=0;if(-1!==l)for(let e=r.idx+1;e<l;e++){const t=o[e];t&&t.span&&(t.span.start>=s&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||c++))}else for(let e=r.idx+1;e<o.length;e++){const t=o[e];t&&t.span&&(t.span.start>=s&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||c++))}if("number"==typeof r.idx){const n=o[r.idx],s=n?.opening?.name?.value,p=s&&i.has(s),l=null===t;1===e.length?(a=Math.max(1,c+1),!l||p||0!==e[0].idx||"a"!==s&&"p"!==s||(a=0)):a=0}}}catch(e){}for(const t of e)l.has(t.idx)||l.set(t.idx,a++);const c=r.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,i=l.has(t)?l.get(t):t;return`<${i}>${n(e.children,i)}</${i}>`}).join("");s+=`<${r.idx}>${c}</${r.idx}>`}return s}try{return n(t(e))}catch(t){return e}}return h=S(h),h.trim()}(i.children,s);let m;const J="JSXAttribute"===o?.type?n(o):void 0;if(void 0!==J)m=J;else{const e=s.extract.defaultValue;m="string"==typeof e?e:""}let X,$;if("JSXAttribute"===r?.type){if("StringLiteral"===r.value?.type){if(X=r.value,$=X.value,!$||""===$.trim())return null;if(S&&"StringLiteral"===X.type){const e=s.extract.nsSeparator??":",t=X.value;if(e&&t.startsWith(`${S}${e}`)){if($=t.slice(`${S}${e}`.length),!$||""===$.trim())return null;X={...X,value:$}}}}else"JSXExpressionContainer"===r.value?.type&&"JSXEmptyExpression"!==r.value.expression.type&&(X=r.value.expression);if(!X)return null}return o||!$||v.trim()?!o&&v.trim()&&(m=v):m=$,{keyExpression:X,serializedChildren:v,ns:S,defaultValue:m,hasCount:c,isOrdinal:d,contextExpression:x,optionsNode:f,explicitDefault:void 0!==J||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(f)}};
1
+ "use strict";var e=require("./ast-utils.js");function t(t){if(t)return"StringLiteral"===t.type?t.value:"TemplateLiteral"===t.type&&e.isSimpleTemplateLiteral(t)?t.quasis[0].cooked:void 0}function n(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?t(e.value.expression):void 0}exports.extractFromTransComponent=function(i,s){const r=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),o=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),p=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),l=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let a;p||"JSXAttribute"!==l?.type||"JSXExpressionContainer"!==l.value?.type||"ObjectExpression"!==l.value.expression.type||(a=e.getObjectPropValueExpression(l.value.expression,"count"));const c=!!p||!!a,u=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),f="JSXAttribute"===u?.type&&"JSXExpressionContainer"===u.value?.type&&"ObjectExpression"===u.value.expression.type?u.value.expression:void 0,y=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),d=!!y,g=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let x="JSXAttribute"===g?.type&&"JSXExpressionContainer"===g.value?.type?g.value.expression:"JSXAttribute"===g?.type&&"StringLiteral"===g.value?.type?g.value:void 0;const h=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let S;S="JSXAttribute"===h?.type?n(h):void 0,f&&(void 0===S&&(S=e.getObjectPropValue(f,"ns")),void 0===x&&(x=e.getObjectPropValueExpression(f,"context")));const v=function(e,n){if(!e||0===e.length)return"";const i=new Set(n.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),s=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function r(e,n,o=!1,p=!1){if(!e||!e.length)return;const l=p&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let a=0,c=e.length-1;for(;a<=c&&s(e[a]);)a++;for(;c>=a&&s(e[c]);)c--;const u=a<=c?e.slice(a,c+1):[],f=u.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<u.length;e++){const a=u[e];if(a)if("JSXText"!==a.type){if("JSXExpressionContainer"===a.type){if(o&&!f&&a.expression){const e=a.expression.type;if("ObjectExpression"===e)continue;if(void 0!==t(a.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const i=t(a.expression);if(void 0!==i){const t=/^\s*$/.test(i)&&!i.includes("\n"),r=u[e-1],o=u[e+1];if(t){const t=u[e+2];if(o&&"JSXText"===o.type&&s(o)&&t&&("JSXElement"===t.type||"JSXFragment"===t.type)){const t=u[e-1],n=u[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue;const i=!o||"JSXText"===o.type&&!s(o);if(r&&"JSXText"===r.type&&i){const e=n[n.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+a.expression.value;continue}}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue}}n.push(a);continue}if("JSXElement"===a.type){const e=a.opening&&a.opening.name&&"Identifier"===a.opening.name.type?a.opening.name.value:void 0;if(e&&i.has(e)){const o=a.opening&&Array.isArray(a.opening.attributes)&&a.opening.attributes.length>0,c=a.children||[],f=1===c.length&&("JSXText"===c[0]?.type||"JSXExpressionContainer"===c[0]?.type&&void 0!==t(c[0].expression)),y=!c.length,d=f;if(o&&!f)n.push(a),r(a.children||[],n,!0);else if(y)n.push(a);else if(!d){if((a.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===t(e.expression)))n.push(a),r(a.children||[],n,!0);else if("p"===e){const e=(c||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,s=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));return!(n&&i.has(n)&&!s&&(0===r.length||o))}),o=p&&u.some(e=>e&&e!==a&&"JSXText"===e.type&&!s(e));l||p&&e&&!o?(n.push(a),r(a.children||[],n,!0,!1)):r(a.children||[],n,!1,!1)}else r(a.children||[],n,!1,!1)}continue}n.push(a),r(a.children||[],n,!0);continue}"JSXFragment"!==a.type||r(a.children||[],n,o)}else{if(o&&!f)continue;if(o&&s(a))continue;if(s(a)){const t=u[e-1],i=u[e+1];if(t&&("JSXElement"===t.type||"JSXFragment"===t.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=n[n.length-1],r=u[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+a.value;continue}}}if(o&&f&&0===e)continue;n.push(a)}}}const o=[];function p(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==o.indexOf(n))return t;if("JSXText"===n.type&&-1!==o.indexOf(n)){if(s(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}r(e,o,!1,!0);const l=new Set,a=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function c(e,n,r=!1){if(!e||0===e.length)return"";let u="";const f=e=>{if(!e)return-1;if(n&&n.has(e))return n.get(e);if(n)for(const[t,i]of n.entries())try{if(t&&e&&t.span&&e.span&&t.span.start===e.span.start&&t.span.end===e.span.end)return i}catch(e){}return o.indexOf(e)},y=t=>{if(!r)return o.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?s(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let n=0;n<e.length;n++){const d=e[n];if(d){if("JSXText"===d.type){if(s(d))continue;const t=e[n+1],r=e[n-1];if(r&&"JSXElement"===r.type){const t="Identifier"===r.opening?.name?.type?r.opening.name.value:void 0,s=t&&i.has(t),o=0===(r.children||[]).length;if(s&&o&&/^\s*\n\s*/.test(d.value)){const e=d.value.replace(/^\s*\n\s*/,"");if(e){u+=e;continue}continue}if(!s&&/^\s*\n\s*/.test(d.value)){const t=d.value.replace(/^\s*\n\s*/,"");if(t){if(r&&"JSXElement"===r.type&&Array.isArray(r.children)&&0===r.children.length){u+=t;continue}const i=e[n-2];if(i&&"JSXText"===i.type){const e=i.value.replace(/\n\s*$/,""),n=/[A-Za-z0-9]$/.test(e),s=/^[A-Za-z0-9]/.test(t),r=/^[a-z]/.test(t);if(n&&s&&r){u+=t;continue}}u+=" "+t;continue}continue}}if(/\n\s*$/.test(d.value)&&t&&"JSXElement"===t.type){const r=d.value.replace(/\n\s*$/,"");if(r.trim()){const o="Identifier"===t.opening?.name?.type?t.opening.name.value:void 0,p=o&&i.has(o),a=(t.children||[]).length>0,c=/\s\n/.test(d.value),f=e[n+2],y=f&&"JSXText"===f.type&&!s(f)&&/[a-zA-Z0-9]/.test(f.value),g=!!(t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0),x=/^\s/.test(r)&&!/^\n/.test(r),h=r.trim(),S=x?" "+h:h,v=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),$=g&&a&&y&&!(v&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;v&&m&&J&&!c&&!x&&!X&&l.add(t),u+=c||p&&a||!p&&y&&x||b?S+" ":S;continue}}u+=d.value;continue}if("JSXExpressionContainer"===d.type){const e=d.expression;if(!e)continue;const n=t(e);if(void 0!==n)u+=n;else if("Identifier"===e.type)u+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)u+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)u+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)u+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)u+=`{{${e.callee.value}}}`;else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===d.type){const l=r?y(d):void 0;let g;if(d.opening&&d.opening.name&&"Identifier"===d.opening.name.type&&(g=d.opening.name.value),g&&i.has(g)){const y=d.opening&&Array.isArray(d.opening.attributes)&&d.opening.attributes.length>0,x=d.children||[],h=x.length>0,S=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==t(x[0].expression)),v="p"===g;let m=0;if(v&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||S){const t=S?c(x,void 0):"";if(""!==String(t).trim())if(i.has(g)&&"p"!==g)u+=`<${g}>${a(t)}</${g}>`;else if(v&&r&&m>1)u+=`<${g}>${a(t)}</${g}>`;else if(v){const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(t)}</${e}>`}else{const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(t)}</${e}>`}else{const t=e[n-1];t&&"JSXText"===t.type&&/\n\s*$/.test(t.value)&&(u=u.replace(/\s+$/,"")),u+=`<${g} />`}}else if(y&&!S){const e=x,n=r&&void 0!==l?l:f(d);if(p(e)){const s=new Map;let r=0;for(const n of e)if(n&&"JSXElement"===n.type){const e=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(e&&i.has(e)){const e=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,i=n.children||[],o=1===i.length&&("JSXText"===i[0]?.type||"JSXExpressionContainer"===i[0]?.type&&void 0!==t(i[0].expression));!e&&(!i.length||o)||s.set(n,r++)}else s.set(n,r++)}const o=c(e,s.size?s:void 0);u+=`<${n}>${a(o)}</${n}>`}else{const e=new Map;let s=0;for(const n of x)if(n&&"JSXElement"===n.type){const r=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(r&&i.has(r)){const i=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,r=n.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==t(r[0].expression));!i&&(!r.length||o)||e.set(n,s++)}else e.set(n,s++)}const r=c(x,e.size?e:void 0);u+=`<${n}>${a(r)}</${n}>`}}else{const e=o.indexOf(d);if(-1!==e){const n=void 0!==l?l:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==o.indexOf(t))return e;if("JSXText"===t.type&&-1!==o.indexOf(t)){if(s(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===n){const e=c(x,void 0,!1);u+=`<${n}>${a(e)}</${n}>`;continue}const e=new Map;for(const e of x)if(e&&"JSXElement"===e.type){const s=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(s&&i.has(s)){const i=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,s=e.children||[],r=1===s.length&&("JSXText"===s[0]?.type||"JSXExpressionContainer"===s[0]?.type&&void 0!==t(s[0].expression));if(!(!i&&(!s.length||r))){const t=c(e.children,void 0,!1);u+=`<${n}>${a(t)}</${n}>`}}else{const t=c(e.children,void 0,!1);u+=`<${n}>${a(t)}</${n}>`}}const s=c(x,e.size?e:void 0,!1);u+=`<${n}>${a(s)}</${n}>`;continue}const r=new Map;let p=0;for(const e of x)if(e&&"JSXElement"===e.type){const n=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(n&&i.has(n)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,i=e.children||[],s=1===i.length&&("JSXText"===i[0]?.type||"JSXExpressionContainer"===i[0]?.type&&void 0!==t(i[0].expression));!n&&(!i.length||s)||r.set(e,p++)}else r.set(e,p++)}const f=c(x,r.size>0?r:void 0,!1);u+=`<${n}>${a(f)}</${n}>`}else{const e=c(x,void 0,!1);u+=`<${g}>${a(e)}</${g}>`}}}else{const e=d.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(d),n=c(e,void 0);u+=`<${t}>${a(n)}</${t}>`}else{const t=new Map,n=f(d);let s=0;for(const n of e)if(n&&"JSXElement"===n.type){const e=n.opening&&n.opening.name&&"Identifier"===n.opening.name.type?n.opening.name.value:void 0;if(e&&i.has(e)){const e=n.opening&&Array.isArray(n.opening.attributes)&&n.opening.attributes.length>0,i=n.children||[],r=1===i.length&&"JSXText"===i[0]?.type;!e&&(!i.length||r)||t.set(n,s++)}else t.set(n,s++)}const r=c(e,t.size?t:void 0);u+=`<${n}>${a(r)}</${n}>`}}continue}"JSXFragment"!==d.type||(u+=c(d.children||[]))}}return u}const u=c(e,void 0,!0),f=String(u).replace(/<br \/>\s*\n\s*/g,"<br />"),y=String(f),d=new Set;if(l&&l.size>0)for(let e=0;e<o.length;e++)l.has(o[e])&&d.add(e);let g=String(y);if(d&&d.size>0)for(const e of d)try{g=g.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),g=g.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}g=g.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return d.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),g=g.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return d.has(i)?`${t}<${n}`:`${t} <${n}`}),g=g.replace(/\s*\n\s*/g," "),g=g.replace(/\s+/g," "),g=g.replace(/\s+([,;:!?.])/g,"$1");const x=g.trim();let h=String(x);if(d&&d.size>0)for(const e of d)try{h=h.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),h=h.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<o.length;e++){const t=o[e];if(!t||"JSXElement"!==t.type)continue;const n=o[e-1],i=o[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),p=s.replace(/\n\s*$/,""),l=/[A-Za-z0-9]$/.test(p),a=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(l&&a&&c&&!u&&!f){const t=e;h=h.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function S(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function n(e,t=null){let r="";for(const p of e)if("text"===p.type)r+=p.text;else{const e=p.children.filter(e=>"ph"===e.type);let l;if("number"==typeof p.idx){const t=o[p.idx];if(t&&Array.isArray(t.children)){const n=new Map;let i=0;for(const e of t.children){const t=o.indexOf(e);if("JSXText"===e.type){if(s(e))continue;-1!==t&&n.set(t,i),i++}else"JSXElement"===e.type?(-1!==t&&n.set(t,i),i++):"JSXExpressionContainer"===e.type&&-1!==t&&(n.set(t,i),i++)}e.every(e=>n.has(e.idx))&&(l=n)}}if(!l){const n=e.map(e=>e.idx);if(n.length<=1||n.every((e,t)=>0===t||e===n[t-1]+1)){l=new Map;let n=0;try{const s=o[p.idx];if(s&&s.span){const r=s.span.start,l=s.span.end;let a=0,c=-1;for(let e=p.idx+1;e<o.length;e++){const t=o[e];if(t&&t.span&&(t.span.start>=r&&t.span.end<=l&&"JSXElement"===t.type)){c=e;break}}if(-1!==c)for(let e=p.idx+1;e<c;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}else for(let e=p.idx+1;e<o.length;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}const u=s?.opening?.name?.value,f=u&&i.has(u),y=null===t;1===e.length&&(n=Math.max(1,a+1),!y||f||0!==e[0].idx||"a"!==u&&"p"!==u||(n=0))}}catch(e){}for(const t of e)l.has(t.idx)||l.set(t.idx,n++)}}const a=p.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,i=l&&l.has(t)?l.get(t):t;return`<${i}>${n(e.children,i)}</${i}>`}).join("");r+=`<${p.idx}>${a}</${p.idx}>`}return r}try{const i=t(e);return n(i)}catch(t){return e}}return h=S(h),h.trim()}(i.children,s);let m;const J="JSXAttribute"===o?.type?n(o):void 0;if(void 0!==J)m=J;else{const e=s.extract.defaultValue;m="string"==typeof e?e:""}let X,$;if("JSXAttribute"===r?.type){if("StringLiteral"===r.value?.type){if(X=r.value,$=X.value,!$||""===$.trim())return null;if(S&&"StringLiteral"===X.type){const e=s.extract.nsSeparator??":",t=X.value;if(e&&t.startsWith(`${S}${e}`)){if($=t.slice(`${S}${e}`.length),!$||""===$.trim())return null;X={...X,value:$}}}}else"JSXExpressionContainer"===r.value?.type&&"JSXEmptyExpression"!==r.value.expression.type&&(X=r.value.expression);if(!X)return null}return o||!$||v.trim()?!o&&v.trim()&&(m=v):m=$,{keyExpression:X,serializedChildren:v,ns:S,defaultValue:m,hasCount:c,isOrdinal:d,contextExpression:x,optionsNode:f,explicitDefault:void 0!==J||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(f)}};
package/dist/cjs/init.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("inquirer"),e=require("node:fs/promises"),n=require("node:path"),i=require("./heuristic-config.js");exports.runInit=async function(){console.log("Welcome to the i18next-cli setup wizard!"),console.log("Scanning your project for a recommended configuration...");const o=await i.detectConfig();o?console.log("✅ Found a potential project structure. Using it for suggestions."):console.log("Could not detect a project structure. Using standard defaults."),"string"==typeof o?.extract?.input&&(o.extract.input=[o?.extract?.input]),o&&"function"==typeof o.extract?.output&&delete o.extract.output;const r=await t.prompt([{type:"list",name:"fileType",message:"What kind of configuration file do you want?",choices:["TypeScript (i18next.config.ts)","JavaScript (i18next.config.js)"]},{type:"input",name:"locales",message:"What locales does your project support? (comma-separated)",default:o?.locales?.join(",")||"en,de,fr",filter:t=>t.split(",").map(t=>t.trim())},{type:"input",name:"input",message:"What is the glob pattern for your source files?",default:o?.extract?.input?(o.extract.input||[])[0]:"src/**/*.{js,jsx,ts,tsx}"},{type:"input",name:"output",message:"What is the path for your output resource files?",default:"string"==typeof o?.extract?.output?o.extract.output:"public/locales/{{language}}/{{namespace}}.json"}]),s=r.fileType.includes("TypeScript"),a=await async function(){try{const t=n.resolve(process.cwd(),"package.json"),i=await e.readFile(t,"utf-8");return"module"===JSON.parse(i).type}catch{return!0}}(),c=s?"i18next.config.ts":"i18next.config.js",u={locales:r.locales,extract:{input:r.input,output:r.output}};function p(t,e=2,n=0){const i=t=>" ".repeat(t*e),o=i(n),r=i(n+1);if(null===t||"number"==typeof t||"boolean"==typeof t)return JSON.stringify(t);if("string"==typeof t)return JSON.stringify(t);if(Array.isArray(t)){if(0===t.length)return"[]";return`[\n${t.map(t=>`${r}${p(t,e,n+1)}`).join(",\n")}\n${o}]`}if("object"==typeof t){const i=Object.keys(t);if(0===i.length)return"{}";return`{\n${i.map(i=>{const o=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(i)?i:JSON.stringify(i);return`${r}${o}: ${p(t[i],e,n+1)}`}).join(",\n")}\n${o}}`}return JSON.stringify(t)}let f="";f=s?`import { defineConfig } from 'i18next-cli';\n\nexport default defineConfig(${p(u)});`:a?`import { defineConfig } from 'i18next-cli';\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nexport default defineConfig(${p(u)});`:`const { defineConfig } = require('i18next-cli');\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nmodule.exports = defineConfig(${p(u)});`;const l=n.resolve(process.cwd(),c);await e.writeFile(l,f.trim()),console.log(`✅ Configuration file created at: ${l}`)};
1
+ "use strict";var t=require("inquirer"),e=require("node:fs/promises"),n=require("node:path"),i=require("./heuristic-config.js");exports.runInit=async function(){console.log("Welcome to the i18next-cli setup wizard!"),console.log("Scanning your project for a recommended configuration...");const o=await i.detectConfig();o?console.log("✅ Found a potential project structure. Using it for suggestions."):console.log("Could not detect a project structure. Using standard defaults."),"string"==typeof o?.extract?.input&&(o.extract.input=[o?.extract?.input]),o&&"function"==typeof o.extract?.output&&delete o.extract.output;const r=await t.prompt([{type:"select",name:"fileType",message:"What kind of configuration file do you want?",choices:["TypeScript (i18next.config.ts)","JavaScript (i18next.config.js)"]},{type:"input",name:"locales",message:"What locales does your project support? (comma-separated)",default:o?.locales?.join(",")||"en,de,fr",filter:t=>t.split(",").map(t=>t.trim())},{type:"input",name:"input",message:"What is the glob pattern for your source files?",default:o?.extract?.input?(o.extract.input||[])[0]:"src/**/*.{js,jsx,ts,tsx}"},{type:"input",name:"output",message:"What is the path for your output resource files?",default:"string"==typeof o?.extract?.output?o.extract.output:"public/locales/{{language}}/{{namespace}}.json"}]),s=r.fileType.includes("TypeScript"),a=await async function(){try{const t=n.resolve(process.cwd(),"package.json"),i=await e.readFile(t,"utf-8");return"module"===JSON.parse(i).type}catch{return!0}}(),c=s?"i18next.config.ts":"i18next.config.js",u={locales:r.locales,extract:{input:r.input,output:r.output}};function p(t,e=2,n=0){const i=t=>" ".repeat(t*e),o=i(n),r=i(n+1);if(null===t||"number"==typeof t||"boolean"==typeof t)return JSON.stringify(t);if("string"==typeof t)return JSON.stringify(t);if(Array.isArray(t)){if(0===t.length)return"[]";return`[\n${t.map(t=>`${r}${p(t,e,n+1)}`).join(",\n")}\n${o}]`}if("object"==typeof t){const i=Object.keys(t);if(0===i.length)return"{}";return`{\n${i.map(i=>{const o=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(i)?i:JSON.stringify(i);return`${r}${o}: ${p(t[i],e,n+1)}`}).join(",\n")}\n${o}}`}return JSON.stringify(t)}let f="";f=s?`import { defineConfig } from 'i18next-cli';\n\nexport default defineConfig(${p(u)});`:a?`import { defineConfig } from 'i18next-cli';\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nexport default defineConfig(${p(u)});`:`const { defineConfig } = require('i18next-cli');\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nmodule.exports = defineConfig(${p(u)});`;const l=n.resolve(process.cwd(),c);await e.writeFile(l,f.trim()),console.log(`✅ Configuration file created at: ${l}`)};
@@ -1 +1 @@
1
- "use strict";var e=require("execa"),o=require("chalk"),n=require("ora"),t=require("inquirer"),r=require("node:path");function s(e,o,n){const{locize:t={},extract:s}=o,{projectId:i,apiKey:c,version:a}=t,l=[e];if(i&&l.push("--project-id",i),c&&l.push("--api-key",c),a&&l.push("--ver",a),"sync"===e){(n.updateValues??t.updateValues)&&l.push("--update-values","true");(n.srcLngOnly??t.sourceLanguageOnly)&&l.push("--reference-language-only","true");(n.compareMtime??t.compareModificationTime)&&l.push("--compare-modification-time","true");(n.dryRun??t.dryRun)&&l.push("--dry","true")}let u;try{if("string"==typeof s.output){const e=s.output.replace(/\\/g,"/"),o=(e.includes("/{{language}}/")?e.split("/{{language}}/")[0]:e.replace("{{language}}","")).split("/").join(r.sep);u=r.resolve(process.cwd(),o)}else if("function"==typeof s.output)try{const e=s.output(o.extract.primaryLanguage||"en"),n=String(e).replace(/\\/g,"/"),t=n.includes("/"+(o.extract.primaryLanguage||"en")+"/")?n.split("/"+(o.extract.primaryLanguage||"en")+"/")[0]:n.replace(o.extract.primaryLanguage||"en","");u=r.resolve(process.cwd(),t.split("/").join(r.sep))}catch{u=r.resolve(process.cwd(),".")}else u=r.resolve(process.cwd(),".")}catch{u=r.resolve(process.cwd(),".")}return l.push("--path",u),l}async function i(r,i,c={}){await async function(){try{await e.execa("locize",["--version"])}catch(e){"ENOENT"===e.code&&(console.error(o.red("Error: `locize-cli` command not found.")),console.log(o.yellow("Please install it globally to use the locize integration:")),console.log(o.cyan("npm install -g locize-cli")),process.exit(1))}}();const a=n(`Running 'locize ${r}'...\n`).start();let l=i;try{const n=s(r,l,c);console.log(o.cyan(`\nRunning 'locize ${n.join(" ")}'...`));const t=await e.execa("locize",n,{stdio:"pipe"});a.succeed(o.green(`'locize ${r}' completed successfully.`)),t?.stdout&&console.log(t.stdout)}catch(n){const i=n.stderr||"";if(i.includes("missing required argument")){const n=await async function(){console.log(o.yellow("\nLocize configuration is missing or invalid. Let's set it up!"));const e=await t.prompt([{type:"input",name:"projectId",message:"What is your locize Project ID? (Find this in your project settings on www.locize.app)",validate:e=>!!e||"Project ID cannot be empty."},{type:"password",name:"apiKey",message:'What is your locize API key? (Create or use one in your project settings > "API Keys")',validate:e=>!!e||"API Key cannot be empty."},{type:"input",name:"version",message:"What version do you want to sync with?",default:"latest"}]);if(!e.projectId)return void console.error(o.red("Project ID is required to continue."));const{save:n}=await t.prompt([{type:"confirm",name:"save",message:"Would you like to see how to save these credentials for future use?",default:!0}]);if(n){const n=`\n# Add this to your .env file (and ensure .env is in your .gitignore!)\nLOCIZE_API_KEY=${e.apiKey}\n`,t=`\n // Add this to your i18next.config.ts file\n locize: {\n projectId: '${e.projectId}',\n // For security, apiKey is best set via an environment variable\n apiKey: process.env.LOCIZE_API_KEY,\n version: '${e.version}',\n },`;console.log(o.cyan("\nGreat! For the best security, we recommend using environment variables for your API key.")),console.log(o.bold("\nRecommended approach (.env file):")),console.log(o.green(n)),console.log(o.bold("Then, in your i18next.config.ts:")),console.log(o.green(t))}return{projectId:e.projectId,apiKey:e.apiKey,version:e.version}}();if(n){l={...l,locize:n},a.start("Retrying with new credentials...");try{const n=s(r,l,c);console.log(o.cyan(`\nRunning 'locize ${n.join(" ")}'...`));const t=await e.execa("locize",n,{stdio:"pipe"});a.succeed(o.green("Retry successful!")),t?.stdout&&console.log(t.stdout)}catch(e){a.fail(o.red("Error during retry.")),console.error(e.stderr||e.message),process.exit(1)}}else a.fail("Operation cancelled."),process.exit(1)}else a.fail(o.red(`Error executing 'locize ${r}'.`)),console.error(i||n.message),process.exit(1)}console.log(o.green(`\n✅ 'locize ${r}' completed successfully.`))}exports.runLocizeDownload=(e,o)=>i("download",e,o),exports.runLocizeMigrate=(e,o)=>i("migrate",e,o),exports.runLocizeSync=(e,o)=>i("sync",e,o);
1
+ "use strict";var e=require("execa"),o=require("chalk"),n=require("ora"),t=require("inquirer"),r=require("node:path");function s(e,o,n){const{locize:t={},extract:s}=o,{projectId:i,apiKey:c,version:a}=t,l=[e];if(i&&l.push("--project-id",i),c&&l.push("--api-key",c),a&&l.push("--ver",a),"sync"===e){(n.updateValues??t.updateValues)&&l.push("--update-values","true");(n.srcLngOnly??t.sourceLanguageOnly)&&l.push("--reference-language-only","true");(n.compareMtime??t.compareModificationTime)&&l.push("--compare-modification-time","true");const e=n.cdnType??t.cdnType;e&&l.push("--cdn-type",e);(n.dryRun??t.dryRun)&&l.push("--dry","true")}let u;try{if("string"==typeof s.output){const e=s.output.replace(/\\/g,"/"),o=(e.includes("/{{language}}/")?e.split("/{{language}}/")[0]:e.replace("{{language}}","")).split("/").join(r.sep);u=r.resolve(process.cwd(),o)}else if("function"==typeof s.output)try{const e=s.output(o.extract.primaryLanguage||"en"),n=String(e).replace(/\\/g,"/"),t=n.includes("/"+(o.extract.primaryLanguage||"en")+"/")?n.split("/"+(o.extract.primaryLanguage||"en")+"/")[0]:n.replace(o.extract.primaryLanguage||"en","");u=r.resolve(process.cwd(),t.split("/").join(r.sep))}catch{u=r.resolve(process.cwd(),".")}else u=r.resolve(process.cwd(),".")}catch{u=r.resolve(process.cwd(),".")}return l.push("--path",u),l}async function i(r,i,c={}){await async function(){try{await e.execa("locize",["--version"])}catch(e){"ENOENT"===e.code&&(console.error(o.red("Error: `locize-cli` command not found.")),console.log(o.yellow("Please install it globally to use the locize integration:")),console.log(o.cyan("npm install -g locize-cli")),process.exit(1))}}();const a=n(`Running 'locize ${r}'...\n`).start();let l=i;try{const n=s(r,l,c);console.log(o.cyan(`\nRunning 'locize ${n.join(" ")}'...`));const t=await e.execa("locize",n,{stdio:"pipe"});a.succeed(o.green(`'locize ${r}' completed successfully.`)),t?.stdout&&console.log(t.stdout)}catch(n){const i=n.stderr||"";if(i.includes("missing required argument")){const n=await async function(){console.log(o.yellow("\nLocize configuration is missing or invalid. Let's set it up!"));const e=await t.prompt([{type:"input",name:"projectId",message:"What is your locize Project ID? (Find this in your project settings on www.locize.app)",validate:e=>!!e||"Project ID cannot be empty."},{type:"password",name:"apiKey",message:'What is your locize API key? (Create or use one in your project settings > "API Keys")',validate:e=>!!e||"API Key cannot be empty."},{type:"input",name:"version",message:"What version do you want to sync with?",default:"latest"}]);if(!e.projectId)return void console.error(o.red("Project ID is required to continue."));const{save:n}=await t.prompt([{type:"confirm",name:"save",message:"Would you like to see how to save these credentials for future use?",default:!0}]);if(n){const n=`\n# Add this to your .env file (and ensure .env is in your .gitignore!)\nLOCIZE_API_KEY=${e.apiKey}\n`,t=`\n // Add this to your i18next.config.ts file\n locize: {\n projectId: '${e.projectId}',\n // For security, apiKey is best set via an environment variable\n apiKey: process.env.LOCIZE_API_KEY,\n version: '${e.version}',\n },`;console.log(o.cyan("\nGreat! For the best security, we recommend using environment variables for your API key.")),console.log(o.bold("\nRecommended approach (.env file):")),console.log(o.green(n)),console.log(o.bold("Then, in your i18next.config.ts:")),console.log(o.green(t))}return{projectId:e.projectId,apiKey:e.apiKey,version:e.version}}();if(n){l={...l,locize:n},a.start("Retrying with new credentials...");try{const n=s(r,l,c);console.log(o.cyan(`\nRunning 'locize ${n.join(" ")}'...`));const t=await e.execa("locize",n,{stdio:"pipe"});a.succeed(o.green("Retry successful!")),t?.stdout&&console.log(t.stdout)}catch(e){a.fail(o.red("Error during retry.")),console.error(e.stderr||e.message),process.exit(1)}}else a.fail("Operation cancelled."),process.exit(1)}else a.fail(o.red(`Error executing 'locize ${r}'.`)),console.error(i||n.message),process.exit(1)}console.log(o.green(`\n✅ 'locize ${r}' completed successfully.`))}exports.runLocizeDownload=(e,o)=>i("download",e,o),exports.runLocizeMigrate=(e,o)=>i("migrate",e,o),exports.runLocizeSync=(e,o)=>i("sync",e,o);
package/dist/esm/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{Command as o}from"commander";import e from"chokidar";import{glob as t}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import"@croct/json5-parser";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as f}from"./migrator.js";import{runInit as m}from"./init.js";import{runLinterCli as d}from"./linter.js";import{runStatus as g}from"./status.js";import{runLocizeSync as u,runLocizeDownload as y,runLocizeMigrate as h}from"./locize.js";import{runRenameKey as w}from"./rename-key.js";const x=new o;x.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.31.0"),x.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),x.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").option("--sync-all","Sync primary language values with default values from code AND clear synced keys in all other locales.").action(async o=>{try{const t=x.opts().config,i=await a(t),r=async()=>{const e=!!o.syncPrimary||!!o.syncAll,t=await s(i,{isWatchMode:!!o.watch,isDryRun:!!o.dryRun,syncPrimaryWithDefaults:e,syncAll:!!o.syncAll});return o.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):o.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await r(),o.watch){console.log("\nWatching for changes...");const o=await v(i.extract.input),t=j(i.extract.ignore),a=k(i.extract.output),c=[...t,...a].filter(Boolean),s=o.filter(o=>!c.some(e=>n(o,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}catch(o){console.error("Error running extractor:",o),process.exit(1)}}),x.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(o,e)=>{const t=x.opts().config;let n=await r(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=o}await g(n,{detail:o,namespace:e.namespace})}),x.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async o=>{const t=x.opts().config,i=await a(t),r=()=>l(i);if(await r(),o.watch){console.log("\nWatching for changes...");const o=await v(i.types?.input||[]),t=[...j(i.extract?.ignore)].filter(Boolean),a=o.filter(o=>!t.some(e=>n(o,e,{dot:!0})));e.watch(a,{persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}),x.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const o=x.opts().config,e=await a(o);await p(e)}),x.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async o=>{await f(o)}),x.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(m),x.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async o=>{const t=x.opts().config,a=async()=>{let o=await r(t);if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await c();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),o=e}await d(o)};if(await a(),o.watch){console.log("\nWatching for changes...");const o=await r(t);if(o?.extract?.input){const t=await v(o.extract.input),i=[...j(o.extract.ignore),...k(o.extract.output)].filter(Boolean),r=t.filter(o=>!i.some(e=>n(o,e,{dot:!0})));e.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}}),x.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async o=>{const e=x.opts().config,t=await a(e);await u(t,o)}),x.command("locize-download").description("Download all translations from your locize project.").action(async o=>{const e=x.opts().config,t=await a(e);await y(t,o)}),x.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async o=>{const e=x.opts().config,t=await a(e);await h(t,o)}),x.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(o,e,t)=>{try{const n=x.opts().config,r=await a(n),c=await w(r,o,e,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(o=>console.error(` - ${o}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((o,e)=>o+e.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${o}"`))}catch(o){console.error(i.red("Error renaming key:"),o),process.exit(1)}}),x.parse(process.argv);const j=o=>Array.isArray(o)?o:o?[o]:[],k=o=>o&&"string"==typeof o?[o.replace(/\{\{[^}]+\}\}/g,"*")]:[],v=async(o=[])=>{const e=j(o),n=await Promise.all(e.map(o=>t(o||"",{nodir:!0})));return Array.from(new Set(n.flat()))};export{x as program};
2
+ import{Command as o}from"commander";import e from"chokidar";import{glob as t}from"glob";import{minimatch as n}from"minimatch";import i from"chalk";import{ensureConfig as r,loadConfig as a}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"@croct/json5-parser";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as d}from"./migrator.js";import{runInit as f}from"./init.js";import{runLinterCli as m}from"./linter.js";import{runStatus as u}from"./status.js";import{runLocizeSync as y,runLocizeDownload as g,runLocizeMigrate as h}from"./locize.js";import{runRenameKey as w}from"./rename-key.js";const x=new o;x.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.33.0"),x.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),x.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").option("--sync-all","Sync primary language values with default values from code AND clear synced keys in all other locales.").action(async o=>{try{const t=x.opts().config,i=await r(t),a=async()=>{const e=!!o.syncPrimary||!!o.syncAll,t=await s(i,{isWatchMode:!!o.watch,isDryRun:!!o.dryRun,syncPrimaryWithDefaults:e,syncAll:!!o.syncAll});return o.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):o.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await a(),o.watch){console.log("\nWatching for changes...");const o=await z(i.extract.input),t=j(i.extract.ignore),r=v(i.extract.output),c=[...t,...r].filter(Boolean),s=o.filter(o=>!c.some(e=>n(o,e,{dot:!0})));e.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}catch(o){console.error("Error running extractor:",o),process.exit(1)}}),x.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(o,e)=>{const t=x.opts().config;let n=await a(t);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=o}await u(n,{detail:o,namespace:e.namespace})}),x.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async o=>{const t=x.opts().config,i=await r(t),a=()=>l(i);if(await a(),o.watch){console.log("\nWatching for changes...");const o=await z(i.types?.input||[]),t=[...j(i.extract?.ignore)].filter(Boolean),r=o.filter(o=>!t.some(e=>n(o,e,{dot:!0})));e.watch(r,{persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}),x.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const o=x.opts().config,e=await r(o);await p(e)}),x.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async o=>{await d(o)}),x.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(f),x.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async o=>{const t=x.opts().config,r=async()=>{let o=await a(t);if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await c();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),o=e}await m(o)};if(await r(),o.watch){console.log("\nWatching for changes...");const o=await a(t);if(o?.extract?.input){const t=await z(o.extract.input),i=[...j(o.extract.ignore),...v(o.extract.output)].filter(Boolean),a=t.filter(o=>!i.some(e=>n(o,e,{dot:!0})));e.watch(a,{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),r()})}}}),x.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async o=>{const e=x.opts().config,t=await r(e);await y(t,o)}),x.command("locize-download").description("Download all translations from your locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async o=>{const e=x.opts().config,t=await r(e);await g(t,o)}),x.command("locize-migrate").description("Migrate local translation files to a new locize project.").option("--cdn-type <standard|pro>","Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project)").action(async o=>{const e=x.opts().config,t=await r(e);await h(t,o)}),x.command("rename-key <oldKey> <newKey>").description("Rename a translation key across all source files and translation files.").option("--dry-run","Preview changes without modifying files").action(async(o,e,t)=>{try{const n=x.opts().config,a=await r(n),c=await w(a,o,e,t);c.success||(c.conflicts&&(console.error(i.red("\n❌ Conflicts detected:")),c.conflicts.forEach(o=>console.error(` - ${o}`))),c.error&&console.error(i.red(`\n❌ ${c.error}`)),process.exit(1));0===c.sourceFiles.reduce((o,e)=>o+e.changes,0)&&console.log(i.yellow(`\n⚠️ No usages found for "${o}"`))}catch(o){console.error(i.red("Error renaming key:"),o),process.exit(1)}}),x.parse(process.argv);const j=o=>Array.isArray(o)?o:o?[o]:[],v=o=>o&&"string"==typeof o?[o.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(o=[])=>{const e=j(o),n=await Promise.all(e.map(o=>t(o||"",{nodir:!0})));return Array.from(new Set(n.flat()))};export{x as program};
@@ -1 +1 @@
1
- import{isSimpleTemplateLiteral as e,getObjectPropValue as t,getObjectPropValueExpression as r}from"./ast-utils.js";class n{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,r,n,i,s){this.config=e,this.pluginContext=t,this.logger=r,this.expressionResolver=n,this.getCurrentFile=i,this.getCurrentCode=s}resetSearchIndex(){this.lastSearchIndex=0}getLocationFromNode(e){const t=this.getCurrentCode();let r;if("CallExpression"===e.type&&e.arguments.length>0){const t=e.arguments[0].expression;"StringLiteral"===t.type?r=t.raw??`'${t.value}'`:"TemplateLiteral"===t.type&&(r="`")}if(!r)return;const n=t.indexOf(r,this.lastSearchIndex);if(-1===n)return;this.lastSearchIndex=n+r.length;const i=t.substring(0,n).split("\n");return{line:i.length,column:i[i.length-1].length}}handleCallExpression(n,i){const s=this.getFunctionName(n.callee);if(!s)return;const o=i(s),l=this.config.extract.functions||["t","*.t"];let a=void 0!==o;if(!a)for(const e of l)if(e.startsWith("*.")){if(s.endsWith(e.substring(1))){a=!0;break}}else if(e===s){a=!0;break}if(!a||0===n.arguments.length)return;const{keysToProcess:u,isSelectorAPI:f}=this.handleCallExpressionArgument(n,0);if(0===u.length)return;let c=!1;const p=this.config.extract.pluralSeparator??"_";for(let e=0;e<u.length;e++)u[e].endsWith(`${p}ordinal`)&&(c=!0,u[e]=u[e].slice(0,-8));let y,g;if(n.arguments.length>1){const t=n.arguments[1].expression;"ObjectExpression"===t.type?g=t:"StringLiteral"===t.type?y=t.value:"TemplateLiteral"===t.type&&e(t)&&(y=t.quasis[0].cooked)}if(n.arguments.length>2){const e=n.arguments[2].expression;"ObjectExpression"===e.type&&(g=e)}const h=g?t(g,"defaultValue"):void 0,d="string"==typeof h?h:y,x=e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1},k="string"==typeof d||x(g),$=x(g),m=Boolean($||"string"==typeof d&&!("string"==typeof(v=d)&&/{{\s*count\s*}}/.test(v)));var v;for(let e=0;e<u.length;e++){const i=u[e];let s,l=u[e];if(g){const e=t(g,"ns");"string"==typeof e&&(s=e)}const a=this.config.extract.nsSeparator??":";if(!s&&a&&l.includes(a)){const e=l.split(a);if(s=e.shift(),l=e.join(a),!l||""===l.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${s}${a}'`);continue}}!s&&o?.defaultNs&&(s=o.defaultNs),s||(s=this.config.extract.defaultNS);let p=l;if(o?.keyPrefix){const e=this.config.extract.keySeparator??".";if(p=!1!==e?o.keyPrefix.endsWith(e)?`${o.keyPrefix}${l}`:`${o.keyPrefix}${e}${l}`:`${o.keyPrefix}${l}`,!1!==e){if(p.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${p}' (keyPrefix: '${o.keyPrefix}', key: '${l}')`);continue}}}const y=e===u.length-1?"string"==typeof d?d:a&&i.includes(a||":")?i:l:l;if(g){const e=r(g,"context"),n=[];if("StringLiteral"===e?.type||"NumericLiteral"===e?.type||"BooleanLiteral"===e?.type){const t=`${e.value}`,r=this.config.extract.contextSeparator??"_";""!==t&&n.push({key:`${p}${r}${t}`,ns:s,defaultValue:y,explicitDefault:k})}else if(e){const t=this.expressionResolver.resolvePossibleContextStringValues(e),r=this.config.extract.contextSeparator??"_";t.length>0&&t.forEach(e=>{n.push({key:`${p}${r}${e}`,ns:s,defaultValue:y,explicitDefault:k})}),n.push({key:p,ns:s,defaultValue:y,explicitDefault:k,keyAcceptingContext:p})}const i=e=>{if(e){if("KeyValueProperty"===e.type&&e.key){if("Identifier"===e.key.type)return e.key.value;if("StringLiteral"===e.key.type)return e.key.value}return"KeyValueProperty"===e.type&&e.value&&"Identifier"===e.value.type?e.key&&"Identifier"===e.key.type?e.key.value:void 0:"ShorthandProperty"!==e.type&&"Identifier"!==e.type||!e.value?e.key&&"string"==typeof e.key?e.key:void 0:e.value}},o=(()=>{if(!g||!Array.isArray(g.properties))return!1;for(const e of g.properties){if("count"===i(e))return!0}return!1})(),l=(()=>{if(!g||!Array.isArray(g.properties))return!1;for(const e of g.properties){if("ordinal"===i(e))return!("KeyValueProperty"!==e.type||!e.value||"BooleanLiteral"!==e.value.type)&&Boolean(e.value.value)}return!1})();if(o||c){try{const e=c?"ordinal":"cardinal",t=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let r=!1;try{const n=new Intl.PluralRules(t,{type:e}).resolvedOptions().pluralCategories;1===n.length&&"other"===n[0]&&(r=!0)}catch{}if(!r){const t=new Set;for(const r of this.config.locales)try{new Intl.PluralRules(r,{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}catch{new Intl.PluralRules("en",{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}const n=Array.from(t).sort();1===n.length&&"other"===n[0]&&(r=!0)}if(r){if(n.length>0)for(const e of n)this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,hasCount:!0,isOrdinal:c});else this.pluginContext.addKey({key:p,ns:s,defaultValue:y,hasCount:!0,isOrdinal:c});continue}}catch(e){}this.config.extract.disablePlurals?n.length>0?n.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:p,ns:s,defaultValue:y,explicitDefault:k}):this.handlePluralKeys(p,s,g,l||c,d,m);continue}if(n.length>0){n.forEach(this.pluginContext.addKey);continue}!0===t(g,"returnObjects")&&this.objectKeys.add(p)}f&&this.objectKeys.add(p);{const e=this.getLocationFromNode(n);this.pluginContext.addKey({key:p,ns:s,defaultValue:y,explicitDefault:k,locations:e?[{file:this.getCurrentFile(),line:e.line,column:e.column}]:void 0})}}}handleCallExpressionArgument(e,t){const r=e.arguments[t].expression,n=[];let i=!1;if("ArrowFunctionExpression"===r.type){const e=this.extractKeyFromSelector(r);e&&(n.push(e),i=!0)}else if("ArrayExpression"===r.type)for(const e of r.elements)e?.expression&&n.push(...this.expressionResolver.resolvePossibleKeyStringValues(e.expression));else n.push(...this.expressionResolver.resolvePossibleKeyStringValues(r));return{keysToProcess:n.filter(e=>!!e),isSelectorAPI:i}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let r=t;const n=[];for(;"MemberExpression"===r.type;){const e=r.property;if("Identifier"===e.type)n.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;n.unshift(e.expression.value)}r=r.object}if(n.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return n.join(t)}return null}handlePluralKeys(e,n,i,s,o,l){try{const a=s?"ordinal":"cardinal",u=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:a});t.resolvedOptions().pluralCategories.forEach(e=>u.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:a});t.resolvedOptions().pluralCategories.forEach(e=>u.add(e))}const f=Array.from(u).sort(),c=this.config.extract.pluralSeparator??"_",p=t(i,"defaultValue"),y=t(i,`defaultValue${c}other`),g=t(i,`defaultValue${c}ordinal${c}other`),h=r(i,"context"),d=[];if(h){const t=this.expressionResolver.resolvePossibleContextStringValues(h);if(t.length>0)if("StringLiteral"===h.type)for(const r of t)r.length>0&&d.push({key:e,context:r});else{for(const r of t)r.length>0&&d.push({key:e,context:r});!1!==this.config.extract?.generateBasePluralForms&&d.push({key:e})}else d.push({key:e})}else d.push({key:e});const x=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let k=!1;try{const e=new Intl.PluralRules(x,{type:a}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&(k=!0)}catch{k=!1}if(k||1===f.length&&"other"===f[0]){for(const{key:e,context:r}of d){const a=t(i,`defaultValue${c}other`);let u;u="string"==typeof a?a:"string"==typeof p?p:"string"==typeof o?o:r?`${e}_${r}`:e;const f=this.config.extract.contextSeparator??"_",y=r?`${e}${f}${r}`:e;this.pluginContext.addKey({key:y,ns:n,defaultValue:u,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(l||"string"==typeof a)})}return}for(const{key:r,context:a}of d)for(const u of f){const f=t(i,s?`defaultValue${c}ordinal${c}${u}`:`defaultValue${c}${u}`);let h,d;if(h="string"==typeof f?f:"one"===u&&"string"==typeof p?p:"one"===u&&"string"==typeof o?o:s&&"string"==typeof g?g:s||"string"!=typeof y?"string"==typeof p?p:"string"==typeof o?o:r:y,a){const e=this.config.extract.contextSeparator??"_";d=s?`${r}${e}${a}${c}ordinal${c}${u}`:`${r}${e}${a}${c}${u}`}else d=s?`${r}${c}ordinal${c}${u}`:`${r}${c}${u}`;this.pluginContext.addKey({key:d,ns:n,defaultValue:h,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(l||"string"==typeof f||"string"==typeof y),keyAcceptingContext:void 0!==a?e:void 0})}}catch(r){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const s=o||t(i,"defaultValue");this.pluginContext.addKey({key:e,ns:n,defaultValue:"string"==typeof s?s:e})}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let r=e;for(;"MemberExpression"===r.type;){if("Identifier"!==r.property.type)return null;t.unshift(r.property.value),r=r.object}if("ThisExpression"===r.type)t.unshift("this");else{if("Identifier"!==r.type)return null;t.unshift(r.value)}return t.join(".")}return null}}export{n as CallExpressionHandler};
1
+ import{isSimpleTemplateLiteral as e,getObjectPropValue as t,getObjectPropValueExpression as n}from"./ast-utils.js";const r=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");class s{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;lastSearchIndex=0;constructor(e,t,n,r,s,i){this.config=e,this.pluginContext=t,this.logger=n,this.expressionResolver=r,this.getCurrentFile=s,this.getCurrentCode=i}resetSearchIndex(){this.lastSearchIndex=0}getLocationFromNode(e){const t=this.getCurrentCode();let n;if("CallExpression"===e.type&&e.arguments.length>0){const t=e.arguments[0].expression;"StringLiteral"===t.type?n=t.raw??`'${t.value}'`:"TemplateLiteral"===t.type?n="`":"ArrowFunctionExpression"===t.type&&(n="=>")}if(!n)return;const r=t.indexOf(n,this.lastSearchIndex);if(-1===r)return;this.lastSearchIndex=r+n.length;const s=t.substring(0,r).split("\n");return{line:s.length,column:s[s.length-1].length}}handleCallExpression(s,i){const o=this.getFunctionName(s.callee);if(!o)return;const l=i(o),a=this.config.extract.functions||["t","*.t"];let c=void 0!==l;if(!c)for(const e of a)if(e.startsWith("*.")){if(o.endsWith(e.substring(1))){c=!0;break}}else if(e===o){c=!0;break}if(!c||0===s.arguments.length)return;const{keysToProcess:u,isSelectorAPI:f}=this.handleCallExpressionArgument(s,0);if(0===u.length)return;let p=!1;const y=this.config.extract.pluralSeparator??"_";for(let e=0;e<u.length;e++)u[e].endsWith(`${y}ordinal`)&&(p=!0,u[e]=u[e].slice(0,-8));let g,h;if(s.arguments.length>1){const t=s.arguments[1].expression;"ObjectExpression"===t.type?h=t:"StringLiteral"===t.type?g=t.value:"TemplateLiteral"===t.type&&e(t)&&(g=t.quasis[0].cooked)}if(s.arguments.length>2){const e=s.arguments[2].expression;"ObjectExpression"===e.type&&(h=e)}const d=h?t(h,"defaultValue"):void 0,x="string"==typeof d?d:g,$=e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1},k="string"==typeof x||$(h),m=$(h),v=Boolean(m||"string"==typeof x&&!(e=>{if("string"!=typeof e)return!1;const t=this.config.extract.interpolationPrefix??"{{",n=this.config.extract.interpolationSuffix??"}}";return new RegExp(`${r(t)}\\s*count\\s*${r(n)}`).test(e)})(x));for(let e=0;e<u.length;e++){const r=u[e];let i,o=u[e];if(h){const e=t(h,"ns");"string"==typeof e&&(i=e)}const a=this.config.extract.nsSeparator??":";if(!i&&a&&o.includes(a)){const e=o.split(a);if(i=e.shift(),o=e.join(a),!o||""===o.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${i}${a}'`);continue}}!i&&l?.defaultNs&&(i=l.defaultNs),i||(i=this.config.extract.defaultNS);let c=o;if(l?.keyPrefix){const e=this.config.extract.keySeparator??".";if(c=!1!==e?l.keyPrefix.endsWith(e)?`${l.keyPrefix}${o}`:`${l.keyPrefix}${e}${o}`:`${l.keyPrefix}${o}`,!1!==e){if(c.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${c}' (keyPrefix: '${l.keyPrefix}', key: '${o}')`);continue}}}const y=e===u.length-1?"string"==typeof x?x:a&&r.includes(a||":")?r:o:o;if(h){const e=n(h,"context"),r=[];if("StringLiteral"===e?.type||"NumericLiteral"===e?.type||"BooleanLiteral"===e?.type){const t=`${e.value}`,n=this.config.extract.contextSeparator??"_";""!==t&&r.push({key:`${c}${n}${t}`,ns:i,defaultValue:y,explicitDefault:k})}else if(e){const t=this.expressionResolver.resolvePossibleContextStringValues(e),n=this.config.extract.contextSeparator??"_";t.length>0&&t.forEach(e=>{r.push({key:`${c}${n}${e}`,ns:i,defaultValue:y,explicitDefault:k})}),r.push({key:c,ns:i,defaultValue:y,explicitDefault:k,keyAcceptingContext:c})}const s=e=>{if(e){if("KeyValueProperty"===e.type&&e.key){if("Identifier"===e.key.type)return e.key.value;if("StringLiteral"===e.key.type)return e.key.value}return"KeyValueProperty"===e.type&&e.value&&"Identifier"===e.value.type?e.key&&"Identifier"===e.key.type?e.key.value:void 0:"ShorthandProperty"!==e.type&&"Identifier"!==e.type||!e.value?e.key&&"string"==typeof e.key?e.key:void 0:e.value}},o=(()=>{if(!h||!Array.isArray(h.properties))return!1;for(const e of h.properties){if("count"===s(e))return!0}return!1})(),l=(()=>{if(!h||!Array.isArray(h.properties))return!1;for(const e of h.properties){if("ordinal"===s(e))return!("KeyValueProperty"!==e.type||!e.value||"BooleanLiteral"!==e.value.type)&&Boolean(e.value.value)}return!1})();if(o||p){try{const e=p?"ordinal":"cardinal",t=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let n=!1;try{const r=new Intl.PluralRules(t,{type:e}).resolvedOptions().pluralCategories;1===r.length&&"other"===r[0]&&(n=!0)}catch{}if(!n){const t=new Set;for(const n of this.config.locales)try{new Intl.PluralRules(n,{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}catch{new Intl.PluralRules("en",{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}const r=Array.from(t).sort();1===r.length&&"other"===r[0]&&(n=!0)}if(n){if(r.length>0)for(const e of r)this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,hasCount:!0,isOrdinal:p});else this.pluginContext.addKey({key:c,ns:i,defaultValue:y,hasCount:!0,isOrdinal:p});continue}}catch(e){}this.config.extract.disablePlurals?r.length>0?r.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:c,ns:i,defaultValue:y,explicitDefault:k}):this.handlePluralKeys(c,i,h,l||p,x,v);continue}if(r.length>0){r.forEach(this.pluginContext.addKey);continue}!0===t(h,"returnObjects")&&this.objectKeys.add(c)}f&&this.objectKeys.add(c);{const e=this.getLocationFromNode(s);this.pluginContext.addKey({key:c,ns:i,defaultValue:y,explicitDefault:k,locations:e?[{file:this.getCurrentFile(),line:e.line,column:e.column}]:void 0}),this.extractNestedKeys(c,i)}"string"==typeof x&&this.extractNestedKeys(x,i)}}extractNestedKeys(e,t){if(!e||"string"!=typeof e)return;const n=this.config.extract.nestingPrefix??"$t(",s=this.config.extract.nestingSuffix??")",i=r(n),o=r(s),l=new RegExp(`${i}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${o}`,"g");let a;for(;null!==(a=l.exec(e));)a[1]&&this.processNestedContent(a[1],void 0)}processNestedContent(e,t){let n=e,s="";const i=this.config.extract.nestingOptionsSeparator??",";if(e.indexOf(i)<0)n=e.trim();else{const t=new RegExp(`${r(i)}[ ]*{`),o=e.split(t);if(o.length>1)n=o[0].trim(),s=`{${o.slice(1).join(i+" {")}`;else{const t=e.indexOf(i);n=e.substring(0,t).trim(),s=e.substring(t+1).trim()}}if((n.startsWith("'")&&n.endsWith("'")||n.startsWith('"')&&n.endsWith('"'))&&(n=n.slice(1,-1)),!n)return;let o;const l=this.config.extract.nsSeparator??":";if(l&&n.includes(l)){const e=n.split(l);if(o=e.shift(),n=e.join(l),!n||""===n.trim())return}else o=this.config.extract.defaultNS;let a,c=!1;if(s){/['"]?count['"]?\s*:/.test(s)&&(c=!0);const e=/['"]?context['"]?\s*:\s*(['"])(.*?)\1/.exec(s);e&&(a=e[2])}c||void 0!==a?this.generateNestedPluralKeys(n,o,c,a):this.pluginContext.addKey({key:n,ns:o})}generateNestedPluralKeys(e,t,n,r){try{const s="cardinal";if(!n&&void 0!==r)return this.pluginContext.addKey({key:e,ns:t}),void this.pluginContext.addKey({key:`${e}_${r}`,ns:t});const i=new Set,o=this.config.locales||["en"];for(const e of o)try{const t=new Intl.PluralRules(e,{type:s});t.resolvedOptions().pluralCategories.forEach(e=>i.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:s});t.resolvedOptions().pluralCategories.forEach(e=>i.add(e))}const l=Array.from(i).sort(),a=this.config.extract.pluralSeparator??"_",c=this.config.extract.contextSeparator??"_",u=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let f=!1;try{const e=new Intl.PluralRules(u,{type:s}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&(f=!0)}catch{f=!1}const p=f||1===l.length&&"other"===l[0],y=[];if(void 0!==r?y.push({key:e,context:r}):y.push({key:e}),p){for(const{key:e,context:n}of y){const r=n?`${e}${c}${n}`:e;this.pluginContext.addKey({key:r,ns:t,hasCount:!0})}return}for(const{key:e,context:n}of y)for(const r of l){let s;s=n?`${e}${c}${n}${a}${r}`:`${e}${a}${r}`,this.pluginContext.addKey({key:s,ns:t,hasCount:!0})}}catch(n){this.pluginContext.addKey({key:e,ns:t})}}handleCallExpressionArgument(e,t){const n=e.arguments[t].expression,r=[];let s=!1;if("ArrowFunctionExpression"===n.type){const e=this.extractKeyFromSelector(n);e&&(r.push(e),s=!0)}else if("ArrayExpression"===n.type)for(const e of n.elements)e?.expression&&r.push(...this.expressionResolver.resolvePossibleKeyStringValues(e.expression));else r.push(...this.expressionResolver.resolvePossibleKeyStringValues(n));return{keysToProcess:r.filter(e=>!!e),isSelectorAPI:s}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let n=t;const r=[];for(;"MemberExpression"===n.type;){const e=n.property;if("Identifier"===e.type)r.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;r.unshift(e.expression.value)}n=n.object}if(r.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return r.join(t)}return null}handlePluralKeys(e,r,s,i,o,l){try{const a=i?"ordinal":"cardinal",c=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:a});t.resolvedOptions().pluralCategories.forEach(e=>c.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:a});t.resolvedOptions().pluralCategories.forEach(e=>c.add(e))}const u=Array.from(c).sort(),f=this.config.extract.pluralSeparator??"_",p=t(s,"defaultValue"),y=t(s,`defaultValue${f}other`),g=t(s,`defaultValue${f}ordinal${f}other`),h=n(s,"context"),d=[];if(h){const t=this.expressionResolver.resolvePossibleContextStringValues(h);if(t.length>0)if("StringLiteral"===h.type)for(const n of t)n.length>0&&d.push({key:e,context:n});else{for(const n of t)n.length>0&&d.push({key:e,context:n});!1!==this.config.extract?.generateBasePluralForms&&d.push({key:e})}else d.push({key:e})}else d.push({key:e});const x=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let $=!1;try{const e=new Intl.PluralRules(x,{type:a}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&($=!0)}catch{$=!1}if($||1===u.length&&"other"===u[0]){for(const{key:e,context:n}of d){const a=t(s,`defaultValue${f}other`);let c;c="string"==typeof a?a:"string"==typeof p?p:"string"==typeof o?o:n?`${e}_${n}`:e;const u=this.config.extract.contextSeparator??"_",y=n?`${e}${u}${n}`:e;this.pluginContext.addKey({key:y,ns:r,defaultValue:c,hasCount:!0,isOrdinal:i,explicitDefault:Boolean(l||"string"==typeof a)})}return}for(const{key:n,context:a}of d)for(const c of u){const u=t(s,i?`defaultValue${f}ordinal${f}${c}`:`defaultValue${f}${c}`);let h,d;if(h="string"==typeof u?u:"one"===c&&"string"==typeof p?p:"one"===c&&"string"==typeof o?o:i&&"string"==typeof g?g:i||"string"!=typeof y?"string"==typeof p?p:"string"==typeof o?o:n:y,a){const e=this.config.extract.contextSeparator??"_";d=i?`${n}${e}${a}${f}ordinal${f}${c}`:`${n}${e}${a}${f}${c}`}else d=i?`${n}${f}ordinal${f}${c}`:`${n}${f}${c}`;this.pluginContext.addKey({key:d,ns:r,defaultValue:h,hasCount:!0,isOrdinal:i,explicitDefault:Boolean(l||"string"==typeof u||"string"==typeof y),keyAcceptingContext:void 0!==a?e:void 0})}}catch(n){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const i=o||t(s,"defaultValue");this.pluginContext.addKey({key:e,ns:r,defaultValue:"string"==typeof i?i:e})}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let n=e;for(;"MemberExpression"===n.type;){if("Identifier"!==n.property.type)return null;t.unshift(n.property.value),n=n.object}if("ThisExpression"===n.type)t.unshift("this");else{if("Identifier"!==n.type)return null;t.unshift(n.value)}return t.join(".")}return null}}export{s as CallExpressionHandler};
@@ -1 +1 @@
1
- import{getObjectPropValueExpression as e,getObjectPropValue as t,isSimpleTemplateLiteral as n}from"./ast-utils.js";function i(e){if(e)return"StringLiteral"===e.type?e.value:"TemplateLiteral"===e.type&&n(e)?e.quasis[0].cooked:void 0}function s(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?i(e.value.expression):void 0}function r(n,r){const o=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),p=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),l=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),a=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let c;l||"JSXAttribute"!==a?.type||"JSXExpressionContainer"!==a.value?.type||"ObjectExpression"!==a.value.expression.type||(c=e(a.value.expression,"count"));const u=!!l||!!c,f=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),y="JSXAttribute"===f?.type&&"JSXExpressionContainer"===f.value?.type&&"ObjectExpression"===f.value.expression.type?f.value.expression:void 0,d=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),g=!!d,x=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let h="JSXAttribute"===x?.type&&"JSXExpressionContainer"===x.value?.type?x.value.expression:"JSXAttribute"===x?.type&&"StringLiteral"===x.value?.type?x.value:void 0;const S=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let v;v="JSXAttribute"===S?.type?s(S):void 0,y&&(void 0===v&&(v=t(y,"ns")),void 0===h&&(h=e(y,"context")));const m=function(e,t){if(!e||0===e.length)return"";const n=new Set(t.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),s=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function r(e,t,o=!1,p=!1){if(!e||!e.length)return;const l=p&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let a=0,c=e.length-1;for(;a<=c&&s(e[a]);)a++;for(;c>=a&&s(e[c]);)c--;const u=a<=c?e.slice(a,c+1):[],f=u.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<u.length;e++){const a=u[e];if(a)if("JSXText"!==a.type){if("JSXExpressionContainer"===a.type){if(o&&!f&&a.expression){const e=a.expression.type;if("ObjectExpression"===e)continue;if(void 0!==i(a.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const n=i(a.expression);if(void 0!==n){const i=/^\s*$/.test(n)&&!n.includes("\n"),r=u[e-1],o=u[e+1];if(i){const n=u[e+2];if(o&&"JSXText"===o.type&&s(o)&&n&&("JSXElement"===n.type||"JSXFragment"===n.type)){const t=u[e-1],n=u[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue;const i=!o||"JSXText"===o.type&&!s(o);if(r&&"JSXText"===r.type&&i){const e=t[t.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+a.expression.value;continue}}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue}}t.push(a);continue}if("JSXElement"===a.type){const e=a.opening&&a.opening.name&&"Identifier"===a.opening.name.type?a.opening.name.value:void 0;if(e&&n.has(e)){const o=a.opening&&Array.isArray(a.opening.attributes)&&a.opening.attributes.length>0,c=a.children||[],f=1===c.length&&("JSXText"===c[0]?.type||"JSXExpressionContainer"===c[0]?.type&&void 0!==i(c[0].expression)),y=!c.length,d=f;if(o&&!f)t.push(a),r(a.children||[],t,!0);else if(y)t.push(a);else if(!d){if((a.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===i(e.expression)))t.push(a),r(a.children||[],t,!0);else if("p"===e){const e=(c||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,s=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));return!(t&&n.has(t)&&!s&&(0===r.length||o))}),o=p&&u.some(e=>e&&e!==a&&"JSXText"===e.type&&!s(e));l||p&&e&&!o?(t.push(a),r(a.children||[],t,!0,!1)):r(a.children||[],t,!1,!1)}else r(a.children||[],t,!1,!1)}continue}t.push(a),r(a.children||[],t,!0);continue}"JSXFragment"!==a.type||r(a.children||[],t,o)}else{if(o&&!f)continue;if(o&&s(a))continue;if(s(a)){const n=u[e-1],i=u[e+1];if(n&&("JSXElement"===n.type||"JSXFragment"===n.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=t[t.length-1],r=u[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+a.value;continue}}}if(o&&f&&0===e)continue;t.push(a)}}}const o=[];function p(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==o.indexOf(n))return t;if("JSXText"===n.type&&-1!==o.indexOf(n)){if(s(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}r(e,o,!1,!0);const l=new Set,a=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function c(e,t,r=!1){if(!e||0===e.length)return"";let u="";const f=e=>{if(!e)return-1;if(t&&t.has(e))return t.get(e);if(t)for(const[n,i]of t.entries())try{if(n&&e&&n.span&&e.span&&n.span.start===e.span.start&&n.span.end===e.span.end)return i}catch(e){}return o.indexOf(e)},y=t=>{if(!r)return o.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?s(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let t=0;t<e.length;t++){const d=e[t];if(d){if("JSXText"===d.type){if(s(d))continue;const i=e[t+1],r=e[t-1];if(r&&"JSXElement"===r.type){const i="Identifier"===r.opening?.name?.type?r.opening.name.value:void 0,s=i&&n.has(i),o=0===(r.children||[]).length;if(s&&o&&/^\s*\n\s*/.test(d.value)){const e=d.value.replace(/^\s*\n\s*/,"");if(e){u+=e;continue}continue}if(!s&&/^\s*\n\s*/.test(d.value)){const n=d.value.replace(/^\s*\n\s*/,"");if(n){if(r&&"JSXElement"===r.type&&Array.isArray(r.children)&&0===r.children.length){u+=n;continue}const i=e[t-2];if(i&&"JSXText"===i.type){const e=i.value.replace(/\n\s*$/,""),t=/[A-Za-z0-9]$/.test(e),s=/^[A-Za-z0-9]/.test(n),r=/^[a-z]/.test(n);if(t&&s&&r){u+=n;continue}}u+=" "+n;continue}continue}}if(/\n\s*$/.test(d.value)&&i&&"JSXElement"===i.type){const r=d.value.replace(/\n\s*$/,"");if(r.trim()){const o="Identifier"===i.opening?.name?.type?i.opening.name.value:void 0,p=o&&n.has(o),a=(i.children||[]).length>0,c=/\s\n/.test(d.value),f=e[t+2],y=f&&"JSXText"===f.type&&!s(f)&&/[a-zA-Z0-9]/.test(f.value),g=!!(i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0),x=/^\s/.test(r)&&!/^\n/.test(r),h=r.trim(),S=x?" "+h:h,v=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),$=g&&a&&y&&!(v&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;v&&m&&J&&!c&&!x&&!X&&l.add(i),u+=c||p&&a||!p&&y&&x||b?S+" ":S;continue}}u+=d.value;continue}if("JSXExpressionContainer"===d.type){const e=d.expression;if(!e)continue;const t=i(e);if(void 0!==t)u+=t;else if("Identifier"===e.type)u+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)u+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)u+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)u+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)u+=`{{${e.callee.value}}}`;else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===d.type){const l=r?y(d):void 0;let g;if(d.opening&&d.opening.name&&"Identifier"===d.opening.name.type&&(g=d.opening.name.value),g&&n.has(g)){const y=d.opening&&Array.isArray(d.opening.attributes)&&d.opening.attributes.length>0,x=d.children||[],h=x.length>0,S=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==i(x[0].expression)),v="p"===g;let m=0;if(v&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||S){const i=S?c(x,void 0):"";if(""!==String(i).trim())if(n.has(g)&&"p"!==g)u+=`<${g}>${a(i)}</${g}>`;else if(v&&r&&m>1)u+=`<${g}>${a(i)}</${g}>`;else if(v){const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(i)}</${e}>`}else{const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(i)}</${e}>`}else{const n=e[t-1];n&&"JSXText"===n.type&&/\n\s*$/.test(n.value)&&(u=u.replace(/\s+$/,"")),u+=`<${g} />`}}else if(y&&!S){const e=x,t=r&&void 0!==l?l:f(d);if(p(e)){const s=new Map;let r=0;for(const t of e)if(t&&"JSXElement"===t.type){const e=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(e&&n.has(e)){const e=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,n=t.children||[],o=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!e&&(!n.length||o)||s.set(t,r++)}else s.set(t,r++)}const o=c(e,s.size?s:void 0);u+=`<${t}>${a(o)}</${t}>`}else{const e=new Map;let s=0;for(const t of x)if(t&&"JSXElement"===t.type){const r=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(r&&n.has(r)){const n=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,r=t.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));!n&&(!r.length||o)||e.set(t,s++)}else e.set(t,s++)}const r=c(x,e.size?e:void 0);u+=`<${t}>${a(r)}</${t}>`}}else{const e=o.indexOf(d);if(-1!==e){const t=void 0!==l?l:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==o.indexOf(t))return e;if("JSXText"===t.type&&-1!==o.indexOf(t)){if(s(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===t){const e=c(x,void 0,!1);u+=`<${t}>${a(e)}</${t}>`;continue}const e=new Map;let s=0;for(const t of x)if(t&&"JSXElement"===t.type){const r=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(r&&n.has(r)){const n=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,r=t.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));!n&&(!r.length||o)||e.set(t,s++)}else e.set(t,s++)}const r=c(x,e.size?e:void 0,!1);u+=`<${t}>${a(r)}</${t}>`;continue}const r=new Map;let p=0;for(const e of x)if(e&&"JSXElement"===e.type){const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(t&&n.has(t)){const t=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,n=e.children||[],s=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!t&&(!n.length||s)||r.set(e,p++)}else r.set(e,p++)}const f=c(x,r.size>0?r:void 0,!1);u+=`<${t}>${a(f)}</${t}>`}else{const e=c(x,void 0,!1);u+=`<${g}>${a(e)}</${g}>`}}}else{const e=d.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(d),n=c(e,void 0);u+=`<${t}>${a(n)}</${t}>`}else{const t=new Map,i=f(d);let s=0;for(const i of e)if(i&&"JSXElement"===i.type){const e=i.opening&&i.opening.name&&"Identifier"===i.opening.name.type?i.opening.name.value:void 0;if(e&&n.has(e)){const e=i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0,n=i.children||[],r=1===n.length&&"JSXText"===n[0]?.type;!e&&(!n.length||r)||t.set(i,s++)}else t.set(i,s++)}const r=c(e,t.size?t:void 0);u+=`<${i}>${a(r)}</${i}>`}}continue}"JSXFragment"!==d.type||(u+=c(d.children||[]))}}return u}const u=c(e,void 0,!0),f=String(u).replace(/<br \/>\s*\n\s*/g,"<br />"),y=String(f),d=new Set;if(l&&l.size>0)for(let e=0;e<o.length;e++)l.has(o[e])&&d.add(e);let g=String(y);if(d&&d.size>0)for(const e of d)try{g=g.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),g=g.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}g=g.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return d.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),g=g.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return d.has(i)?`${t}<${n}`:`${t} <${n}`}),g=g.replace(/\s*\n\s*/g," "),g=g.replace(/\s+/g," "),g=g.replace(/\s+([,;:!?.])/g,"$1");const x=g.trim();let h=String(x);if(d&&d.size>0)for(const e of d)try{h=h.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),h=h.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<o.length;e++){const t=o[e];if(!t||"JSXElement"!==t.type)continue;const n=o[e-1],i=o[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),p=s.replace(/\n\s*$/,""),l=/[A-Za-z0-9]$/.test(p),a=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(l&&a&&c&&!u&&!f){const t=e;h=h.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function S(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function i(e,t=null){let s="";for(const r of e)if("text"===r.type)s+=r.text;else{const e=r.children.filter(e=>"ph"===e.type),p=e.map(e=>e.idx);if(!(p.length<=1||p.every((e,t)=>0===t||e===p[t-1]+1))){const e=r.children.map(e=>"text"===e.type?e.text:`<${e.idx}>${i(e.children,e.idx)}</${e.idx}>`).join("");s+=`<${r.idx}>${e}</${r.idx}>`;continue}const l=new Map;let a=0;try{const i=o[r.idx];if(i&&i.span){const s=i.span.start,p=i.span.end;let l=-1;for(let e=r.idx+1;e<o.length;e++){const t=o[e];if(t&&t.span&&(t.span.start>=s&&t.span.end<=p&&"JSXElement"===t.type)){l=e;break}}let c=0;if(-1!==l)for(let e=r.idx+1;e<l;e++){const t=o[e];t&&t.span&&(t.span.start>=s&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||c++))}else for(let e=r.idx+1;e<o.length;e++){const t=o[e];t&&t.span&&(t.span.start>=s&&t.span.end<=p&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||c++))}if("number"==typeof r.idx){const i=o[r.idx],s=i?.opening?.name?.value,p=s&&n.has(s),l=null===t;1===e.length?(a=Math.max(1,c+1),!l||p||0!==e[0].idx||"a"!==s&&"p"!==s||(a=0)):a=0}}}catch(e){}for(const t of e)l.has(t.idx)||l.set(t.idx,a++);const c=r.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,n=l.has(t)?l.get(t):t;return`<${n}>${i(e.children,n)}</${n}>`}).join("");s+=`<${r.idx}>${c}</${r.idx}>`}return s}try{return i(t(e))}catch(t){return e}}return h=S(h),h.trim()}(n.children,r);let J;const X="JSXAttribute"===p?.type?s(p):void 0;if(void 0!==X)J=X;else{const e=r.extract.defaultValue;J="string"==typeof e?e:""}let $,E;if("JSXAttribute"===o?.type){if("StringLiteral"===o.value?.type){if($=o.value,E=$.value,!E||""===E.trim())return null;if(v&&"StringLiteral"===$.type){const e=r.extract.nsSeparator??":",t=$.value;if(e&&t.startsWith(`${v}${e}`)){if(E=t.slice(`${v}${e}`.length),!E||""===E.trim())return null;$={...$,value:E}}}}else"JSXExpressionContainer"===o.value?.type&&"JSXEmptyExpression"!==o.value.expression.type&&($=o.value.expression);if(!$)return null}p||!E||m.trim()?!p&&m.trim()&&(J=m):J=E;return{keyExpression:$,serializedChildren:m,ns:v,defaultValue:J,hasCount:u,isOrdinal:g,contextExpression:h,optionsNode:y,explicitDefault:void 0!==X||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(y)}}export{r as extractFromTransComponent};
1
+ import{getObjectPropValueExpression as e,getObjectPropValue as t,isSimpleTemplateLiteral as n}from"./ast-utils.js";function i(e){if(e)return"StringLiteral"===e.type?e.value:"TemplateLiteral"===e.type&&n(e)?e.quasis[0].cooked:void 0}function s(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?i(e.value.expression):void 0}function r(n,r){const o=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"i18nKey"===e.name.value),p=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"defaults"===e.name.value),l=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"count"===e.name.value),a=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"values"===e.name.value);let c;l||"JSXAttribute"!==a?.type||"JSXExpressionContainer"!==a.value?.type||"ObjectExpression"!==a.value.expression.type||(c=e(a.value.expression,"count"));const u=!!l||!!c,f=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),y="JSXAttribute"===f?.type&&"JSXExpressionContainer"===f.value?.type&&"ObjectExpression"===f.value.expression.type?f.value.expression:void 0,d=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),g=!!d,x=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let h="JSXAttribute"===x?.type&&"JSXExpressionContainer"===x.value?.type?x.value.expression:"JSXAttribute"===x?.type&&"StringLiteral"===x.value?.type?x.value:void 0;const S=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let v;v="JSXAttribute"===S?.type?s(S):void 0,y&&(void 0===v&&(v=t(y,"ns")),void 0===h&&(h=e(y,"context")));const m=function(e,t){if(!e||0===e.length)return"";const n=new Set(t.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),s=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function r(e,t,o=!1,p=!1){if(!e||!e.length)return;const l=p&&e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length>1;let a=0,c=e.length-1;for(;a<=c&&s(e[a]);)a++;for(;c>=a&&s(e[c]);)c--;const u=a<=c?e.slice(a,c+1):[],f=u.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<u.length;e++){const a=u[e];if(a)if("JSXText"!==a.type){if("JSXExpressionContainer"===a.type){if(o&&!f&&a.expression){const e=a.expression.type;if("ObjectExpression"===e)continue;if(void 0!==i(a.expression))continue;if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const n=i(a.expression);if(void 0!==n){const i=/^\s*$/.test(n)&&!n.includes("\n"),r=u[e-1],o=u[e+1];if(i){const n=u[e+2];if(o&&"JSXText"===o.type&&s(o)&&n&&("JSXElement"===n.type||"JSXFragment"===n.type)){const t=u[e-1],n=u[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue;const i=!o||"JSXText"===o.type&&!s(o);if(r&&"JSXText"===r.type&&i){const e=t[t.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+a.expression.value;continue}}if(r&&("JSXElement"===r.type||"JSXFragment"===r.type)&&o&&"JSXText"===o.type&&s(o))continue}}t.push(a);continue}if("JSXElement"===a.type){const e=a.opening&&a.opening.name&&"Identifier"===a.opening.name.type?a.opening.name.value:void 0;if(e&&n.has(e)){const o=a.opening&&Array.isArray(a.opening.attributes)&&a.opening.attributes.length>0,c=a.children||[],f=1===c.length&&("JSXText"===c[0]?.type||"JSXExpressionContainer"===c[0]?.type&&void 0!==i(c[0].expression)),y=!c.length,d=f;if(o&&!f)t.push(a),r(a.children||[],t,!0);else if(y)t.push(a);else if(!d){if((a.children||[]).some(e=>"JSXExpressionContainer"===e.type&&void 0===i(e.expression)))t.push(a),r(a.children||[],t,!0);else if("p"===e){const e=(c||[]).some(e=>{if(!e||"JSXElement"!==e.type)return!1;const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0,s=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,r=e.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));return!(t&&n.has(t)&&!s&&(0===r.length||o))}),o=p&&u.some(e=>e&&e!==a&&"JSXText"===e.type&&!s(e));l||p&&e&&!o?(t.push(a),r(a.children||[],t,!0,!1)):r(a.children||[],t,!1,!1)}else r(a.children||[],t,!1,!1)}continue}t.push(a),r(a.children||[],t,!0);continue}"JSXFragment"!==a.type||r(a.children||[],t,o)}else{if(o&&!f)continue;if(o&&s(a))continue;if(s(a)){const n=u[e-1],i=u[e+1];if(n&&("JSXElement"===n.type||"JSXFragment"===n.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const s=t[t.length-1],r=u[e-1];if(s){if(r&&"JSXExpressionContainer"===r.type)continue;if("JSXText"===s.type&&r&&"JSXText"===r.type){s.value=String(s.value)+a.value;continue}}}if(o&&f&&0===e)continue;t.push(a)}}}const o=[];function p(e){if(!e||!e.length)return!1;let t=!1;for(const n of e)if(n)if("JSXElement"!==n.type){if("JSXExpressionContainer"===n.type&&-1!==o.indexOf(n))return t;if("JSXText"===n.type&&-1!==o.indexOf(n)){if(s(n))continue;if(!t)return!0;const i=e.indexOf(n);if(e.slice(i+1).some(e=>e&&"JSXElement"===e.type))return!0}}else t=!0;return!1}r(e,o,!1,!0);const l=new Set,a=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function c(e,t,r=!1){if(!e||0===e.length)return"";let u="";const f=e=>{if(!e)return-1;if(t&&t.has(e))return t.get(e);if(t)for(const[n,i]of t.entries())try{if(n&&e&&n.span&&e.span&&n.span.start===e.span.start&&n.span.end===e.span.end)return i}catch(e){}return o.indexOf(e)},y=t=>{if(!r)return o.indexOf(t);const n=e.indexOf(t);if(-1===n)return-1;let i=0;for(let t=0;t<n;t++){const n=e[t];n&&("JSXText"===n.type?s(n)||i++:"JSXExpressionContainer"===n.type?n.expression&&"JSXEmptyExpression"!==n.expression.type&&i++:"JSXElement"===n.type&&i++)}return i};for(let t=0;t<e.length;t++){const d=e[t];if(d){if("JSXText"===d.type){if(s(d))continue;const i=e[t+1],r=e[t-1];if(r&&"JSXElement"===r.type){const i="Identifier"===r.opening?.name?.type?r.opening.name.value:void 0,s=i&&n.has(i),o=0===(r.children||[]).length;if(s&&o&&/^\s*\n\s*/.test(d.value)){const e=d.value.replace(/^\s*\n\s*/,"");if(e){u+=e;continue}continue}if(!s&&/^\s*\n\s*/.test(d.value)){const n=d.value.replace(/^\s*\n\s*/,"");if(n){if(r&&"JSXElement"===r.type&&Array.isArray(r.children)&&0===r.children.length){u+=n;continue}const i=e[t-2];if(i&&"JSXText"===i.type){const e=i.value.replace(/\n\s*$/,""),t=/[A-Za-z0-9]$/.test(e),s=/^[A-Za-z0-9]/.test(n),r=/^[a-z]/.test(n);if(t&&s&&r){u+=n;continue}}u+=" "+n;continue}continue}}if(/\n\s*$/.test(d.value)&&i&&"JSXElement"===i.type){const r=d.value.replace(/\n\s*$/,"");if(r.trim()){const o="Identifier"===i.opening?.name?.type?i.opening.name.value:void 0,p=o&&n.has(o),a=(i.children||[]).length>0,c=/\s\n/.test(d.value),f=e[t+2],y=f&&"JSXText"===f.type&&!s(f)&&/[a-zA-Z0-9]/.test(f.value),g=!!(i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0),x=/^\s/.test(r)&&!/^\n/.test(r),h=r.trim(),S=x?" "+h:h,v=/[A-Za-z0-9]$/.test(h),m=f&&"string"==typeof f.value&&/^[A-Za-z0-9]/.test(f.value.trim()),J=f&&"string"==typeof f.value&&/^[a-z]/.test(f.value.trim()),X=f&&"string"==typeof f.value&&/^\s/.test(f.value)&&!/^\n/.test(f.value),$=g&&a&&y&&!(v&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;v&&m&&J&&!c&&!x&&!X&&l.add(i),u+=c||p&&a||!p&&y&&x||b?S+" ":S;continue}}u+=d.value;continue}if("JSXExpressionContainer"===d.type){const e=d.expression;if(!e)continue;const t=i(e);if(void 0!==t)u+=t;else if("Identifier"===e.type)u+=`{{${e.value}}}`;else if("TsAsExpression"===e.type&&"ObjectExpression"===e.expression?.type){const t=e.expression,n=t.properties.filter(e=>"KeyValueProperty"===e.type&&e.key&&"Identifier"===e.key.type).map(e=>e.key.value);if(n.length>0)u+=n.map(e=>`{{${e}}}`).join("");else{const e=t.properties[0];if(!e||"Identifier"!==e.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.value}}}`}}else if("ObjectExpression"===e.type){const t=e.properties[0];if(t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type)u+=`{{${t.key.value}}}`;else{if(!t||"Identifier"!==t.type)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${t.value}}}`}}else if("MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type)u+=`{{${e.property.value}}}`;else if("CallExpression"===e.type&&"Identifier"===e.callee?.type)u+=`{{${e.callee.value}}}`;else if("JSXEmptyExpression"!==e.type)throw new Error(`Unrecognized expression in JSX placeholder: ${e.type}`);continue}if("JSXElement"===d.type){const l=r?y(d):void 0;let g;if(d.opening&&d.opening.name&&"Identifier"===d.opening.name.type&&(g=d.opening.name.value),g&&n.has(g)){const y=d.opening&&Array.isArray(d.opening.attributes)&&d.opening.attributes.length>0,x=d.children||[],h=x.length>0,S=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==i(x[0].expression)),v="p"===g;let m=0;if(v&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||S){const i=S?c(x,void 0):"";if(""!==String(i).trim())if(n.has(g)&&"p"!==g)u+=`<${g}>${a(i)}</${g}>`;else if(v&&r&&m>1)u+=`<${g}>${a(i)}</${g}>`;else if(v){const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(i)}</${e}>`}else{const e=r&&void 0!==l?l:o.indexOf(d);u+=`<${e}>${a(i)}</${e}>`}else{const n=e[t-1];n&&"JSXText"===n.type&&/\n\s*$/.test(n.value)&&(u=u.replace(/\s+$/,"")),u+=`<${g} />`}}else if(y&&!S){const e=x,t=r&&void 0!==l?l:f(d);if(p(e)){const s=new Map;let r=0;for(const t of e)if(t&&"JSXElement"===t.type){const e=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(e&&n.has(e)){const e=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,n=t.children||[],o=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!e&&(!n.length||o)||s.set(t,r++)}else s.set(t,r++)}const o=c(e,s.size?s:void 0);u+=`<${t}>${a(o)}</${t}>`}else{const e=new Map;let s=0;for(const t of x)if(t&&"JSXElement"===t.type){const r=t.opening&&t.opening.name&&"Identifier"===t.opening.name.type?t.opening.name.value:void 0;if(r&&n.has(r)){const n=t.opening&&Array.isArray(t.opening.attributes)&&t.opening.attributes.length>0,r=t.children||[],o=1===r.length&&("JSXText"===r[0]?.type||"JSXExpressionContainer"===r[0]?.type&&void 0!==i(r[0].expression));!n&&(!r.length||o)||e.set(t,s++)}else e.set(t,s++)}const r=c(x,e.size?e:void 0);u+=`<${t}>${a(r)}</${t}>`}}else{const e=o.indexOf(d);if(-1!==e){const t=void 0!==l?l:e;if((()=>{let e=!1;for(const t of x)if(t)if("JSXElement"!==t.type){if("JSXExpressionContainer"===t.type&&-1!==o.indexOf(t))return e;if("JSXText"===t.type&&-1!==o.indexOf(t)){if(s(t))continue;if(!e)return!0;if(x.slice(x.indexOf(t)+1).some(e=>e&&"JSXElement"===e.type))return!0}}else e=!0;return!1})()){if(0===t){const e=c(x,void 0,!1);u+=`<${t}>${a(e)}</${t}>`;continue}const e=new Map;for(const e of x)if(e&&"JSXElement"===e.type){const s=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(s&&n.has(s)){const n=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,s=e.children||[],r=1===s.length&&("JSXText"===s[0]?.type||"JSXExpressionContainer"===s[0]?.type&&void 0!==i(s[0].expression));if(!(!n&&(!s.length||r))){const n=c(e.children,void 0,!1);u+=`<${t}>${a(n)}</${t}>`}}else{const n=c(e.children,void 0,!1);u+=`<${t}>${a(n)}</${t}>`}}const s=c(x,e.size?e:void 0,!1);u+=`<${t}>${a(s)}</${t}>`;continue}const r=new Map;let p=0;for(const e of x)if(e&&"JSXElement"===e.type){const t=e.opening&&e.opening.name&&"Identifier"===e.opening.name.type?e.opening.name.value:void 0;if(t&&n.has(t)){const t=e.opening&&Array.isArray(e.opening.attributes)&&e.opening.attributes.length>0,n=e.children||[],s=1===n.length&&("JSXText"===n[0]?.type||"JSXExpressionContainer"===n[0]?.type&&void 0!==i(n[0].expression));!t&&(!n.length||s)||r.set(e,p++)}else r.set(e,p++)}const f=c(x,r.size>0?r:void 0,!1);u+=`<${t}>${a(f)}</${t}>`}else{const e=c(x,void 0,!1);u+=`<${g}>${a(e)}</${g}>`}}}else{const e=d.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(d),n=c(e,void 0);u+=`<${t}>${a(n)}</${t}>`}else{const t=new Map,i=f(d);let s=0;for(const i of e)if(i&&"JSXElement"===i.type){const e=i.opening&&i.opening.name&&"Identifier"===i.opening.name.type?i.opening.name.value:void 0;if(e&&n.has(e)){const e=i.opening&&Array.isArray(i.opening.attributes)&&i.opening.attributes.length>0,n=i.children||[],r=1===n.length&&"JSXText"===n[0]?.type;!e&&(!n.length||r)||t.set(i,s++)}else t.set(i,s++)}const r=c(e,t.size?t:void 0);u+=`<${i}>${a(r)}</${i}>`}}continue}"JSXFragment"!==d.type||(u+=c(d.children||[]))}}return u}const u=c(e,void 0,!0),f=String(u).replace(/<br \/>\s*\n\s*/g,"<br />"),y=String(f),d=new Set;if(l&&l.size>0)for(let e=0;e<o.length;e++)l.has(o[e])&&d.add(e);let g=String(y);if(d&&d.size>0)for(const e of d)try{g=g.replace(new RegExp("\\s+<"+e+">","g"),"<"+e+">"),g=g.replace(new RegExp("<\\/"+e+">\\s+","g"),"</"+e+">")}catch(e){}g=g.replace(/<\/(\d+)>\s*\n\s*(\S)/g,(e,t,n)=>{const i=Number(t);return d.has(i)?`</${t}>${n}`:`</${t}> ${n}`}),g=g.replace(/(\S)\s*\n\s*<(\d+)/g,(e,t,n)=>{const i=Number(n);return d.has(i)?`${t}<${n}`:`${t} <${n}`}),g=g.replace(/\s*\n\s*/g," "),g=g.replace(/\s+/g," "),g=g.replace(/\s+([,;:!?.])/g,"$1");const x=g.trim();let h=String(x);if(d&&d.size>0)for(const e of d)try{h=h.replace(new RegExp("[\\s\\u00A0]+<"+e+">","g"),"<"+e+">"),h=h.replace(new RegExp("<\\/"+e+">[\\s\\u00A0]+","g"),"</"+e+">")}catch(e){}try{for(let e=0;e<o.length;e++){const t=o[e];if(!t||"JSXElement"!==t.type)continue;const n=o[e-1],i=o[e+1];if(!n||!i)continue;if("JSXText"!==n.type||"JSXText"!==i.type)continue;const s=String(n.value),r=String(i.value),p=s.replace(/\n\s*$/,""),l=/[A-Za-z0-9]$/.test(p),a=/^[A-Za-z0-9]/.test(r.trim()),c=/^[a-z]/.test(r.trim()),u=/\s\n/.test(s),f=r&&/^\s/.test(r)&&!/^\n/.test(r);if(l&&a&&c&&!u&&!f){const t=e;h=h.replace(new RegExp("\\s+<"+t+">","g"),"<"+t+">")}}}catch(e){}function S(e){if(!e||!e.includes("<"))return e;function t(e){const t=[],n=[];let i=0;const s=/<\/?(\d+)>|<[^>]+>/g;let r;for(;r=s.exec(e);){const o=r[0],p=r.index;if(p>i){const s={type:"text",text:e.slice(i,p)};n.length?n[n.length-1].node.children.push(s):t.push(s)}const l=/^<\/(\d+)>$/.exec(o),a=/^<(\d+)>$/.exec(o);if(a){const e=Number(a[1]),i={type:"ph",idx:e,children:[]};n.length?n[n.length-1].node.children.push(i):t.push(i),n.push({node:i,idx:e})}else if(l)n.length&&n.pop();else{const e={type:"text",text:o};n.length?n[n.length-1].node.children.push(e):t.push(e)}i=s.lastIndex}if(i<e.length){const s={type:"text",text:e.slice(i)};n.length?n[n.length-1].node.children.push(s):t.push(s)}return t}function i(e,t=null){let r="";for(const p of e)if("text"===p.type)r+=p.text;else{const e=p.children.filter(e=>"ph"===e.type);let l;if("number"==typeof p.idx){const t=o[p.idx];if(t&&Array.isArray(t.children)){const n=new Map;let i=0;for(const e of t.children){const t=o.indexOf(e);if("JSXText"===e.type){if(s(e))continue;-1!==t&&n.set(t,i),i++}else"JSXElement"===e.type?(-1!==t&&n.set(t,i),i++):"JSXExpressionContainer"===e.type&&-1!==t&&(n.set(t,i),i++)}e.every(e=>n.has(e.idx))&&(l=n)}}if(!l){const i=e.map(e=>e.idx);if(i.length<=1||i.every((e,t)=>0===t||e===i[t-1]+1)){l=new Map;let i=0;try{const s=o[p.idx];if(s&&s.span){const r=s.span.start,l=s.span.end;let a=0,c=-1;for(let e=p.idx+1;e<o.length;e++){const t=o[e];if(t&&t.span&&(t.span.start>=r&&t.span.end<=l&&"JSXElement"===t.type)){c=e;break}}if(-1!==c)for(let e=p.idx+1;e<c;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}else for(let e=p.idx+1;e<o.length;e++){const t=o[e];t&&t.span&&(t.span.start>=r&&t.span.end<=l&&("JSXText"!==t.type&&"JSXExpressionContainer"!==t.type||a++))}const u=s?.opening?.name?.value,f=u&&n.has(u),y=null===t;1===e.length&&(i=Math.max(1,a+1),!y||f||0!==e[0].idx||"a"!==u&&"p"!==u||(i=0))}}catch(e){}for(const t of e)l.has(t.idx)||l.set(t.idx,i++)}}const a=p.children.map(e=>{if("text"===e.type)return e.text;const t=e.idx,n=l&&l.has(t)?l.get(t):t;return`<${n}>${i(e.children,n)}</${n}>`}).join("");r+=`<${p.idx}>${a}</${p.idx}>`}return r}try{const n=t(e);return i(n)}catch(t){return e}}return h=S(h),h.trim()}(n.children,r);let J;const X="JSXAttribute"===p?.type?s(p):void 0;if(void 0!==X)J=X;else{const e=r.extract.defaultValue;J="string"==typeof e?e:""}let $,E;if("JSXAttribute"===o?.type){if("StringLiteral"===o.value?.type){if($=o.value,E=$.value,!E||""===E.trim())return null;if(v&&"StringLiteral"===$.type){const e=r.extract.nsSeparator??":",t=$.value;if(e&&t.startsWith(`${v}${e}`)){if(E=t.slice(`${v}${e}`.length),!E||""===E.trim())return null;$={...$,value:E}}}}else"JSXExpressionContainer"===o.value?.type&&"JSXEmptyExpression"!==o.value.expression.type&&($=o.value.expression);if(!$)return null}p||!E||m.trim()?!p&&m.trim()&&(J=m):J=E;return{keyExpression:$,serializedChildren:m,ns:v,defaultValue:J,hasCount:u,isOrdinal:g,contextExpression:h,optionsNode:y,explicitDefault:void 0!==X||(e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1})(y)}}export{r as extractFromTransComponent};
package/dist/esm/init.js CHANGED
@@ -1 +1 @@
1
- import t from"inquirer";import{writeFile as e,readFile as n}from"node:fs/promises";import{resolve as o}from"node:path";import{detectConfig as i}from"./heuristic-config.js";async function r(){console.log("Welcome to the i18next-cli setup wizard!"),console.log("Scanning your project for a recommended configuration...");const r=await i();r?console.log("✅ Found a potential project structure. Using it for suggestions."):console.log("Could not detect a project structure. Using standard defaults."),"string"==typeof r?.extract?.input&&(r.extract.input=[r?.extract?.input]),r&&"function"==typeof r.extract?.output&&delete r.extract.output;const a=await t.prompt([{type:"list",name:"fileType",message:"What kind of configuration file do you want?",choices:["TypeScript (i18next.config.ts)","JavaScript (i18next.config.js)"]},{type:"input",name:"locales",message:"What locales does your project support? (comma-separated)",default:r?.locales?.join(",")||"en,de,fr",filter:t=>t.split(",").map(t=>t.trim())},{type:"input",name:"input",message:"What is the glob pattern for your source files?",default:r?.extract?.input?(r.extract.input||[])[0]:"src/**/*.{js,jsx,ts,tsx}"},{type:"input",name:"output",message:"What is the path for your output resource files?",default:"string"==typeof r?.extract?.output?r.extract.output:"public/locales/{{language}}/{{namespace}}.json"}]),s=a.fileType.includes("TypeScript"),c=await async function(){try{const t=o(process.cwd(),"package.json"),e=await n(t,"utf-8");return"module"===JSON.parse(e).type}catch{return!0}}(),p=s?"i18next.config.ts":"i18next.config.js",u={locales:a.locales,extract:{input:a.input,output:a.output}};function f(t,e=2,n=0){const o=t=>" ".repeat(t*e),i=o(n),r=o(n+1);if(null===t||"number"==typeof t||"boolean"==typeof t)return JSON.stringify(t);if("string"==typeof t)return JSON.stringify(t);if(Array.isArray(t)){if(0===t.length)return"[]";return`[\n${t.map(t=>`${r}${f(t,e,n+1)}`).join(",\n")}\n${i}]`}if("object"==typeof t){const o=Object.keys(t);if(0===o.length)return"{}";return`{\n${o.map(o=>{const i=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(o)?o:JSON.stringify(o);return`${r}${i}: ${f(t[o],e,n+1)}`}).join(",\n")}\n${i}}`}return JSON.stringify(t)}let l="";l=s?`import { defineConfig } from 'i18next-cli';\n\nexport default defineConfig(${f(u)});`:c?`import { defineConfig } from 'i18next-cli';\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nexport default defineConfig(${f(u)});`:`const { defineConfig } = require('i18next-cli');\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nmodule.exports = defineConfig(${f(u)});`;const g=o(process.cwd(),p);await e(g,l.trim()),console.log(`✅ Configuration file created at: ${g}`)}export{r as runInit};
1
+ import t from"inquirer";import{writeFile as e,readFile as n}from"node:fs/promises";import{resolve as o}from"node:path";import{detectConfig as i}from"./heuristic-config.js";async function r(){console.log("Welcome to the i18next-cli setup wizard!"),console.log("Scanning your project for a recommended configuration...");const r=await i();r?console.log("✅ Found a potential project structure. Using it for suggestions."):console.log("Could not detect a project structure. Using standard defaults."),"string"==typeof r?.extract?.input&&(r.extract.input=[r?.extract?.input]),r&&"function"==typeof r.extract?.output&&delete r.extract.output;const a=await t.prompt([{type:"select",name:"fileType",message:"What kind of configuration file do you want?",choices:["TypeScript (i18next.config.ts)","JavaScript (i18next.config.js)"]},{type:"input",name:"locales",message:"What locales does your project support? (comma-separated)",default:r?.locales?.join(",")||"en,de,fr",filter:t=>t.split(",").map(t=>t.trim())},{type:"input",name:"input",message:"What is the glob pattern for your source files?",default:r?.extract?.input?(r.extract.input||[])[0]:"src/**/*.{js,jsx,ts,tsx}"},{type:"input",name:"output",message:"What is the path for your output resource files?",default:"string"==typeof r?.extract?.output?r.extract.output:"public/locales/{{language}}/{{namespace}}.json"}]),s=a.fileType.includes("TypeScript"),c=await async function(){try{const t=o(process.cwd(),"package.json"),e=await n(t,"utf-8");return"module"===JSON.parse(e).type}catch{return!0}}(),p=s?"i18next.config.ts":"i18next.config.js",u={locales:a.locales,extract:{input:a.input,output:a.output}};function f(t,e=2,n=0){const o=t=>" ".repeat(t*e),i=o(n),r=o(n+1);if(null===t||"number"==typeof t||"boolean"==typeof t)return JSON.stringify(t);if("string"==typeof t)return JSON.stringify(t);if(Array.isArray(t)){if(0===t.length)return"[]";return`[\n${t.map(t=>`${r}${f(t,e,n+1)}`).join(",\n")}\n${i}]`}if("object"==typeof t){const o=Object.keys(t);if(0===o.length)return"{}";return`{\n${o.map(o=>{const i=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(o)?o:JSON.stringify(o);return`${r}${i}: ${f(t[o],e,n+1)}`}).join(",\n")}\n${i}}`}return JSON.stringify(t)}let l="";l=s?`import { defineConfig } from 'i18next-cli';\n\nexport default defineConfig(${f(u)});`:c?`import { defineConfig } from 'i18next-cli';\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nexport default defineConfig(${f(u)});`:`const { defineConfig } = require('i18next-cli');\n\n/** @type {import('i18next-cli').I18nextToolkitConfig} */\nmodule.exports = defineConfig(${f(u)});`;const g=o(process.cwd(),p);await e(g,l.trim()),console.log(`✅ Configuration file created at: ${g}`)}export{r as runInit};
@@ -1 +1 @@
1
- import{execa as e}from"execa";import o from"chalk";import t from"ora";import n from"inquirer";import{sep as r,resolve as i}from"node:path";function s(e,o,t){const{locize:n={},extract:s}=o,{projectId:c,apiKey:a,version:l}=n,u=[e];if(c&&u.push("--project-id",c),a&&u.push("--api-key",a),l&&u.push("--ver",l),"sync"===e){(t.updateValues??n.updateValues)&&u.push("--update-values","true");(t.srcLngOnly??n.sourceLanguageOnly)&&u.push("--reference-language-only","true");(t.compareMtime??n.compareModificationTime)&&u.push("--compare-modification-time","true");(t.dryRun??n.dryRun)&&u.push("--dry","true")}let p;try{if("string"==typeof s.output){const e=s.output.replace(/\\/g,"/"),o=(e.includes("/{{language}}/")?e.split("/{{language}}/")[0]:e.replace("{{language}}","")).split("/").join(r);p=i(process.cwd(),o)}else if("function"==typeof s.output)try{const e=s.output(o.extract.primaryLanguage||"en"),t=String(e).replace(/\\/g,"/"),n=t.includes("/"+(o.extract.primaryLanguage||"en")+"/")?t.split("/"+(o.extract.primaryLanguage||"en")+"/")[0]:t.replace(o.extract.primaryLanguage||"en","");p=i(process.cwd(),n.split("/").join(r))}catch{p=i(process.cwd(),".")}else p=i(process.cwd(),".")}catch{p=i(process.cwd(),".")}return u.push("--path",p),u}async function c(r,i,c={}){await async function(){try{await e("locize",["--version"])}catch(e){"ENOENT"===e.code&&(console.error(o.red("Error: `locize-cli` command not found.")),console.log(o.yellow("Please install it globally to use the locize integration:")),console.log(o.cyan("npm install -g locize-cli")),process.exit(1))}}();const a=t(`Running 'locize ${r}'...\n`).start();let l=i;try{const t=s(r,l,c);console.log(o.cyan(`\nRunning 'locize ${t.join(" ")}'...`));const n=await e("locize",t,{stdio:"pipe"});a.succeed(o.green(`'locize ${r}' completed successfully.`)),n?.stdout&&console.log(n.stdout)}catch(t){const i=t.stderr||"";if(i.includes("missing required argument")){const t=await async function(){console.log(o.yellow("\nLocize configuration is missing or invalid. Let's set it up!"));const e=await n.prompt([{type:"input",name:"projectId",message:"What is your locize Project ID? (Find this in your project settings on www.locize.app)",validate:e=>!!e||"Project ID cannot be empty."},{type:"password",name:"apiKey",message:'What is your locize API key? (Create or use one in your project settings > "API Keys")',validate:e=>!!e||"API Key cannot be empty."},{type:"input",name:"version",message:"What version do you want to sync with?",default:"latest"}]);if(!e.projectId)return void console.error(o.red("Project ID is required to continue."));const{save:t}=await n.prompt([{type:"confirm",name:"save",message:"Would you like to see how to save these credentials for future use?",default:!0}]);if(t){const t=`\n# Add this to your .env file (and ensure .env is in your .gitignore!)\nLOCIZE_API_KEY=${e.apiKey}\n`,n=`\n // Add this to your i18next.config.ts file\n locize: {\n projectId: '${e.projectId}',\n // For security, apiKey is best set via an environment variable\n apiKey: process.env.LOCIZE_API_KEY,\n version: '${e.version}',\n },`;console.log(o.cyan("\nGreat! For the best security, we recommend using environment variables for your API key.")),console.log(o.bold("\nRecommended approach (.env file):")),console.log(o.green(t)),console.log(o.bold("Then, in your i18next.config.ts:")),console.log(o.green(n))}return{projectId:e.projectId,apiKey:e.apiKey,version:e.version}}();if(t){l={...l,locize:t},a.start("Retrying with new credentials...");try{const t=s(r,l,c);console.log(o.cyan(`\nRunning 'locize ${t.join(" ")}'...`));const n=await e("locize",t,{stdio:"pipe"});a.succeed(o.green("Retry successful!")),n?.stdout&&console.log(n.stdout)}catch(e){a.fail(o.red("Error during retry.")),console.error(e.stderr||e.message),process.exit(1)}}else a.fail("Operation cancelled."),process.exit(1)}else a.fail(o.red(`Error executing 'locize ${r}'.`)),console.error(i||t.message),process.exit(1)}console.log(o.green(`\n✅ 'locize ${r}' completed successfully.`))}const a=(e,o)=>c("sync",e,o),l=(e,o)=>c("download",e,o),u=(e,o)=>c("migrate",e,o);export{l as runLocizeDownload,u as runLocizeMigrate,a as runLocizeSync};
1
+ import{execa as e}from"execa";import o from"chalk";import t from"ora";import n from"inquirer";import{sep as r,resolve as s}from"node:path";function i(e,o,t){const{locize:n={},extract:i}=o,{projectId:c,apiKey:a,version:l}=n,u=[e];if(c&&u.push("--project-id",c),a&&u.push("--api-key",a),l&&u.push("--ver",l),"sync"===e){(t.updateValues??n.updateValues)&&u.push("--update-values","true");(t.srcLngOnly??n.sourceLanguageOnly)&&u.push("--reference-language-only","true");(t.compareMtime??n.compareModificationTime)&&u.push("--compare-modification-time","true");const e=t.cdnType??n.cdnType;e&&u.push("--cdn-type",e);(t.dryRun??n.dryRun)&&u.push("--dry","true")}let p;try{if("string"==typeof i.output){const e=i.output.replace(/\\/g,"/"),o=(e.includes("/{{language}}/")?e.split("/{{language}}/")[0]:e.replace("{{language}}","")).split("/").join(r);p=s(process.cwd(),o)}else if("function"==typeof i.output)try{const e=i.output(o.extract.primaryLanguage||"en"),t=String(e).replace(/\\/g,"/"),n=t.includes("/"+(o.extract.primaryLanguage||"en")+"/")?t.split("/"+(o.extract.primaryLanguage||"en")+"/")[0]:t.replace(o.extract.primaryLanguage||"en","");p=s(process.cwd(),n.split("/").join(r))}catch{p=s(process.cwd(),".")}else p=s(process.cwd(),".")}catch{p=s(process.cwd(),".")}return u.push("--path",p),u}async function c(r,s,c={}){await async function(){try{await e("locize",["--version"])}catch(e){"ENOENT"===e.code&&(console.error(o.red("Error: `locize-cli` command not found.")),console.log(o.yellow("Please install it globally to use the locize integration:")),console.log(o.cyan("npm install -g locize-cli")),process.exit(1))}}();const a=t(`Running 'locize ${r}'...\n`).start();let l=s;try{const t=i(r,l,c);console.log(o.cyan(`\nRunning 'locize ${t.join(" ")}'...`));const n=await e("locize",t,{stdio:"pipe"});a.succeed(o.green(`'locize ${r}' completed successfully.`)),n?.stdout&&console.log(n.stdout)}catch(t){const s=t.stderr||"";if(s.includes("missing required argument")){const t=await async function(){console.log(o.yellow("\nLocize configuration is missing or invalid. Let's set it up!"));const e=await n.prompt([{type:"input",name:"projectId",message:"What is your locize Project ID? (Find this in your project settings on www.locize.app)",validate:e=>!!e||"Project ID cannot be empty."},{type:"password",name:"apiKey",message:'What is your locize API key? (Create or use one in your project settings > "API Keys")',validate:e=>!!e||"API Key cannot be empty."},{type:"input",name:"version",message:"What version do you want to sync with?",default:"latest"}]);if(!e.projectId)return void console.error(o.red("Project ID is required to continue."));const{save:t}=await n.prompt([{type:"confirm",name:"save",message:"Would you like to see how to save these credentials for future use?",default:!0}]);if(t){const t=`\n# Add this to your .env file (and ensure .env is in your .gitignore!)\nLOCIZE_API_KEY=${e.apiKey}\n`,n=`\n // Add this to your i18next.config.ts file\n locize: {\n projectId: '${e.projectId}',\n // For security, apiKey is best set via an environment variable\n apiKey: process.env.LOCIZE_API_KEY,\n version: '${e.version}',\n },`;console.log(o.cyan("\nGreat! For the best security, we recommend using environment variables for your API key.")),console.log(o.bold("\nRecommended approach (.env file):")),console.log(o.green(t)),console.log(o.bold("Then, in your i18next.config.ts:")),console.log(o.green(n))}return{projectId:e.projectId,apiKey:e.apiKey,version:e.version}}();if(t){l={...l,locize:t},a.start("Retrying with new credentials...");try{const t=i(r,l,c);console.log(o.cyan(`\nRunning 'locize ${t.join(" ")}'...`));const n=await e("locize",t,{stdio:"pipe"});a.succeed(o.green("Retry successful!")),n?.stdout&&console.log(n.stdout)}catch(e){a.fail(o.red("Error during retry.")),console.error(e.stderr||e.message),process.exit(1)}}else a.fail("Operation cancelled."),process.exit(1)}else a.fail(o.red(`Error executing 'locize ${r}'.`)),console.error(s||t.message),process.exit(1)}console.log(o.green(`\n✅ 'locize ${r}' completed successfully.`))}const a=(e,o)=>c("sync",e,o),l=(e,o)=>c("download",e,o),u=(e,o)=>c("migrate",e,o);export{l as runLocizeDownload,u as runLocizeMigrate,a as runLocizeSync};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.31.0",
3
+ "version": "1.33.0",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -55,10 +55,10 @@
55
55
  "@rollup/plugin-replace": "6.0.3",
56
56
  "@rollup/plugin-terser": "0.4.4",
57
57
  "@types/inquirer": "9.0.9",
58
- "@types/node": "24.10.1",
58
+ "@types/node": "25.0.2",
59
59
  "@types/react": "19.2.7",
60
60
  "@vitest/coverage-v8": "4.0.15",
61
- "eslint": "9.39.1",
61
+ "eslint": "9.39.2",
62
62
  "eslint-plugin-import": "2.32.0",
63
63
  "memfs": "4.51.1",
64
64
  "neostandard": "0.12.2",
@@ -70,14 +70,14 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@croct/json5-parser": "0.2.2",
73
- "@swc/core": "1.15.3",
73
+ "@swc/core": "1.15.4",
74
74
  "chalk": "5.6.2",
75
- "chokidar": "4.0.3",
75
+ "chokidar": "5.0.0",
76
76
  "commander": "14.0.2",
77
77
  "execa": "9.6.1",
78
78
  "glob": "13.0.0",
79
- "i18next-resources-for-ts": "1.9.0",
80
- "inquirer": "12.10.0",
79
+ "i18next-resources-for-ts": "2.0.0",
80
+ "inquirer": "13.1.0",
81
81
  "jiti": "2.6.1",
82
82
  "jsonc-parser": "3.3.1",
83
83
  "minimatch": "10.1.1",
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAkBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AA4Q7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAkBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AA+Q7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
@@ -36,6 +36,12 @@ export declare class CallExpressionHandler {
36
36
  * @param getScopeInfo - Function to retrieve scope information for variables
37
37
  */
38
38
  handleCallExpression(node: CallExpression, getScopeInfo: (name: string) => ScopeInfo | undefined): void;
39
+ /**
40
+ * Scans a string for nested translations like $t(key, options) and extracts them.
41
+ */
42
+ private extractNestedKeys;
43
+ private processNestedContent;
44
+ private generateNestedPluralKeys;
39
45
  /**
40
46
  * Processed a call expression to extract keys from the specified argument.
41
47
  *
@@ -1 +1 @@
1
- {"version":3,"file":"call-expression-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/call-expression-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA6C,MAAM,WAAW,CAAA;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAgB,SAAS,EAAE,MAAM,aAAa,CAAA;AACvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,qBAAa,qBAAqB;IAChC,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,kBAAkB,CAAoB;IACvC,UAAU,cAAoB;IACrC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,eAAe,CAAY;gBAGjC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,MAAM,MAAM,EAC5B,cAAc,EAAE,MAAM,MAAM;IAU9B;;;OAGG;IACI,gBAAgB,IAAK,IAAI;IAIhC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IA0C3B;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,GAAG,IAAI;IAyWxG;;;;;;OAMG;IACH,OAAO,CAAC,4BAA4B;IA8BpC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,sBAAsB;IA2C9B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,gBAAgB;IA6LxB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;CA2BxB"}
1
+ {"version":3,"file":"call-expression-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/call-expression-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA6C,MAAM,WAAW,CAAA;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAgB,SAAS,EAAE,MAAM,aAAa,CAAA;AACvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAM1D,qBAAa,qBAAqB;IAChC,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,kBAAkB,CAAoB;IACvC,UAAU,cAAoB;IACrC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,eAAe,CAAY;gBAGjC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,MAAM,MAAM,EAC5B,cAAc,EAAE,MAAM,MAAM;IAU9B;;;OAGG;IACI,gBAAgB,IAAK,IAAI;IAIhC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IA4C3B;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,GAAG,IAAI;IAuXxG;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA4BzB,OAAO,CAAC,oBAAoB;IA6E5B,OAAO,CAAC,wBAAwB;IAyEhC;;;;;;OAMG;IACH,OAAO,CAAC,4BAA4B;IA8BpC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,sBAAsB;IA2C9B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,gBAAgB;IA6LxB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;CA2BxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"locize.d.ts","sourceRoot":"","sources":["../src/locize.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AA+PnD,eAAO,MAAM,aAAa,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAiD,CAAA;AAC7H,eAAO,MAAM,iBAAiB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAqD,CAAA;AACrI,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAoD,CAAA"}
1
+ {"version":3,"file":"locize.d.ts","sourceRoot":"","sources":["../src/locize.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAiQnD,eAAO,MAAM,aAAa,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAiD,CAAA;AAC7H,eAAO,MAAM,iBAAiB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAqD,CAAA;AACrI,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAoD,CAAA"}
package/types/types.d.ts CHANGED
@@ -124,6 +124,31 @@ export interface I18nextToolkitConfig {
124
124
  extractFromComments?: boolean;
125
125
  generateBasePluralForms?: boolean;
126
126
  disablePlurals?: boolean;
127
+ /**
128
+ * Prefix for nested translations.
129
+ * (default: '$t(')
130
+ */
131
+ nestingPrefix?: string;
132
+ /**
133
+ * Suffix for nested translations.
134
+ * (default: ')')
135
+ */
136
+ nestingSuffix?: string;
137
+ /**
138
+ * Separator for nested translation options.
139
+ * (default: ',')
140
+ */
141
+ nestingOptionsSeparator?: string;
142
+ /**
143
+ * Interpolation prefix used in defaultValue templates and runtime interpolation.
144
+ * Example: '{{' (default)
145
+ */
146
+ interpolationPrefix?: string;
147
+ /**
148
+ * Interpolation suffix used in defaultValue templates and runtime interpolation.
149
+ * Example: '}}' (default)
150
+ */
151
+ interpolationSuffix?: string;
127
152
  };
128
153
  /** Configuration options for linter */
129
154
  lint?: {
@@ -180,6 +205,8 @@ export interface I18nextToolkitConfig {
180
205
  sourceLanguageOnly?: boolean;
181
206
  /** Compare modification times when syncing */
182
207
  compareModificationTime?: boolean;
208
+ /** Specify the cdn endpoint that should be used (depends on which cdn type you've in your locize project) */
209
+ cdnType?: 'standard' | 'pro';
183
210
  /** Preview changes without making them */
184
211
  dryRun?: boolean;
185
212
  };
@@ -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,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;QAEpE;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;QAE3B,uEAAuE;QACvE,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,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