i18next-cli 1.29.2 → 1.29.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/cli.js CHANGED
@@ -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.29.2"),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"),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.29.4"),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;
@@ -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 v;v="JSXAttribute"===h?.type?n(h):void 0,f&&(void 0===v&&(v=e.getObjectPropValue(f,"ns")),void 0===x&&(x=e.getObjectPropValueExpression(f,"context")));const S=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(),v=x?" "+h:h,S=/[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&&!(S&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;S&&m&&J&&!c&&!x&&!X&&l.add(t),u+=c||p&&a||!p&&y&&x||b?v+" ":v;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)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.callee.value}}}`}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,v=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==t(x[0].expression)),S="p"===g;let m=0;if(S&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||v){const t=v?c(x,void 0):"";if(""!==String(t).trim())if(i.has(g)&&"p"!==g)u+=`<${g}>${a(t)}</${g}>`;else if(S&&r&&m>1)u+=`<${g}>${a(t)}</${g}>`;else if(S){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&&!v){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 v(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=v(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(v&&"StringLiteral"===X.type){const e=s.extract.nsSeparator??":",t=X.value;if(e&&t.startsWith(`${v}${e}`)){if($=t.slice(`${v}${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||!$||S.trim()?!o&&S.trim()&&(m=S):m=$,{keyExpression:X,serializedChildren:S,ns:v,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;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 +1 @@
1
- "use strict";var e=require("chalk"),t=require("ora"),a=require("node:path"),o=require("./extractor/core/key-finder.js"),s=require("./utils/nested-object.js"),n=require("./utils/file-utils.js"),l=require("./utils/funnel-msg-tracker.js");function r(t,a,o){const s=o>0?Math.round(a/o*100):100,n=c(s);console.log(`${e.bold(t)}: ${n} ${s}% (${a}/${o})`)}function c(t){const a=Math.floor(t/100*20),o=20-a;return`[${e.green("".padStart(a,"■"))}${"".padStart(o,"□")}]`}async function i(){if(await l.shouldShowFunnel("status"))return console.log(e.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${e.cyan("npx i18next-cli locize-migrate")} to get started.`),l.recordFunnelShown("status")}exports.runStatus=async function(l,u={}){l.extract.primaryLanguage||=l.locales[0]||"en",l.extract.secondaryLanguages||=l.locales.filter(e=>e!==l?.extract?.primaryLanguage);const d=t("Analyzing project localization status...\n").start();try{const t=await async function(e){e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(t=>t!==e?.extract?.primaryLanguage);const{allKeys:t}=await o.findKeys(e),{secondaryLanguages:l,keySeparator:r=".",defaultNS:c="translation",mergeNamespaces:i=!1,pluralSeparator:u="_"}=e.extract,d=new Map;for(const e of t.values()){const t=e.ns||c||"translation";d.has(t)||d.set(t,[]),d.get(t).push(e)}const y={totalBaseKeys:t.size,keysByNs:d,locales:new Map};for(const t of l){let o=0,l=0;const g=new Map,f=i?await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,t,!1===c?"translation":c||"translation")))||{}:null;for(const[c,y]of d.entries()){const d=i?f?.[c]??f??{}:await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,t,c)))||{};let p=0,$=0;const m=[],h=(e,t)=>{try{const a=t?"ordinal":"cardinal";return new Intl.PluralRules(e,{type:a}).resolvedOptions().pluralCategories}catch(e){return new Intl.PluralRules("en",{type:t?"ordinal":"cardinal"}).resolvedOptions().pluralCategories}};for(const{key:e,hasCount:a,isOrdinal:o,isExpandedPlural:n}of y)if(a)if(n){const a=e.split(u),o=a[a.length-1],n=a.length>=2&&"ordinal"===a[a.length-2],l=n?a[a.length-1]:o;if(h(t,n).includes(l)){$++;const t=!!s.getNestedValue(d,e,r??".");t&&p++,m.push({key:e,isTranslated:t})}}else{const a=h(t,o||!1);for(const t of a){$++;const a=o?`${e}${u}ordinal${u}${t}`:`${e}${u}${t}`,n=!!s.getNestedValue(d,a,r??".");n&&p++,m.push({key:a,isTranslated:n})}}else{$++;const t=!!s.getNestedValue(d,e,r??".");t&&p++,m.push({key:e,isTranslated:t})}g.set(c,{totalKeys:$,translatedKeys:p,keyDetails:m}),o+=p,l+=$}y.locales.set(t,{totalKeys:l,totalTranslated:o,namespaces:g})}return y}(l);d.succeed("Analysis complete."),await async function(t,a,o){o.detail?await async function(t,a,o,s){if(o===a.extract.primaryLanguage)return void console.log(e.yellow(`Locale "${o}" is the primary language. All keys are considered present.`));if(!a.locales.includes(o))return void console.error(e.red(`Error: Locale "${o}" is not defined in your configuration.`));const n=t.locales.get(o);if(!n)return void console.error(e.red(`Error: Locale "${o}" is not a valid secondary language.`));console.log(e.bold(`\nKey Status for "${e.cyan(o)}":`));const l=Array.from(t.keysByNs.values()).flat().length;r("Overall",n.totalTranslated,n.totalKeys);const c=s?[s]:Array.from(n.namespaces.keys()).sort();for(const t of c){const a=n.namespaces.get(t);a&&(console.log(e.cyan.bold(`\nNamespace: ${t}`)),r("Namespace Progress",a.translatedKeys,a.totalKeys),a.keyDetails.forEach(({key:t,isTranslated:a})=>{const o=a?e.green("✓"):e.red("✗");console.log(` ${o} ${t}`)}))}const u=l-n.totalTranslated;u>0?console.log(e.yellow.bold(`\nSummary: Found ${u} missing translations for "${o}".`)):console.log(e.green.bold(`\nSummary: 🎉 All keys are translated for "${o}".`));await i()}(t,a,o.detail,o.namespace):o.namespace?await async function(t,a,o){const s=t.keysByNs.get(o);if(!s)return void console.error(e.red(`Error: Namespace "${o}" was not found in your source code.`));console.log(e.cyan.bold(`\nStatus for Namespace: "${o}"`)),console.log("------------------------");for(const[e,a]of t.locales.entries()){const t=a.namespaces.get(o);if(t){const a=t.totalKeys>0?Math.round(t.translatedKeys/t.totalKeys*100):100,o=c(a);console.log(`- ${e}: ${o} ${a}% (${t.translatedKeys}/${t.totalKeys} keys)`)}}await i()}(t,0,o.namespace):await async function(t,a){const{primaryLanguage:o}=a.extract;console.log(e.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${e.bold(t.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${e.bold(t.keysByNs.size)}`),console.log(`🌍 Locales: ${e.bold(a.locales.join(", "))}`),console.log(`✅ Primary Language: ${e.bold(o)}`),console.log("\nTranslation Progress:");for(const[e,a]of t.locales.entries()){const t=a.totalKeys>0?Math.round(a.totalTranslated/a.totalKeys*100):100,o=c(t);console.log(`- ${e}: ${o} ${t}% (${a.totalTranslated}/${a.totalKeys} keys)`)}await i()}(t,a)}(t,l,u);let y=!1;for(const[,e]of t.locales.entries())if(e.totalTranslated<t.totalBaseKeys){y=!0;break}y&&(d.fail("Error: Missing translations detected."),process.exit(1))}catch(e){d.fail("Failed to generate status report."),console.error(e)}};
1
+ "use strict";var e=require("chalk"),t=require("ora"),a=require("node:path"),o=require("./extractor/core/key-finder.js"),s=require("./utils/nested-object.js"),n=require("./utils/file-utils.js"),l=require("./utils/funnel-msg-tracker.js");function r(t,a,o){const s=o>0?Math.round(a/o*100):100,n=c(s);console.log(`${e.bold(t)}: ${n} ${s}% (${a}/${o})`)}function c(t){const a=Math.floor(t/100*20),o=20-a;return`[${e.green("".padStart(a,"■"))}${"".padStart(o,"□")}]`}async function i(){if(await l.shouldShowFunnel("status"))return console.log(e.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${e.cyan("npx i18next-cli locize-migrate")} to get started.`),l.recordFunnelShown("status")}exports.runStatus=async function(l,u={}){l.extract.primaryLanguage||=l.locales[0]||"en",l.extract.secondaryLanguages||=l.locales.filter(e=>e!==l?.extract?.primaryLanguage);const d=t("Analyzing project localization status...\n").start();try{const t=await async function(e){e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(t=>t!==e?.extract?.primaryLanguage);const{allKeys:t}=await o.findKeys(e),{secondaryLanguages:l,keySeparator:r=".",defaultNS:c="translation",mergeNamespaces:i=!1,pluralSeparator:u="_"}=e.extract,d=new Map;for(const e of t.values()){const t=e.ns||c||"translation";d.has(t)||d.set(t,[]),d.get(t).push(e)}const y={totalBaseKeys:t.size,keysByNs:d,locales:new Map};for(const t of l){let o=0,l=0;const g=new Map,f=i?await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,t,!1===c?"translation":c||"translation")))||{}:null;for(const[c,y]of d.entries()){const d=i?f?.[c]??f??{}:await n.loadTranslationFile(a.resolve(process.cwd(),n.getOutputPath(e.extract.output,t,c)))||{};let p=0,$=0;const m=[],h=(e,t)=>{try{const a=t?"ordinal":"cardinal";return new Intl.PluralRules(e,{type:a}).resolvedOptions().pluralCategories}catch(e){return new Intl.PluralRules("en",{type:t?"ordinal":"cardinal"}).resolvedOptions().pluralCategories}};for(const{key:e,hasCount:a,isOrdinal:o,isExpandedPlural:n}of y)if(a)if(n){const a=e.split(u),o=a[a.length-1],n=a.length>=2&&"ordinal"===a[a.length-2],l=n?a[a.length-1]:o;if(h(t,n).includes(l)){$++;const t=!!s.getNestedValue(d,e,r??".");t&&p++,m.push({key:e,isTranslated:t})}}else{const a=h(t,o||!1);for(const t of a){$++;const a=o?`${e}${u}ordinal${u}${t}`:`${e}${u}${t}`,n=!!s.getNestedValue(d,a,r??".");n&&p++,m.push({key:a,isTranslated:n})}}else{$++;const t=!!s.getNestedValue(d,e,r??".");t&&p++,m.push({key:e,isTranslated:t})}g.set(c,{totalKeys:$,translatedKeys:p,keyDetails:m}),o+=p,l+=$}y.locales.set(t,{totalKeys:l,totalTranslated:o,namespaces:g})}return y}(l);d.succeed("Analysis complete."),await async function(t,a,o){o.detail?await async function(t,a,o,s){if(o===a.extract.primaryLanguage)return void console.log(e.yellow(`Locale "${o}" is the primary language. All keys are considered present.`));if(!a.locales.includes(o))return void console.error(e.red(`Error: Locale "${o}" is not defined in your configuration.`));const n=t.locales.get(o);if(!n)return void console.error(e.red(`Error: Locale "${o}" is not a valid secondary language.`));console.log(e.bold(`\nKey Status for "${e.cyan(o)}":`));const l=n.totalKeys;r("Overall",n.totalTranslated,l);const c=s?[s]:Array.from(n.namespaces.keys()).sort();for(const t of c){const a=n.namespaces.get(t);a&&(console.log(e.cyan.bold(`\nNamespace: ${t}`)),r("Namespace Progress",a.translatedKeys,a.totalKeys),a.keyDetails.forEach(({key:t,isTranslated:a})=>{const o=a?e.green("✓"):e.red("✗");console.log(` ${o} ${t}`)}))}const u=l-n.totalTranslated;u>0?console.log(e.yellow.bold(`\nSummary: Found ${u} missing translations for "${o}".`)):console.log(e.green.bold(`\nSummary: 🎉 All keys are translated for "${o}".`));await i()}(t,a,o.detail,o.namespace):o.namespace?await async function(t,a,o){const s=t.keysByNs.get(o);if(!s)return void console.error(e.red(`Error: Namespace "${o}" was not found in your source code.`));console.log(e.cyan.bold(`\nStatus for Namespace: "${o}"`)),console.log("------------------------");for(const[e,a]of t.locales.entries()){const t=a.namespaces.get(o);if(t){const a=t.totalKeys>0?Math.round(t.translatedKeys/t.totalKeys*100):100,o=c(a);console.log(`- ${e}: ${o} ${a}% (${t.translatedKeys}/${t.totalKeys} keys)`)}}await i()}(t,0,o.namespace):await async function(t,a){const{primaryLanguage:o}=a.extract;console.log(e.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${e.bold(t.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${e.bold(t.keysByNs.size)}`),console.log(`🌍 Locales: ${e.bold(a.locales.join(", "))}`),console.log(`✅ Primary Language: ${e.bold(o)}`),console.log("\nTranslation Progress:");for(const[e,a]of t.locales.entries()){const t=a.totalKeys>0?Math.round(a.totalTranslated/a.totalKeys*100):100,o=c(t);console.log(`- ${e}: ${o} ${t}% (${a.totalTranslated}/${a.totalKeys} keys)`)}await i()}(t,a)}(t,l,u);let y=!1;for(const[,e]of t.locales.entries())if(e.totalTranslated<e.totalKeys){y=!0;break}y&&(d.fail("Error: Missing translations detected."),process.exit(1))}catch(e){d.fail("Failed to generate status report."),console.error(e)}};
package/dist/esm/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{Command as 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.29.2"),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 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.29.4"),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};
@@ -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 v=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let S;S="JSXAttribute"===v?.type?s(v):void 0,y&&(void 0===S&&(S=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(),v=x?" "+h:h,S=/[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&&!(S&&m&&J&&!c&&!x&&!X),E=f&&"string"==typeof f.value&&/^[,;:!?.]/.test(f.value.trim()),b=$&&!E;S&&m&&J&&!c&&!x&&!X&&l.add(i),u+=c||p&&a||!p&&y&&x||b?v+" ":v;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)throw new Error("Unrecognized expression in JSX placeholder");u+=`{{${e.callee.value}}}`}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,v=1===x.length&&("JSXText"===x[0]?.type||"JSXExpressionContainer"===x[0]?.type&&void 0!==i(x[0].expression)),S="p"===g;let m=0;if(S&&r&&(m=e.filter(e=>e&&"JSXElement"===e.type&&"p"===e.opening?.name?.value).length),!h||v){const i=v?c(x,void 0):"";if(""!==String(i).trim())if(n.has(g)&&"p"!==g)u+=`<${g}>${a(i)}</${g}>`;else if(S&&r&&m>1)u+=`<${g}>${a(i)}</${g}>`;else if(S){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&&!v){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 v(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=v(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(S&&"StringLiteral"===$.type){const e=r.extract.nsSeparator??":",t=$.value;if(e&&t.startsWith(`${S}${e}`)){if(E=t.slice(`${S}${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:S,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;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 +1 @@
1
- import e from"chalk";import o from"ora";import{resolve as t}from"node:path";import{findKeys as a}from"./extractor/core/key-finder.js";import{getNestedValue as s}from"./utils/nested-object.js";import{loadTranslationFile as n,getOutputPath as l}from"./utils/file-utils.js";import{shouldShowFunnel as r,recordFunnelShown as c}from"./utils/funnel-msg-tracker.js";async function i(r,c={}){r.extract.primaryLanguage||=r.locales[0]||"en",r.extract.secondaryLanguages||=r.locales.filter(e=>e!==r?.extract?.primaryLanguage);const i=o("Analyzing project localization status...\n").start();try{const o=await async function(e){e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(o=>o!==e?.extract?.primaryLanguage);const{allKeys:o}=await a(e),{secondaryLanguages:r,keySeparator:c=".",defaultNS:i="translation",mergeNamespaces:d=!1,pluralSeparator:u="_"}=e.extract,y=new Map;for(const e of o.values()){const o=e.ns||i||"translation";y.has(o)||y.set(o,[]),y.get(o).push(e)}const g={totalBaseKeys:o.size,keysByNs:y,locales:new Map};for(const o of r){let a=0,r=0;const f=new Map,p=d?await n(t(process.cwd(),l(e.extract.output,o,!1===i?"translation":i||"translation")))||{}:null;for(const[i,g]of y.entries()){const y=d?p?.[i]??p??{}:await n(t(process.cwd(),l(e.extract.output,o,i)))||{};let m=0,$=0;const w=[],h=(e,o)=>{try{const t=o?"ordinal":"cardinal";return new Intl.PluralRules(e,{type:t}).resolvedOptions().pluralCategories}catch(e){return new Intl.PluralRules("en",{type:o?"ordinal":"cardinal"}).resolvedOptions().pluralCategories}};for(const{key:e,hasCount:t,isOrdinal:a,isExpandedPlural:n}of g)if(t)if(n){const t=e.split(u),a=t[t.length-1],n=t.length>=2&&"ordinal"===t[t.length-2],l=n?t[t.length-1]:a;if(h(o,n).includes(l)){$++;const o=!!s(y,e,c??".");o&&m++,w.push({key:e,isTranslated:o})}}else{const t=h(o,a||!1);for(const o of t){$++;const t=a?`${e}${u}ordinal${u}${o}`:`${e}${u}${o}`,n=!!s(y,t,c??".");n&&m++,w.push({key:t,isTranslated:n})}}else{$++;const o=!!s(y,e,c??".");o&&m++,w.push({key:e,isTranslated:o})}f.set(i,{totalKeys:$,translatedKeys:m,keyDetails:w}),a+=m,r+=$}g.locales.set(o,{totalKeys:r,totalTranslated:a,namespaces:f})}return g}(r);i.succeed("Analysis complete."),await async function(o,t,a){a.detail?await async function(o,t,a,s){if(a===t.extract.primaryLanguage)return void console.log(e.yellow(`Locale "${a}" is the primary language. All keys are considered present.`));if(!t.locales.includes(a))return void console.error(e.red(`Error: Locale "${a}" is not defined in your configuration.`));const n=o.locales.get(a);if(!n)return void console.error(e.red(`Error: Locale "${a}" is not a valid secondary language.`));console.log(e.bold(`\nKey Status for "${e.cyan(a)}":`));const l=Array.from(o.keysByNs.values()).flat().length;d("Overall",n.totalTranslated,n.totalKeys);const r=s?[s]:Array.from(n.namespaces.keys()).sort();for(const o of r){const t=n.namespaces.get(o);t&&(console.log(e.cyan.bold(`\nNamespace: ${o}`)),d("Namespace Progress",t.translatedKeys,t.totalKeys),t.keyDetails.forEach(({key:o,isTranslated:t})=>{const a=t?e.green("✓"):e.red("✗");console.log(` ${a} ${o}`)}))}const c=l-n.totalTranslated;c>0?console.log(e.yellow.bold(`\nSummary: Found ${c} missing translations for "${a}".`)):console.log(e.green.bold(`\nSummary: 🎉 All keys are translated for "${a}".`));await y()}(o,t,a.detail,a.namespace):a.namespace?await async function(o,t,a){const s=o.keysByNs.get(a);if(!s)return void console.error(e.red(`Error: Namespace "${a}" was not found in your source code.`));console.log(e.cyan.bold(`\nStatus for Namespace: "${a}"`)),console.log("------------------------");for(const[e,t]of o.locales.entries()){const o=t.namespaces.get(a);if(o){const t=o.totalKeys>0?Math.round(o.translatedKeys/o.totalKeys*100):100,a=u(t);console.log(`- ${e}: ${a} ${t}% (${o.translatedKeys}/${o.totalKeys} keys)`)}}await y()}(o,0,a.namespace):await async function(o,t){const{primaryLanguage:a}=t.extract;console.log(e.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${e.bold(o.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${e.bold(o.keysByNs.size)}`),console.log(`🌍 Locales: ${e.bold(t.locales.join(", "))}`),console.log(`✅ Primary Language: ${e.bold(a)}`),console.log("\nTranslation Progress:");for(const[e,t]of o.locales.entries()){const o=t.totalKeys>0?Math.round(t.totalTranslated/t.totalKeys*100):100,a=u(o);console.log(`- ${e}: ${a} ${o}% (${t.totalTranslated}/${t.totalKeys} keys)`)}await y()}(o,t)}(o,r,c);let g=!1;for(const[,e]of o.locales.entries())if(e.totalTranslated<o.totalBaseKeys){g=!0;break}g&&(i.fail("Error: Missing translations detected."),process.exit(1))}catch(e){i.fail("Failed to generate status report."),console.error(e)}}function d(o,t,a){const s=a>0?Math.round(t/a*100):100,n=u(s);console.log(`${e.bold(o)}: ${n} ${s}% (${t}/${a})`)}function u(o){const t=Math.floor(o/100*20),a=20-t;return`[${e.green("".padStart(t,"■"))}${"".padStart(a,"□")}]`}async function y(){if(await r("status"))return console.log(e.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${e.cyan("npx i18next-cli locize-migrate")} to get started.`),c("status")}export{i as runStatus};
1
+ import e from"chalk";import o from"ora";import{resolve as t}from"node:path";import{findKeys as a}from"./extractor/core/key-finder.js";import{getNestedValue as s}from"./utils/nested-object.js";import{loadTranslationFile as n,getOutputPath as l}from"./utils/file-utils.js";import{shouldShowFunnel as r,recordFunnelShown as c}from"./utils/funnel-msg-tracker.js";async function i(r,c={}){r.extract.primaryLanguage||=r.locales[0]||"en",r.extract.secondaryLanguages||=r.locales.filter(e=>e!==r?.extract?.primaryLanguage);const i=o("Analyzing project localization status...\n").start();try{const o=await async function(e){e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(o=>o!==e?.extract?.primaryLanguage);const{allKeys:o}=await a(e),{secondaryLanguages:r,keySeparator:c=".",defaultNS:i="translation",mergeNamespaces:d=!1,pluralSeparator:u="_"}=e.extract,y=new Map;for(const e of o.values()){const o=e.ns||i||"translation";y.has(o)||y.set(o,[]),y.get(o).push(e)}const g={totalBaseKeys:o.size,keysByNs:y,locales:new Map};for(const o of r){let a=0,r=0;const f=new Map,p=d?await n(t(process.cwd(),l(e.extract.output,o,!1===i?"translation":i||"translation")))||{}:null;for(const[i,g]of y.entries()){const y=d?p?.[i]??p??{}:await n(t(process.cwd(),l(e.extract.output,o,i)))||{};let m=0,$=0;const w=[],h=(e,o)=>{try{const t=o?"ordinal":"cardinal";return new Intl.PluralRules(e,{type:t}).resolvedOptions().pluralCategories}catch(e){return new Intl.PluralRules("en",{type:o?"ordinal":"cardinal"}).resolvedOptions().pluralCategories}};for(const{key:e,hasCount:t,isOrdinal:a,isExpandedPlural:n}of g)if(t)if(n){const t=e.split(u),a=t[t.length-1],n=t.length>=2&&"ordinal"===t[t.length-2],l=n?t[t.length-1]:a;if(h(o,n).includes(l)){$++;const o=!!s(y,e,c??".");o&&m++,w.push({key:e,isTranslated:o})}}else{const t=h(o,a||!1);for(const o of t){$++;const t=a?`${e}${u}ordinal${u}${o}`:`${e}${u}${o}`,n=!!s(y,t,c??".");n&&m++,w.push({key:t,isTranslated:n})}}else{$++;const o=!!s(y,e,c??".");o&&m++,w.push({key:e,isTranslated:o})}f.set(i,{totalKeys:$,translatedKeys:m,keyDetails:w}),a+=m,r+=$}g.locales.set(o,{totalKeys:r,totalTranslated:a,namespaces:f})}return g}(r);i.succeed("Analysis complete."),await async function(o,t,a){a.detail?await async function(o,t,a,s){if(a===t.extract.primaryLanguage)return void console.log(e.yellow(`Locale "${a}" is the primary language. All keys are considered present.`));if(!t.locales.includes(a))return void console.error(e.red(`Error: Locale "${a}" is not defined in your configuration.`));const n=o.locales.get(a);if(!n)return void console.error(e.red(`Error: Locale "${a}" is not a valid secondary language.`));console.log(e.bold(`\nKey Status for "${e.cyan(a)}":`));const l=n.totalKeys;d("Overall",n.totalTranslated,l);const r=s?[s]:Array.from(n.namespaces.keys()).sort();for(const o of r){const t=n.namespaces.get(o);t&&(console.log(e.cyan.bold(`\nNamespace: ${o}`)),d("Namespace Progress",t.translatedKeys,t.totalKeys),t.keyDetails.forEach(({key:o,isTranslated:t})=>{const a=t?e.green("✓"):e.red("✗");console.log(` ${a} ${o}`)}))}const c=l-n.totalTranslated;c>0?console.log(e.yellow.bold(`\nSummary: Found ${c} missing translations for "${a}".`)):console.log(e.green.bold(`\nSummary: 🎉 All keys are translated for "${a}".`));await y()}(o,t,a.detail,a.namespace):a.namespace?await async function(o,t,a){const s=o.keysByNs.get(a);if(!s)return void console.error(e.red(`Error: Namespace "${a}" was not found in your source code.`));console.log(e.cyan.bold(`\nStatus for Namespace: "${a}"`)),console.log("------------------------");for(const[e,t]of o.locales.entries()){const o=t.namespaces.get(a);if(o){const t=o.totalKeys>0?Math.round(o.translatedKeys/o.totalKeys*100):100,a=u(t);console.log(`- ${e}: ${a} ${t}% (${o.translatedKeys}/${o.totalKeys} keys)`)}}await y()}(o,0,a.namespace):await async function(o,t){const{primaryLanguage:a}=t.extract;console.log(e.cyan.bold("\ni18next Project Status")),console.log("------------------------"),console.log(`🔑 Keys Found: ${e.bold(o.totalBaseKeys)}`),console.log(`📚 Namespaces Found: ${e.bold(o.keysByNs.size)}`),console.log(`🌍 Locales: ${e.bold(t.locales.join(", "))}`),console.log(`✅ Primary Language: ${e.bold(a)}`),console.log("\nTranslation Progress:");for(const[e,t]of o.locales.entries()){const o=t.totalKeys>0?Math.round(t.totalTranslated/t.totalKeys*100):100,a=u(o);console.log(`- ${e}: ${a} ${o}% (${t.totalTranslated}/${t.totalKeys} keys)`)}await y()}(o,t)}(o,r,c);let g=!1;for(const[,e]of o.locales.entries())if(e.totalTranslated<e.totalKeys){g=!0;break}g&&(i.fail("Error: Missing translations detected."),process.exit(1))}catch(e){i.fail("Failed to generate status report."),console.error(e)}}function d(o,t,a){const s=a>0?Math.round(t/a*100):100,n=u(s);console.log(`${e.bold(o)}: ${n} ${s}% (${t}/${a})`)}function u(o){const t=Math.floor(o/100*20),a=20-t;return`[${e.green("".padStart(t,"■"))}${"".padStart(a,"□")}]`}async function y(){if(await r("status"))return console.log(e.yellow.bold("\n✨ Take your localization to the next level!")),console.log("Manage translations with your team in the cloud with locize => https://www.locize.com/docs/getting-started"),console.log(`Run ${e.cyan("npx i18next-cli locize-migrate")} to get started.`),c("status")}export{i as runStatus};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.29.2",
3
+ "version": "1.29.4",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {