i18next-cli 1.22.2 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +8 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/extractor/core/translation-manager.js +1 -1
- package/dist/cjs/extractor/parsers/call-expression-handler.js +1 -1
- package/dist/cjs/extractor/parsers/jsx-handler.js +1 -1
- package/dist/cjs/extractor/parsers/jsx-parser.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/core/translation-manager.js +1 -1
- package/dist/esm/extractor/parsers/call-expression-handler.js +1 -1
- package/dist/esm/extractor/parsers/jsx-handler.js +1 -1
- package/dist/esm/extractor/parsers/jsx-parser.js +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -1
- package/src/extractor/core/translation-manager.ts +86 -2
- package/src/extractor/parsers/call-expression-handler.ts +11 -3
- package/src/extractor/parsers/jsx-handler.ts +19 -10
- package/src/extractor/parsers/jsx-parser.ts +1 -1
- package/src/types.ts +16 -0
- package/types/extractor/core/translation-manager.d.ts.map +1 -1
- package/types/extractor/parsers/call-expression-handler.d.ts.map +1 -1
- package/types/extractor/parsers/jsx-handler.d.ts +2 -1
- package/types/extractor/parsers/jsx-handler.d.ts.map +1 -1
- package/types/types.d.ts +14 -0
- package/types/types.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.23.1](https://github.com/i18next/i18next-cli/compare/v1.23.0...v1.23.1) - 2025-11-10
|
|
9
|
+
|
|
10
|
+
- **Extractor (`<Trans>`):** Fixed self-closing tag formatting in Trans component extraction. Self-closing HTML tags like `<br />` (with space before slash) are now correctly preserved as `<br />` instead of being normalized to `<br/>` (without space). This ensures consistent formatting between source code and extracted translation keys, matching common JSX/HTML conventions and maintaining compatibility with existing translation workflows. [#101](https://github.com/i18next/i18next-cli/issues/101)
|
|
11
|
+
|
|
12
|
+
## [1.23.0](https://github.com/i18next/i18next-cli/compare/v1.22.2...v1.23.0) - 2025-11-09
|
|
13
|
+
|
|
14
|
+
- **Extractor:** Add a `preserveContextVariants` option to keep context variants when removing unused keys. When enabled, all context variants of keys that use context parameters are preserved in translation files even if not explicitly found in source code. [#99](https://github.com/i18next/i18next-cli/pull/99)
|
|
15
|
+
|
|
8
16
|
## [1.22.2](https://github.com/i18next/i18next-cli/compare/v1.22.1...v1.22.2) - 2025-11-08
|
|
9
17
|
|
|
10
18
|
- **Status Command:** Fixed incorrect plural key requirements for languages with different pluralization rules. The status report now correctly evaluates each language based on its own plural categories instead of incorrectly using the primary language's rules. For example, Swedish (which only requires `_one` and `_other` forms) will now show 100% completion when both forms are present, even when other languages in the project like French require additional forms (`_many`). This ensures accurate translation progress reporting across multilingual projects with varying plural rules. [#98](https://github.com/i18next/i18next-cli/issues/98)
|
package/README.md
CHANGED
|
@@ -372,6 +372,14 @@ export default defineConfig({
|
|
|
372
372
|
'dynamic:user.*.profile', // Matches dynamic:user.admin.profile, dynamic:user.guest.profile
|
|
373
373
|
],
|
|
374
374
|
|
|
375
|
+
/**
|
|
376
|
+
* When true, preserves all context variants of keys that use context parameters.
|
|
377
|
+
* For example, if 'friend' is used with context, all variants like 'friend_male',
|
|
378
|
+
* 'friend_female', etc. are preserved even if not explicitly found in source code.
|
|
379
|
+
* (default: false)
|
|
380
|
+
*/
|
|
381
|
+
preserveContextVariants: false,
|
|
382
|
+
|
|
375
383
|
// Output formatting
|
|
376
384
|
sort: true, // can be also a sort function => i.e. (a, b) => a.key > b.key ? -1 : a.key < b.key ? 1 : 0, // sort in reverse order
|
|
377
385
|
indentation: 2, // can be also a string
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),t=require("chokidar"),o=require("glob"),n=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),g=require("./init.js"),d=require("./linter.js"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.
|
|
2
|
+
"use strict";var e=require("commander"),t=require("chokidar"),o=require("glob"),n=require("minimatch"),i=require("chalk"),a=require("./config.js"),r=require("./heuristic-config.js"),c=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var s=require("./types-generator.js"),l=require("./syncer.js"),u=require("./migrator.js"),g=require("./init.js"),d=require("./linter.js"),p=require("./status.js"),f=require("./locize.js");const m=new e.Command;m.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.23.1"),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.").action(async e=>{try{const o=m.opts().config,i=await a.ensureConfig(o),r=async()=>{const t=await c.runExtractor(i,{isWatchMode:!!e.watch,isDryRun:!!e.dryRun,syncPrimaryWithDefaults:!!e.syncPrimary});return e.ci&&!t?(console.log("✅ No files were updated."),process.exit(0)):e.ci&&t&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),t};if(await r(),e.watch){console.log("\nWatching for changes...");const e=await w(i.extract.input),o=y(i.extract.ignore),a=h(i.extract.output),c=[...o,...a].filter(Boolean),s=e.filter(e=>!c.some(t=>n.minimatch(e,t,{dot:!0})));t.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),r()})}}catch(e){console.error("Error running extractor:",e),process.exit(1)}}),m.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,t)=>{const o=m.opts().config;let n=await a.loadConfig(o);if(!n){console.log(i.blue("No config file found. Attempting to detect project structure..."));const e=await r.detectConfig();e||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),n=e}await p.runStatus(n,{detail:e,namespace:t.namespace})}),m.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const o=m.opts().config,i=await a.ensureConfig(o),r=()=>s.runTypesGenerator(i);if(await r(),e.watch){console.log("\nWatching for changes...");const e=await w(i.types?.input||[]),o=[...y(i.extract?.ignore)].filter(Boolean),a=e.filter(e=>!o.some(t=>n.minimatch(e,t,{dot:!0})));t.watch(a,{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),r()})}}),m.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=m.opts().config,t=await a.ensureConfig(e);await l.runSyncer(t)}),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(g.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 o=m.opts().config,c=async()=>{let e=await a.loadConfig(o);if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await r.detectConfig();t||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=t}await d.runLinterCli(e)};if(await c(),e.watch){console.log("\nWatching for changes...");const e=await a.loadConfig(o);if(e?.extract?.input){const o=await w(e.extract.input),i=[...y(e.extract.ignore),...h(e.extract.output)].filter(Boolean),a=o.filter(e=>!i.some(t=>n.minimatch(e,t,{dot:!0})));t.watch(a,{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 t=m.opts().config,o=await a.ensureConfig(t);await f.runLocizeSync(o,e)}),m.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const t=m.opts().config,o=await a.ensureConfig(t);await f.runLocizeDownload(o,e)}),m.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const t=m.opts().config,o=await a.ensureConfig(t);await f.runLocizeMigrate(o,e)}),m.parse(process.argv);const y=e=>Array.isArray(e)?e:e?[e]:[],h=e=>e&&"string"==typeof e?[e.replace(/\{\{[^}]+\}\}/g,"*")]:[],w=async(e=[])=>{const t=y(e),n=await Promise.all(t.map(e=>o.glob(e||"",{nodir:!0})));return Array.from(new Set(n.flat()))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:path"),t=require("glob"),s=require("../../utils/nested-object.js"),n=require("../../utils/file-utils.js"),r=require("../../utils/default-value.js");function o(e){const t=`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(t)}function a(e,t){if("object"!=typeof e||null===e||Array.isArray(e))return e;const s={},n=t?.extract?.pluralSeparator??"_",r=["zero","one","two","few","many","other"],o=r.map(e=>`ordinal${n}${e}`),
|
|
1
|
+
"use strict";var e=require("node:path"),t=require("glob"),s=require("../../utils/nested-object.js"),n=require("../../utils/file-utils.js"),r=require("../../utils/default-value.js");function o(e){const t=`^${e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(t)}function a(e,t,s,n){if(0===t.size)return!1;let r=e;const o=["zero","one","two","few","many","other"];for(const e of o){if(r.endsWith(`${s}${e}`)){r=r.slice(0,-(s.length+e.length));break}if(r.endsWith(`${s}ordinal${s}${e}`)){r=r.slice(0,-(s.length+7+s.length+e.length));break}}const a=r.split(n);if(a.length>1)for(let e=1;e<a.length;e++){const s=a.slice(0,-e).join(n);if(t.has(s))return!0}return!!t.has(r)}function i(e,t){if("object"!=typeof e||null===e||Array.isArray(e))return e;const s={},n=t?.extract?.pluralSeparator??"_",r=["zero","one","two","few","many","other"],o=r.map(e=>`ordinal${n}${e}`),a=Object.keys(e).sort((e,t)=>{const s=e=>{for(const t of o)if(e.endsWith(`${n}${t}`)){return{base:e.slice(0,-(n.length+t.length)),form:t,isOrdinal:!0,isPlural:!0,fullKey:e}}for(const t of r)if(e.endsWith(`${n}${t}`)){return{base:e.slice(0,-(n.length+t.length)),form:t,isOrdinal:!1,isPlural:!0,fullKey:e}}return{base:e,form:"",isOrdinal:!1,isPlural:!1,fullKey:e}},a=s(e),i=s(t);if(a.isPlural&&i.isPlural){const e=a.base.localeCompare(i.base,void 0,{sensitivity:"base"});if(0!==e)return e;if(a.isOrdinal!==i.isOrdinal)return a.isOrdinal?1:-1;const t=a.isOrdinal?o:r,s=t.indexOf(a.form),n=t.indexOf(i.form);return-1!==s&&-1!==n?s-n:a.form.localeCompare(i.form)}const l=e.localeCompare(t,void 0,{sensitivity:"base"});return 0===l?e.localeCompare(t,void 0,{sensitivity:"case"}):l});for(const n of a)s[n]=i(e[n],t);return s}function l(e,t,n,l,c,u=[],f=new Set,d=!1){const{keySeparator:p=".",sort:g=!0,removeUnusedKeys:h=!0,primaryLanguage:y,defaultValue:x="",pluralSeparator:m="_",contextSeparator:O="_",preserveContextVariants:S=!1}=n.extract,$=new Set;if(S)for(const{keyAcceptingContext:t}of e)t&&$.add(t);const v=new Set;let w=[],N=[];try{const e=new Intl.PluralRules(l,{type:"cardinal"}),t=new Intl.PluralRules(l,{type:"ordinal"});w=e.resolvedOptions().pluralCategories,N=t.resolvedOptions().pluralCategories,w.forEach(e=>v.add(e)),t.resolvedOptions().pluralCategories.forEach(e=>v.add(`ordinal_${e}`))}catch(e){const t=y||"en",s=new Intl.PluralRules(t,{type:"cardinal"}),n=new Intl.PluralRules(t,{type:"ordinal"});w=s.resolvedOptions().pluralCategories,N=n.resolvedOptions().pluralCategories,w.forEach(e=>v.add(e)),n.resolvedOptions().pluralCategories.forEach(e=>v.add(`ordinal_${e}`))}const b=n.extract.preservePatterns||[],j="string"==typeof n.extract.nsSeparator?n.extract.nsSeparator:":",k=e=>{if(u.some(t=>t.test(e)))return!0;for(const t of b)if("string"==typeof t){if(t.endsWith(`${j}*`)){const e=t.slice(0,-(j.length+1));if("*"===e||c&&e===c)return!0}if(t.includes(j)&&c){const[s,n]=t.split(j);if(s===c){if(o(n).test(e))return!0}}}return!1},P=e.filter(({key:e,hasCount:t,isOrdinal:s})=>{if((e=>{if(u.some(t=>t.test(e)))return!0;for(const e of b)if("string"==typeof e&&e.endsWith(`${j}*`)){const t=e.slice(0,-(j.length+1));if("*"===t||c&&t===c)return!0}return!1})(e))return!1;if(!t)return!0;const n=e.split(m);if(t&&1===n.length)return!0;if(1===w.length&&"other"===w[0]&&1===n.length)return!0;if(s&&n.includes("ordinal")){const e=n[n.length-1];return v.has(`ordinal_${e}`)}if(t){const e=n[n.length-1];return v.has(e)}return!0}),V=new Set;for(const e of P)if(e.isExpandedPlural){const t=String(e.key).split(m);t.length>=3&&"ordinal"===t[t.length-2]?V.add(t.slice(0,-2).join(m)):V.add(t.slice(0,-1).join(m))}let C=h?{}:JSON.parse(JSON.stringify(t));const W=s.getNestedKeys(t,p??".");for(const e of W){const n=k(e),r=!n&&a(e,$,m,O);if(n||S&&r){const n=s.getNestedValue(t,e,p??".");s.setNestedValue(C,e,n,p??".")}}if(h){const e=s.getNestedKeys(t,p??".");for(const n of e){const e=n.split(m);if("zero"===e[e.length-1]){const r=e.slice(0,-1).join(m);if(P.some(({key:e})=>e.split(m).slice(0,-1).join(m)===r)){const e=s.getNestedValue(t,n,p??".");s.setNestedValue(C,n,e,p??".")}}}}for(const{key:e,defaultValue:o,explicitDefault:a,hasCount:i,isExpandedPlural:u,isOrdinal:g}of P){if(i&&!u){const t=String(e).split(m);let s=e;if(t.length>=3&&"ordinal"===t[t.length-2]?s=t.slice(0,-2).join(m):t.length>=2&&(s=t.slice(0,-1).join(m)),V.has(s))continue}if(i&&!u){if(1===String(e).split(m).length&&l!==y){const a=e;if(V.has(a));else{const e=g?N:w;for(const i of e){const e=g?`${a}${m}ordinal${m}${i}`:`${a}${m}${i}`,u=s.getNestedValue(t,e,p??".");if(void 0===u){let t;t="string"==typeof o?o:r.resolveDefaultValue(x,String(a),c||n?.extract?.defaultNS||"translation",l,o),s.setNestedValue(C,e,t,p??".")}else s.setNestedValue(C,e,u,p??".")}}continue}}const h=s.getNestedValue(t,e,p??"."),S=!1===p||!P.some(t=>t.key!==e&&t.key.startsWith(`${e}${p}`)),$="object"==typeof h&&null!==h&&(f.has(e)||!o||o===e),v="object"==typeof h&&null!==h&&S&&!f.has(e)&&!$;if($){s.setNestedValue(C,e,h,p??".");continue}let b;if(void 0===h||v)if(l===y)if(d){const t=o&&(o===e||o.includes(j)||e!==o&&(e.startsWith(o+m)||e.startsWith(o+O)));b=o&&!t?o:r.resolveDefaultValue(x,e,c||n?.extract?.defaultNS||"translation",l,o)}else b=o||e;else b=r.resolveDefaultValue(x,e,c||n?.extract?.defaultNS||"translation",l,o);else if(l===y&&d){const t=o&&(o===e||o.includes(j)||e!==o&&(e.startsWith(o+m)||e.startsWith(o+O)));b=(e.includes(m)||e.includes(O))&&!a?h:o&&!t?o:h}else b=h;s.setNestedValue(C,e,b,p??".")}if(!0===g)return i(C,n);if("function"==typeof g){const e={},t=Object.keys(C),s=new Map;for(const e of P){const t=!1===p?e.key:e.key.split(p)[0];s.has(t)||s.set(t,e)}t.sort((e,t)=>{if("function"==typeof g){const n=s.get(e),r=s.get(t);if(n&&r)return g(n,r)}return e.localeCompare(t,void 0,{sensitivity:"base"})});for(const s of t)e[s]=i(C[s],n);C=e}return C}exports.getTranslations=async function(s,r,a,{syncPrimaryWithDefaults:i=!1}={}){a.extract.primaryLanguage||=a.locales[0]||"en",a.extract.secondaryLanguages||=a.locales.filter(e=>e!==a?.extract?.primaryLanguage);const c=[...a.extract.preservePatterns||[]],u=a.extract.indentation??2;for(const e of r)c.push(`${e}.*`);const f=c.map(o),d="__no_namespace__",p=new Map;for(const e of s.values()){const t=e.nsIsImplicit&&!1===a.extract.defaultNS?d:String(e.ns??a.extract.defaultNS??"translation");p.has(t)||p.set(t,[]),p.get(t).push(e)}const g=[],h=Array.isArray(a.extract.ignore)?a.extract.ignore:a.extract.ignore?[a.extract.ignore]:[];for(const s of a.locales){if(a.extract.mergeNamespaces||"string"==typeof a.extract.output&&!a.extract.output.includes("{{namespace}}")){const t={},o=n.getOutputPath(a.extract.output,s),c=e.resolve(process.cwd(),o),h=await n.loadTranslationFile(c)||{},y=Object.keys(h),x=!1!==a.extract.defaultNS&&y.some(e=>{const t=h[e];return"object"==typeof t&&null!==t&&!Array.isArray(t)})?new Set([...p.keys(),...y]):new Set([...p.keys(),d]);for(const e of x){const n=p.get(e)||[];if(e===d){const e=l(n,h,a,s,void 0,f,r,i);Object.assign(t,e)}else{const o=h[e]||{};t[e]=l(n,o,a,s,e,f,r,i)}}const m=JSON.stringify(h,null,u),O=JSON.stringify(t,null,u);g.push({path:c,updated:O!==m,newTranslations:t,existingTranslations:h})}else{const o=new Set(p.keys()),c=n.getOutputPath(a.extract.output,s,"*").replace(/\\/g,"/"),d=await t.glob(c,{ignore:h});for(const t of d)o.add(e.basename(t,e.extname(t)));for(const t of o){const o=p.get(t)||[],c=n.getOutputPath(a.extract.output,s,t),d=e.resolve(process.cwd(),c),h=await n.loadTranslationFile(d)||{},y=l(o,h,a,s,t,f,r,i),x=JSON.stringify(h,null,u),m=JSON.stringify(y,null,u);g.push({path:d,updated:m!==x,newTranslations:y,existingTranslations:h})}}}return g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./ast-utils.js");exports.CallExpressionHandler=class{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;constructor(e,t,r,n,o,i){this.config=e,this.pluginContext=t,this.logger=r,this.expressionResolver=n,this.getCurrentFile=o,this.getCurrentCode=i}getLocationFromSpan(e){if(!e||"number"!=typeof e.start)return;const t=this.getCurrentCode(),r=e.start,n=t.substring(0,r).split("\n");return{line:n.length,column:n[n.length-1].length}}handleCallExpression(t,r){const n=this.getFunctionName(t.callee);if(!n)return;const o=r(n),i=this.config.extract.functions||["t","*.t"];let s=void 0!==o;if(!s)for(const e of i)if(e.startsWith("*.")){if(n.endsWith(e.substring(1))){s=!0;break}}else if(e===n){s=!0;break}if(!s||0===t.arguments.length)return;const{keysToProcess:l,isSelectorAPI:a}=this.handleCallExpressionArgument(t,0);if(0===l.length)return;let u=!1;const p=this.config.extract.pluralSeparator??"_";for(let e=0;e<l.length;e++)l[e].endsWith(`${p}ordinal`)&&(u=!0,l[e]=l[e].slice(0,-8));let c,f;if(t.arguments.length>1){const r=t.arguments[1].expression;"ObjectExpression"===r.type?f=r:"StringLiteral"===r.type?c=r.value:"TemplateLiteral"===r.type&&e.isSimpleTemplateLiteral(r)&&(c=r.quasis[0].cooked)}if(t.arguments.length>2){const e=t.arguments[2].expression;"ObjectExpression"===e.type&&(f=e)}const y=f?e.getObjectPropValue(f,"defaultValue"):void 0,g="string"==typeof y?y:c,h=e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1},d="string"==typeof g||h(f),x=h(f),k=Boolean(x||"string"==typeof g&&!("string"==typeof(v=g)&&/{{\s*count\s*}}/.test(v)));var v;for(let r=0;r<l.length;r++){let n,i=l[r];if(f){const t=e.getObjectPropValue(f,"ns");"string"==typeof t&&(n=t)}const s=this.config.extract.nsSeparator??":";if(!n&&s&&i.includes(s)){const e=i.split(s);if(n=e.shift(),i=e.join(s),!i||""===i.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${n}${s}'`);continue}}!n&&o?.defaultNs&&(n=o.defaultNs),n||(n=this.config.extract.defaultNS);let p=i;if(o?.keyPrefix){const e=this.config.extract.keySeparator??".";if(p=!1!==e?o.keyPrefix.endsWith(e)?`${o.keyPrefix}${i}`:`${o.keyPrefix}${e}${i}`:`${o.keyPrefix}${i}`,!1!==e){if(p.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${p}' (keyPrefix: '${o.keyPrefix}', key: '${i}')`);continue}}}const c=r===l.length-1&&g||i;if(f){const t=e.getObjectProperty(f,"context"),r=[];if("StringLiteral"===t?.value?.type||"NumericLiteral"===t?.value.type||"BooleanLiteral"===t?.value.type){const e=`${t.value.value}`,o=this.config.extract.contextSeparator??"_";""!==e&&r.push({key:`${p}${o}${e}`,ns:n,defaultValue:c,explicitDefault:d})}else if(t?.value){const e=this.expressionResolver.resolvePossibleContextStringValues(t.value),o=this.config.extract.contextSeparator??"_";e.length>0&&
|
|
1
|
+
"use strict";var e=require("./ast-utils.js");exports.CallExpressionHandler=class{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;constructor(e,t,r,n,o,i){this.config=e,this.pluginContext=t,this.logger=r,this.expressionResolver=n,this.getCurrentFile=o,this.getCurrentCode=i}getLocationFromSpan(e){if(!e||"number"!=typeof e.start)return;const t=this.getCurrentCode(),r=e.start,n=t.substring(0,r).split("\n");return{line:n.length,column:n[n.length-1].length}}handleCallExpression(t,r){const n=this.getFunctionName(t.callee);if(!n)return;const o=r(n),i=this.config.extract.functions||["t","*.t"];let s=void 0!==o;if(!s)for(const e of i)if(e.startsWith("*.")){if(n.endsWith(e.substring(1))){s=!0;break}}else if(e===n){s=!0;break}if(!s||0===t.arguments.length)return;const{keysToProcess:l,isSelectorAPI:a}=this.handleCallExpressionArgument(t,0);if(0===l.length)return;let u=!1;const p=this.config.extract.pluralSeparator??"_";for(let e=0;e<l.length;e++)l[e].endsWith(`${p}ordinal`)&&(u=!0,l[e]=l[e].slice(0,-8));let c,f;if(t.arguments.length>1){const r=t.arguments[1].expression;"ObjectExpression"===r.type?f=r:"StringLiteral"===r.type?c=r.value:"TemplateLiteral"===r.type&&e.isSimpleTemplateLiteral(r)&&(c=r.quasis[0].cooked)}if(t.arguments.length>2){const e=t.arguments[2].expression;"ObjectExpression"===e.type&&(f=e)}const y=f?e.getObjectPropValue(f,"defaultValue"):void 0,g="string"==typeof y?y:c,h=e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1},d="string"==typeof g||h(f),x=h(f),k=Boolean(x||"string"==typeof g&&!("string"==typeof(v=g)&&/{{\s*count\s*}}/.test(v)));var v;for(let r=0;r<l.length;r++){let n,i=l[r];if(f){const t=e.getObjectPropValue(f,"ns");"string"==typeof t&&(n=t)}const s=this.config.extract.nsSeparator??":";if(!n&&s&&i.includes(s)){const e=i.split(s);if(n=e.shift(),i=e.join(s),!i||""===i.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${n}${s}'`);continue}}!n&&o?.defaultNs&&(n=o.defaultNs),n||(n=this.config.extract.defaultNS);let p=i;if(o?.keyPrefix){const e=this.config.extract.keySeparator??".";if(p=!1!==e?o.keyPrefix.endsWith(e)?`${o.keyPrefix}${i}`:`${o.keyPrefix}${e}${i}`:`${o.keyPrefix}${i}`,!1!==e){if(p.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${p}' (keyPrefix: '${o.keyPrefix}', key: '${i}')`);continue}}}const c=r===l.length-1&&g||i;if(f){const t=e.getObjectProperty(f,"context"),r=[];if("StringLiteral"===t?.value?.type||"NumericLiteral"===t?.value.type||"BooleanLiteral"===t?.value.type){const e=`${t.value.value}`,o=this.config.extract.contextSeparator??"_";""!==e&&r.push({key:`${p}${o}${e}`,ns:n,defaultValue:c,explicitDefault:d})}else if(t?.value){const e=this.expressionResolver.resolvePossibleContextStringValues(t.value),o=this.config.extract.contextSeparator??"_";e.length>0&&e.forEach(e=>{r.push({key:`${p}${o}${e}`,ns:n,defaultValue:c,explicitDefault:d})}),r.push({key:p,ns:n,defaultValue:c,explicitDefault:d,keyAcceptingContext:p})}const o=e=>{if(e){if("KeyValueProperty"===e.type&&e.key){if("Identifier"===e.key.type)return e.key.value;if("StringLiteral"===e.key.type)return e.key.value}return"KeyValueProperty"===e.type&&e.value&&"Identifier"===e.value.type?e.key&&"Identifier"===e.key.type?e.key.value:void 0:"ShorthandProperty"!==e.type&&"Identifier"!==e.type||!e.value?e.key&&"string"==typeof e.key?e.key:void 0:e.value}},i=(()=>{if(!f||!Array.isArray(f.properties))return!1;for(const e of f.properties){if("count"===o(e))return!0}return!1})(),s=(()=>{if(!f||!Array.isArray(f.properties))return!1;for(const e of f.properties){if("ordinal"===o(e))return!("KeyValueProperty"!==e.type||!e.value||"BooleanLiteral"!==e.value.type)&&Boolean(e.value.value)}return!1})();if(i||u){try{const e=u?"ordinal":"cardinal",t=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let o=!1;try{const r=new Intl.PluralRules(t,{type:e}).resolvedOptions().pluralCategories;1===r.length&&"other"===r[0]&&(o=!0)}catch{}if(!o){const t=new Set;for(const r of this.config.locales)try{new Intl.PluralRules(r,{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}catch{new Intl.PluralRules("en",{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}const r=Array.from(t).sort();1===r.length&&"other"===r[0]&&(o=!0)}if(o){if(r.length>0)for(const e of r)this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,hasCount:!0,isOrdinal:u});else this.pluginContext.addKey({key:p,ns:n,defaultValue:c,hasCount:!0,isOrdinal:u});continue}}catch(e){}this.config.extract.disablePlurals?r.length>0?r.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:p,ns:n,defaultValue:c,explicitDefault:d}):this.handlePluralKeys(p,n,f,s||u,g,k);continue}if(r.length>0){r.forEach(this.pluginContext.addKey);continue}!0===e.getObjectPropValue(f,"returnObjects")&&this.objectKeys.add(p)}a&&this.objectKeys.add(p);{const e=t.span?this.getLocationFromSpan(t.span):void 0;this.pluginContext.addKey({key:p,ns:n,defaultValue:c,explicitDefault:d,locations:e?[{file:this.getCurrentFile(),line:e.line,column:e.column}]:void 0})}}}handleCallExpressionArgument(e,t){const r=e.arguments[t].expression,n=[];let o=!1;if("ArrowFunctionExpression"===r.type){const e=this.extractKeyFromSelector(r);e&&(n.push(e),o=!0)}else if("ArrayExpression"===r.type)for(const e of r.elements)e?.expression&&n.push(...this.expressionResolver.resolvePossibleKeyStringValues(e.expression));else n.push(...this.expressionResolver.resolvePossibleKeyStringValues(r));return{keysToProcess:n.filter(e=>!!e),isSelectorAPI:o}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let r=t;const n=[];for(;"MemberExpression"===r.type;){const e=r.property;if("Identifier"===e.type)n.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;n.unshift(e.expression.value)}r=r.object}if(n.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return n.join(t)}return null}handlePluralKeys(t,r,n,o,i,s){try{const l=o?"ordinal":"cardinal",a=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:l});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:l});t.resolvedOptions().pluralCategories.forEach(e=>a.add(e))}const u=Array.from(a).sort(),p=this.config.extract.pluralSeparator??"_",c=e.getObjectPropValue(n,"defaultValue"),f=e.getObjectPropValue(n,`defaultValue${p}other`),y=e.getObjectPropValue(n,`defaultValue${p}ordinal${p}other`),g=e.getObjectProperty(n,"context"),h=[];if(g?.value){const e=this.expressionResolver.resolvePossibleContextStringValues(g.value);if(e.length>0)if("StringLiteral"===g.value.type)for(const r of e)r.length>0&&h.push({key:t,context:r});else{for(const r of e)r.length>0&&h.push({key:t,context:r});!1!==this.config.extract?.generateBasePluralForms&&h.push({key:t})}else h.push({key:t})}else h.push({key:t});const d=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let x=!1;try{const e=new Intl.PluralRules(d,{type:l}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&(x=!0)}catch{x=!1}if(x||1===u.length&&"other"===u[0]){for(const{key:t,context:l}of h){const a=e.getObjectPropValue(n,`defaultValue${p}other`);let u;u="string"==typeof a?a:"string"==typeof c?c:"string"==typeof i?i:l?`${t}_${l}`:t;const f=this.config.extract.contextSeparator??"_",y=l?`${t}${f}${l}`:t;this.pluginContext.addKey({key:y,ns:r,defaultValue:u,hasCount:!0,isOrdinal:o,explicitDefault:Boolean(s||"string"==typeof a)})}return}for(const{key:l,context:a}of h)for(const g of u){const u=o?`defaultValue${p}ordinal${p}${g}`:`defaultValue${p}${g}`,h=e.getObjectPropValue(n,u);let d,x;if(d="string"==typeof h?h:"one"===g&&"string"==typeof c?c:"one"===g&&"string"==typeof i?i:o&&"string"==typeof y?y:o||"string"!=typeof f?"string"==typeof c?c:"string"==typeof i?i:l:f,a){const e=this.config.extract.contextSeparator??"_";x=o?`${l}${e}${a}${p}ordinal${p}${g}`:`${l}${e}${a}${p}${g}`}else x=o?`${l}${p}ordinal${p}${g}`:`${l}${p}${g}`;this.pluginContext.addKey({key:x,ns:r,defaultValue:d,hasCount:!0,isOrdinal:o,explicitDefault:Boolean(s||"string"==typeof h||"string"==typeof f),keyAcceptingContext:void 0!==a?t:void 0})}}catch(o){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const s=i||e.getObjectPropValue(n,"defaultValue");this.pluginContext.addKey({key:t,ns:r,defaultValue:"string"==typeof s?s:t})}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let r=e;for(;"MemberExpression"===r.type;){if("Identifier"!==r.property.type)return null;t.unshift(r.property.value),r=r.object}if("ThisExpression"===r.type)t.unshift("this");else{if("Identifier"!==r.type)return null;t.unshift(r.value)}return t.join(".")}return null}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./jsx-parser.js"),t=require("./ast-utils.js");exports.JSXHandler=class{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;constructor(e,t,n,s
|
|
1
|
+
"use strict";var e=require("./jsx-parser.js"),t=require("./ast-utils.js");exports.JSXHandler=class{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;constructor(e,t,n,o,s){this.config=e,this.pluginContext=t,this.expressionResolver=n,this.getCurrentFile=o,this.getCurrentCode=s}getLocationFromSpan(e){if(!e||"number"!=typeof e.start)return;const t=this.getCurrentCode(),n=e.start,o=t.substring(0,n).split("\n");return{line:o.length,column:o[o.length-1].length}}handleJSXElement(t,n){const o=this.getElementName(t);if(o&&(this.config.extract.transComponents||["Trans"]).includes(o)){const o=e.extractFromTransComponent(t,this.config),s=[];if(o){if(o.keyExpression){const e=this.expressionResolver.resolvePossibleKeyStringValues(o.keyExpression);s.push(...e)}else s.push(o.serializedChildren);let e;const{contextExpression:i,optionsNode:a,defaultValue:l,hasCount:r,isOrdinal:u,serializedChildren:c}=o,f=t.span?this.getLocationFromSpan(t.span):void 0,p=f?[{file:this.getCurrentFile(),line:f.line,column:f.column}]:void 0;if(o.ns){const{ns:t}=o;e=s.map(e=>({key:e,ns:t,defaultValue:l||c,hasCount:r,isOrdinal:u,locations:p}))}else{e=s.map(e=>{const t=this.config.extract.nsSeparator??":";let n;if(t&&e.includes(t)){let o;[n,...o]=e.split(t),e=o.join(t)}return{key:e,ns:n,defaultValue:l||c,hasCount:r,isOrdinal:u,explicitDefault:o.explicitDefault,locations:p}});const i=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"t"===e.name.value);if("JSXAttribute"===i?.type&&"JSXExpressionContainer"===i.value?.type&&"Identifier"===i.value.expression.type){const t=n(i.value.expression.value);t?.defaultNs&&e.forEach(e=>{e.ns||(e.ns=t.defaultNs)})}}if(e.forEach(e=>{e.ns||(e.ns=this.config.extract.defaultNS)}),i&&r)if(this.config.extract.disablePlurals){const t=this.expressionResolver.resolvePossibleContextStringValues(i),n=this.config.extract.contextSeparator??"_";if(t.length>0)if("StringLiteral"===i.type)for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}else{e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})});for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),o=!!n,s=this.expressionResolver.resolvePossibleContextStringValues(i),l=this.config.extract.contextSeparator??"_";if(s.length>0){e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,a,void 0,e.locations,e.key));for(const t of s)for(const n of e){const e=`${n.key}${l}${t}`;this.generatePluralKeysForTrans(e,n.defaultValue,n.ns,o,a,n.explicitDefault,n.locations,n.key)}}else e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,a,e.explicitDefault,e.locations))}else if(i){const t=this.expressionResolver.resolvePossibleContextStringValues(i),n=this.config.extract.contextSeparator??"_";if(t.length>0){for(const o of t)for(const{key:t,ns:s,defaultValue:i,locations:a}of e)this.pluginContext.addKey({key:`${t}${n}${o}`,ns:s,defaultValue:i,locations:a,keyAcceptingContext:t});"StringLiteral"!==i.type&&e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}else if(r)if(this.config.extract.disablePlurals)e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})});else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),o=!!n;e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,a,e.explicitDefault,e.locations))}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}}}generatePluralKeysForTrans(e,n,o,s,i,a,l,r){try{const u=s?"ordinal":"cardinal",c=new Intl.PluralRules(this.config.extract?.primaryLanguage,{type:u}).resolvedOptions().pluralCategories,f=this.config.extract.pluralSeparator??"_";let p,d;if(i&&(p=t.getObjectPropValue(i,`defaultValue${f}other`),d=t.getObjectPropValue(i,`defaultValue${f}ordinal${f}other`)),1===c.length&&"other"===c[0]){const u=i?t.getObjectPropValue(i,`defaultValue${f}other`):void 0,c="string"==typeof u?u:"string"==typeof n?n:e;return void this.pluginContext.addKey({key:e,ns:o,defaultValue:c,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(a||"string"==typeof u||"string"==typeof p),locations:l,keyAcceptingContext:r})}for(const u of c){const c=s?`defaultValue${f}ordinal${f}${u}`:`defaultValue${f}${u}`,y=i?t.getObjectPropValue(i,c):void 0;let g;g="string"==typeof y?y:"one"===u&&"string"==typeof n?n:s&&"string"==typeof d?d:s||"string"!=typeof p?"string"==typeof n?n:e:p;const h=s?`${e}${f}ordinal${f}${u}`:`${e}${f}${u}`;this.pluginContext.addKey({key:h,ns:o,defaultValue:g,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(a||"string"==typeof y||"string"==typeof p),locations:l,keyAcceptingContext:r})}}catch(t){this.pluginContext.addKey({key:e,ns:o,defaultValue:n,locations:l})}}getElementName(e){if("Identifier"===e.opening.name.type)return e.opening.name.value;if("JSXMemberExpression"===e.opening.name.type){let t=e.opening.name;const n=[];for(;"JSXMemberExpression"===t.type;)"Identifier"===t.property.type&&n.unshift(t.property.value),t=t.object;return"Identifier"===t.type&&n.unshift(t.value),n.join(".")}}};
|
|
@@ -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,r){const s=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.getObjectProperty(l.value.expression,"count"));const u=!!p||!!a,y=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),f="JSXAttribute"===y?.type&&"JSXExpressionContainer"===y.value?.type&&"ObjectExpression"===y.value.expression.type?y.value.expression:void 0,c=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),v=!!c,S=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let d="JSXAttribute"===S?.type&&"JSXExpressionContainer"===S.value?.type?S.value.expression:"JSXAttribute"===S?.type&&"StringLiteral"===S.value?.type?S.value:void 0;const g=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let x;if(x="JSXAttribute"===g?.type?n(g):void 0,f&&(void 0===x&&(x=e.getObjectPropValue(f,"ns")),void 0===d)){const t=e.getObjectProperty(f,"context");t?.value&&(d=t.value)}const m=function(e,n){if(!e||0===e.length)return"";const i=new Set(n.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),r=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function s(e,n,o=!1){if(!e||!e.length)return;let p=0,l=e.length-1;for(;p<=l&&r(e[p]);)p++;for(;l>=p&&r(e[l]);)l--;const a=p<=l?e.slice(p,l+1):[],u=a.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<a.length;e++){const p=a[e];if(p)if("JSXText"!==p.type){if("JSXExpressionContainer"===p.type){if(o&&!u&&p.expression){const e=p.expression.type;if("ObjectExpression"===e){const e=p.expression.properties&&p.expression.properties[0];if(e&&"KeyValueProperty"===e.type)continue}const n=t(p.expression);if(void 0!==n){if(!(/^\s*$/.test(n)&&!n.includes("\n")))continue}else if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const i=t(p.expression);if(void 0!==i){const t=/^\s*$/.test(i)&&!i.includes("\n"),s=a[e-1],o=a[e+1];if(t){const t=a[e+2];if(o&&"JSXText"===o.type&&r(o)&&t&&("JSXElement"===t.type||"JSXFragment"===t.type)){const t=a[e-1],n=a[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue;const i=!o||"JSXText"===o.type&&!r(o);if(s&&"JSXText"===s.type&&i){const e=n[n.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+p.expression.value;continue}}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue}}n.push(p);continue}if("JSXElement"===p.type){const e=p.opening&&p.opening.name&&"Identifier"===p.opening.name.type?p.opening.name.value:void 0;if(e&&i.has(e)){!(!p.opening||!p.opening.selfClosing)&&n.push(p),s(p.children||[],n,!1)}else n.push(p),s(p.children||[],n,!0);continue}"JSXFragment"!==p.type||s(p.children||[],n,o)}else{if(o&&!u)continue;if(o&&r(p))continue;if(r(p)){const t=a[e-1],i=a[e+1];if(t&&("JSXElement"===t.type||"JSXFragment"===t.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const r=n[n.length-1],s=a[e-1];if(r){if(s&&"JSXExpressionContainer"===s.type)continue;if("JSXText"===r.type&&s&&"JSXText"===s.type){r.value=String(r.value)+p.value;continue}}}if(o&&u&&0===e)continue;n.push(p)}}}const o=[];s(e,o,!1);const p=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function l(e,n){if(!e||0===e.length)return"";let s="",a=!1;for(let u=0;u<e.length;u++){const y=e[u];if(y)if("JSXText"!==y.type){if("JSXExpressionContainer"===y.type){const e=y.expression;if(!e)continue;const n=t(e);if(void 0!==n)s+=n;else if("Identifier"===e.type)s+=`{{${e.value}}}`;else if("ObjectExpression"===e.type){const t=e.properties[0];t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type?s+=`{{${t.key.value}}}`:t&&"Identifier"===t.type?s+=`{{${t.value}}}`:s+="{{value}}"}else"MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type?s+=`{{${e.property.value}}}`:"CallExpression"===e.type&&"Identifier"===e.callee?.type?s+=`{{${e.callee.value}}}`:s+="{{value}}";a=!1;continue}if("JSXElement"===y.type){let t;if(y.opening&&y.opening.name&&"Identifier"===y.opening.name.type&&(t=y.opening.name.value),t&&i.has(t)){const i=l(y.children||[],n),r=!(!y.opening||!y.opening.selfClosing),o=""!==String(i).trim();if(r||!o){const n=e[u-1];n&&"JSXText"===n.type&&/\n\s*$/.test(n.value)&&(s=s.replace(/\s+$/,"")),s+=`<${t}/>`,a=!0}else s+=`<${t}>${i}</${t}>`,a=!1}else{const e=y.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(y),n=l(e,void 0);s+=`<${t}>${p(n)}</${t}>`,a=!1}else{const t=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)){!(!n.opening||!n.opening.selfClosing)&&t.set(n,r++)}else t.set(n,r++)}const u=n&&n.has(y)?n.get(y):o.indexOf(y),f=l(e,t.size?t:void 0);s+=`<${u}>${p(f)}</${u}>`,a=!1}}continue}"JSXFragment"!==y.type||(s+=l(y.children||[]),a=!1)}else{if(r(y))continue;a?(s+=y.value.replace(/^\s+/,""),a=!1):s+=y.value}}return s}const a=l(e);return String(a).replace(/\s+/g," ").trim()}(i.children,r);let J;const X="JSXAttribute"===o?.type?n(o):void 0;if(void 0!==X)J=X;else{const e=r.extract.defaultValue;J="string"==typeof e?e:""}let b,E;if("JSXAttribute"===s?.type){if("StringLiteral"===s.value?.type){if(b=s.value,E=b.value,!E||""===E.trim())return null;if(x&&"StringLiteral"===b.type){const e=r.extract.nsSeparator??":",t=b.value;if(e&&t.startsWith(`${x}${e}`)){if(E=t.slice(`${x}${e}`.length),!E||""===E.trim())return null;b={...b,value:E}}}}else"JSXExpressionContainer"===s.value?.type&&"JSXEmptyExpression"!==s.value.expression.type&&(b=s.value.expression);if(!b)return null}return o||!E||m.trim()?!o&&m.trim()&&(J=m):J=E,{keyExpression:b,serializedChildren:m,ns:x,defaultValue:J,hasCount:u,isOrdinal:v,contextExpression:d,optionsNode:f,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})(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,r){const s=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.getObjectProperty(l.value.expression,"count"));const u=!!p||!!a,y=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),f="JSXAttribute"===y?.type&&"JSXExpressionContainer"===y.value?.type&&"ObjectExpression"===y.value.expression.type?y.value.expression:void 0,c=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),v=!!c,S=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let d="JSXAttribute"===S?.type&&"JSXExpressionContainer"===S.value?.type?S.value.expression:"JSXAttribute"===S?.type&&"StringLiteral"===S.value?.type?S.value:void 0;const g=i.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let x;if(x="JSXAttribute"===g?.type?n(g):void 0,f&&(void 0===x&&(x=e.getObjectPropValue(f,"ns")),void 0===d)){const t=e.getObjectProperty(f,"context");t?.value&&(d=t.value)}const m=function(e,n){if(!e||0===e.length)return"";const i=new Set(n.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),r=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function s(e,n,o=!1){if(!e||!e.length)return;let p=0,l=e.length-1;for(;p<=l&&r(e[p]);)p++;for(;l>=p&&r(e[l]);)l--;const a=p<=l?e.slice(p,l+1):[],u=a.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<a.length;e++){const p=a[e];if(p)if("JSXText"!==p.type){if("JSXExpressionContainer"===p.type){if(o&&!u&&p.expression){const e=p.expression.type;if("ObjectExpression"===e){const e=p.expression.properties&&p.expression.properties[0];if(e&&"KeyValueProperty"===e.type)continue}const n=t(p.expression);if(void 0!==n){if(!(/^\s*$/.test(n)&&!n.includes("\n")))continue}else if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const i=t(p.expression);if(void 0!==i){const t=/^\s*$/.test(i)&&!i.includes("\n"),s=a[e-1],o=a[e+1];if(t){const t=a[e+2];if(o&&"JSXText"===o.type&&r(o)&&t&&("JSXElement"===t.type||"JSXFragment"===t.type)){const t=a[e-1],n=a[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue;const i=!o||"JSXText"===o.type&&!r(o);if(s&&"JSXText"===s.type&&i){const e=n[n.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+p.expression.value;continue}}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue}}n.push(p);continue}if("JSXElement"===p.type){const e=p.opening&&p.opening.name&&"Identifier"===p.opening.name.type?p.opening.name.value:void 0;if(e&&i.has(e)){!(!p.opening||!p.opening.selfClosing)&&n.push(p),s(p.children||[],n,!1)}else n.push(p),s(p.children||[],n,!0);continue}"JSXFragment"!==p.type||s(p.children||[],n,o)}else{if(o&&!u)continue;if(o&&r(p))continue;if(r(p)){const t=a[e-1],i=a[e+1];if(t&&("JSXElement"===t.type||"JSXFragment"===t.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const r=n[n.length-1],s=a[e-1];if(r){if(s&&"JSXExpressionContainer"===s.type)continue;if("JSXText"===r.type&&s&&"JSXText"===s.type){r.value=String(r.value)+p.value;continue}}}if(o&&u&&0===e)continue;n.push(p)}}}const o=[];s(e,o,!1);const p=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function l(e,n){if(!e||0===e.length)return"";let s="",a=!1;for(let u=0;u<e.length;u++){const y=e[u];if(y)if("JSXText"!==y.type){if("JSXExpressionContainer"===y.type){const e=y.expression;if(!e)continue;const n=t(e);if(void 0!==n)s+=n;else if("Identifier"===e.type)s+=`{{${e.value}}}`;else if("ObjectExpression"===e.type){const t=e.properties[0];t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type?s+=`{{${t.key.value}}}`:t&&"Identifier"===t.type?s+=`{{${t.value}}}`:s+="{{value}}"}else"MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type?s+=`{{${e.property.value}}}`:"CallExpression"===e.type&&"Identifier"===e.callee?.type?s+=`{{${e.callee.value}}}`:s+="{{value}}";a=!1;continue}if("JSXElement"===y.type){let t;if(y.opening&&y.opening.name&&"Identifier"===y.opening.name.type&&(t=y.opening.name.value),t&&i.has(t)){const i=l(y.children||[],n),r=!(!y.opening||!y.opening.selfClosing),o=""!==String(i).trim();if(r||!o){const n=e[u-1];n&&"JSXText"===n.type&&/\n\s*$/.test(n.value)&&(s=s.replace(/\s+$/,"")),s+=`<${t} />`,a=!0}else s+=`<${t}>${i}</${t}>`,a=!1}else{const e=y.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(y),n=l(e,void 0);s+=`<${t}>${p(n)}</${t}>`,a=!1}else{const t=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)){!(!n.opening||!n.opening.selfClosing)&&t.set(n,r++)}else t.set(n,r++)}const u=n&&n.has(y)?n.get(y):o.indexOf(y),f=l(e,t.size?t:void 0);s+=`<${u}>${p(f)}</${u}>`,a=!1}}continue}"JSXFragment"!==y.type||(s+=l(y.children||[]),a=!1)}else{if(r(y))continue;a?(s+=y.value.replace(/^\s+/,""),a=!1):s+=y.value}}return s}const a=l(e);return String(a).replace(/\s+/g," ").trim()}(i.children,r);let J;const X="JSXAttribute"===o?.type?n(o):void 0;if(void 0!==X)J=X;else{const e=r.extract.defaultValue;J="string"==typeof e?e:""}let b,E;if("JSXAttribute"===s?.type){if("StringLiteral"===s.value?.type){if(b=s.value,E=b.value,!E||""===E.trim())return null;if(x&&"StringLiteral"===b.type){const e=r.extract.nsSeparator??":",t=b.value;if(e&&t.startsWith(`${x}${e}`)){if(E=t.slice(`${x}${e}`.length),!E||""===E.trim())return null;b={...b,value:E}}}}else"JSXExpressionContainer"===s.value?.type&&"JSXEmptyExpression"!==s.value.expression.type&&(b=s.value.expression);if(!b)return null}return o||!E||m.trim()?!o&&m.trim()&&(J=m):J=E,{keyExpression:b,serializedChildren:m,ns:x,defaultValue:J,hasCount:u,isOrdinal:v,contextExpression:d,optionsNode:f,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})(f)}};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as t}from"commander";import o from"chokidar";import{glob as e}from"glob";import{minimatch as i}from"minimatch";import n from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as f}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";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.
|
|
2
|
+
import{Command as t}from"commander";import o from"chokidar";import{glob as e}from"glob";import{minimatch as i}from"minimatch";import n from"chalk";import{ensureConfig as a,loadConfig as r}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as s}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as l}from"./types-generator.js";import{runSyncer as p}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as f}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";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.23.1"),w.option("-c, --config <path>","Path to i18next-cli config file (overrides detection)"),w.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").option("--sync-primary","Sync primary language values with default values from code.").action(async t=>{try{const e=w.opts().config,n=await a(e),r=async()=>{const o=await s(n,{isWatchMode:!!t.watch,isDryRun:!!t.dryRun,syncPrimaryWithDefaults:!!t.syncPrimary});return t.ci&&!o?(console.log("✅ No files were updated."),process.exit(0)):t.ci&&o&&(console.error("❌ Some files were updated. This should not happen in CI mode."),process.exit(1)),o};if(await r(),t.watch){console.log("\nWatching for changes...");const t=await z(n.extract.input),e=x(n.extract.ignore),a=j(n.extract.output),c=[...e,...a].filter(Boolean),s=t.filter(t=>!c.some(o=>i(t,o,{dot:!0})));o.watch(s,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),r()})}}catch(t){console.error("Error running extractor:",t),process.exit(1)}}),w.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(t,o)=>{const e=w.opts().config;let i=await r(e);if(!i){console.log(n.blue("No config file found. Attempting to detect project structure..."));const t=await c();t||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),i=t}await g(i,{detail:t,namespace:o.namespace})}),w.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async t=>{const e=w.opts().config,n=await a(e),r=()=>l(n);if(await r(),t.watch){console.log("\nWatching for changes...");const t=await z(n.types?.input||[]),e=[...x(n.extract?.ignore)].filter(Boolean),a=t.filter(t=>!e.some(o=>i(t,o,{dot:!0})));o.watch(a,{persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),r()})}}),w.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const t=w.opts().config,o=await a(t);await p(o)}),w.command("migrate-config [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async t=>{await m(t)}),w.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(f),w.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async t=>{const e=w.opts().config,a=async()=>{let t=await r(e);if(!t){console.log(n.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),t=o}await d(t)};if(await a(),t.watch){console.log("\nWatching for changes...");const t=await r(e);if(t?.extract?.input){const e=await z(t.extract.input),n=[...x(t.extract.ignore),...j(t.extract.output)].filter(Boolean),r=e.filter(t=>!n.some(o=>i(t,o,{dot:!0})));o.watch(r,{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),a()})}}}),w.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async t=>{const o=w.opts().config,e=await a(o);await u(e,t)}),w.command("locize-download").description("Download all translations from your locize project.").action(async t=>{const o=w.opts().config,e=await a(o);await y(e,t)}),w.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async t=>{const o=w.opts().config,e=await a(o);await h(e,t)}),w.parse(process.argv);const x=t=>Array.isArray(t)?t:t?[t]:[],j=t=>t&&"string"==typeof t?[t.replace(/\{\{[^}]+\}\}/g,"*")]:[],z=async(t=[])=>{const o=x(t),i=await Promise.all(o.map(t=>e(t||"",{nodir:!0})));return Array.from(new Set(i.flat()))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolve as t,basename as e,extname as n}from"node:path";import{glob as r}from"glob";import{getNestedKeys as s,getNestedValue as o,setNestedValue as i}from"../../utils/nested-object.js";import{getOutputPath as a,loadTranslationFile as l}from"../../utils/file-utils.js";import{resolveDefaultValue as c}from"../../utils/default-value.js";function f(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function u(t,e){if("object"!=typeof t||null===t||Array.isArray(t))return t;const n={},r=e?.extract?.pluralSeparator??"_",s=["zero","one","two","few","many","other"],o=s.map(t=>`ordinal${r}${t}`),i=Object.keys(t).sort((t,e)=>{const n=t=>{for(const e of o)if(t.endsWith(`${r}${e}`)){return{base:t.slice(0,-(r.length+e.length)),form:e,isOrdinal:!0,isPlural:!0,fullKey:t}}for(const e of s)if(t.endsWith(`${r}${e}`)){return{base:t.slice(0,-(r.length+e.length)),form:e,isOrdinal:!1,isPlural:!0,fullKey:t}}return{base:t,form:"",isOrdinal:!1,isPlural:!1,fullKey:t}},i=n(t),a=n(e);if(i.isPlural&&a.isPlural){const t=i.base.localeCompare(a.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(i.isOrdinal!==a.isOrdinal)return i.isOrdinal?1:-1;const e=i.isOrdinal?o:s,n=e.indexOf(i.form),r=e.indexOf(a.form);return-1!==n&&-1!==r?n-r:i.form.localeCompare(a.form)}const l=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===l?t.localeCompare(e,void 0,{sensitivity:"case"}):l});for(const r of i)n[r]=
|
|
1
|
+
import{resolve as t,basename as e,extname as n}from"node:path";import{glob as r}from"glob";import{getNestedKeys as s,getNestedValue as o,setNestedValue as i}from"../../utils/nested-object.js";import{getOutputPath as a,loadTranslationFile as l}from"../../utils/file-utils.js";import{resolveDefaultValue as c}from"../../utils/default-value.js";function f(t){const e=`^${t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`;return new RegExp(e)}function u(t,e,n,r){if(0===e.size)return!1;let s=t;const o=["zero","one","two","few","many","other"];for(const t of o){if(s.endsWith(`${n}${t}`)){s=s.slice(0,-(n.length+t.length));break}if(s.endsWith(`${n}ordinal${n}${t}`)){s=s.slice(0,-(n.length+7+n.length+t.length));break}}const i=s.split(r);if(i.length>1)for(let t=1;t<i.length;t++){const n=i.slice(0,-t).join(r);if(e.has(n))return!0}return!!e.has(s)}function p(t,e){if("object"!=typeof t||null===t||Array.isArray(t))return t;const n={},r=e?.extract?.pluralSeparator??"_",s=["zero","one","two","few","many","other"],o=s.map(t=>`ordinal${r}${t}`),i=Object.keys(t).sort((t,e)=>{const n=t=>{for(const e of o)if(t.endsWith(`${r}${e}`)){return{base:t.slice(0,-(r.length+e.length)),form:e,isOrdinal:!0,isPlural:!0,fullKey:t}}for(const e of s)if(t.endsWith(`${r}${e}`)){return{base:t.slice(0,-(r.length+e.length)),form:e,isOrdinal:!1,isPlural:!0,fullKey:t}}return{base:t,form:"",isOrdinal:!1,isPlural:!1,fullKey:t}},i=n(t),a=n(e);if(i.isPlural&&a.isPlural){const t=i.base.localeCompare(a.base,void 0,{sensitivity:"base"});if(0!==t)return t;if(i.isOrdinal!==a.isOrdinal)return i.isOrdinal?1:-1;const e=i.isOrdinal?o:s,n=e.indexOf(i.form),r=e.indexOf(a.form);return-1!==n&&-1!==r?n-r:i.form.localeCompare(a.form)}const l=t.localeCompare(e,void 0,{sensitivity:"base"});return 0===l?t.localeCompare(e,void 0,{sensitivity:"case"}):l});for(const r of i)n[r]=p(t[r],e);return n}function d(t,e,n,r,a,l=[],d=new Set,g=!1){const{keySeparator:h=".",sort:y=!0,removeUnusedKeys:m=!0,primaryLanguage:x,defaultValue:S="",pluralSeparator:$="_",contextSeparator:O="_",preserveContextVariants:w=!1}=n.extract,v=new Set;if(w)for(const{keyAcceptingContext:e}of t)e&&v.add(e);const b=new Set;let j=[],k=[];try{const t=new Intl.PluralRules(r,{type:"cardinal"}),e=new Intl.PluralRules(r,{type:"ordinal"});j=t.resolvedOptions().pluralCategories,k=e.resolvedOptions().pluralCategories,j.forEach(t=>b.add(t)),e.resolvedOptions().pluralCategories.forEach(t=>b.add(`ordinal_${t}`))}catch(t){const e=x||"en",n=new Intl.PluralRules(e,{type:"cardinal"}),r=new Intl.PluralRules(e,{type:"ordinal"});j=n.resolvedOptions().pluralCategories,k=r.resolvedOptions().pluralCategories,j.forEach(t=>b.add(t)),r.resolvedOptions().pluralCategories.forEach(t=>b.add(`ordinal_${t}`))}const C=n.extract.preservePatterns||[],P="string"==typeof n.extract.nsSeparator?n.extract.nsSeparator:":",N=t=>{if(l.some(e=>e.test(t)))return!0;for(const e of C)if("string"==typeof e){if(e.endsWith(`${P}*`)){const t=e.slice(0,-(P.length+1));if("*"===t||a&&t===a)return!0}if(e.includes(P)&&a){const[n,r]=e.split(P);if(n===a){if(f(r).test(t))return!0}}}return!1},W=t.filter(({key:t,hasCount:e,isOrdinal:n})=>{if((t=>{if(l.some(e=>e.test(t)))return!0;for(const t of C)if("string"==typeof t&&t.endsWith(`${P}*`)){const e=t.slice(0,-(P.length+1));if("*"===e||a&&e===a)return!0}return!1})(t))return!1;if(!e)return!0;const r=t.split($);if(e&&1===r.length)return!0;if(1===j.length&&"other"===j[0]&&1===r.length)return!0;if(n&&r.includes("ordinal")){const t=r[r.length-1];return b.has(`ordinal_${t}`)}if(e){const t=r[r.length-1];return b.has(t)}return!0}),_=new Set;for(const t of W)if(t.isExpandedPlural){const e=String(t.key).split($);e.length>=3&&"ordinal"===e[e.length-2]?_.add(e.slice(0,-2).join($)):_.add(e.slice(0,-1).join($))}let A=m?{}:JSON.parse(JSON.stringify(e));const E=s(e,h??".");for(const t of E){const n=N(t),r=!n&&u(t,v,$,O);if(n||w&&r){const n=o(e,t,h??".");i(A,t,n,h??".")}}if(m){const t=s(e,h??".");for(const n of t){const t=n.split($);if("zero"===t[t.length-1]){const r=t.slice(0,-1).join($);if(W.some(({key:t})=>t.split($).slice(0,-1).join($)===r)){const t=o(e,n,h??".");i(A,n,t,h??".")}}}}for(const{key:t,defaultValue:s,explicitDefault:l,hasCount:f,isExpandedPlural:u,isOrdinal:p}of W){if(f&&!u){const e=String(t).split($);let n=t;if(e.length>=3&&"ordinal"===e[e.length-2]?n=e.slice(0,-2).join($):e.length>=2&&(n=e.slice(0,-1).join($)),_.has(n))continue}if(f&&!u){if(1===String(t).split($).length&&r!==x){const l=t;if(_.has(l));else{const t=p?k:j;for(const f of t){const t=p?`${l}${$}ordinal${$}${f}`:`${l}${$}${f}`,u=o(e,t,h??".");if(void 0===u){let e;e="string"==typeof s?s:c(S,String(l),a||n?.extract?.defaultNS||"translation",r,s),i(A,t,e,h??".")}else i(A,t,u,h??".")}}continue}}const y=o(e,t,h??"."),m=!1===h||!W.some(e=>e.key!==t&&e.key.startsWith(`${t}${h}`)),w="object"==typeof y&&null!==y&&(d.has(t)||!s||s===t),v="object"==typeof y&&null!==y&&m&&!d.has(t)&&!w;if(w){i(A,t,y,h??".");continue}let b;if(void 0===y||v)if(r===x)if(g){const e=s&&(s===t||s.includes(P)||t!==s&&(t.startsWith(s+$)||t.startsWith(s+O)));b=s&&!e?s:c(S,t,a||n?.extract?.defaultNS||"translation",r,s)}else b=s||t;else b=c(S,t,a||n?.extract?.defaultNS||"translation",r,s);else if(r===x&&g){const e=s&&(s===t||s.includes(P)||t!==s&&(t.startsWith(s+$)||t.startsWith(s+O)));b=(t.includes($)||t.includes(O))&&!l?y:s&&!e?s:y}else b=y;i(A,t,b,h??".")}if(!0===y)return p(A,n);if("function"==typeof y){const t={},e=Object.keys(A),r=new Map;for(const t of W){const e=!1===h?t.key:t.key.split(h)[0];r.has(e)||r.set(e,t)}e.sort((t,e)=>{if("function"==typeof y){const n=r.get(t),s=r.get(e);if(n&&s)return y(n,s)}return t.localeCompare(e,void 0,{sensitivity:"base"})});for(const r of e)t[r]=p(A[r],n);A=t}return A}async function g(s,o,i,{syncPrimaryWithDefaults:c=!1}={}){i.extract.primaryLanguage||=i.locales[0]||"en",i.extract.secondaryLanguages||=i.locales.filter(t=>t!==i?.extract?.primaryLanguage);const u=[...i.extract.preservePatterns||[]],p=i.extract.indentation??2;for(const t of o)u.push(`${t}.*`);const g=u.map(f),h="__no_namespace__",y=new Map;for(const t of s.values()){const e=t.nsIsImplicit&&!1===i.extract.defaultNS?h:String(t.ns??i.extract.defaultNS??"translation");y.has(e)||y.set(e,[]),y.get(e).push(t)}const m=[],x=Array.isArray(i.extract.ignore)?i.extract.ignore:i.extract.ignore?[i.extract.ignore]:[];for(const s of i.locales){if(i.extract.mergeNamespaces||"string"==typeof i.extract.output&&!i.extract.output.includes("{{namespace}}")){const e={},n=a(i.extract.output,s),r=t(process.cwd(),n),f=await l(r)||{},u=Object.keys(f),x=!1!==i.extract.defaultNS&&u.some(t=>{const e=f[t];return"object"==typeof e&&null!==e&&!Array.isArray(e)})?new Set([...y.keys(),...u]):new Set([...y.keys(),h]);for(const t of x){const n=y.get(t)||[];if(t===h){const t=d(n,f,i,s,void 0,g,o,c);Object.assign(e,t)}else{const r=f[t]||{};e[t]=d(n,r,i,s,t,g,o,c)}}const S=JSON.stringify(f,null,p),$=JSON.stringify(e,null,p);m.push({path:r,updated:$!==S,newTranslations:e,existingTranslations:f})}else{const f=new Set(y.keys()),u=a(i.extract.output,s,"*").replace(/\\/g,"/"),h=await r(u,{ignore:x});for(const t of h)f.add(e(t,n(t)));for(const e of f){const n=y.get(e)||[],r=a(i.extract.output,s,e),f=t(process.cwd(),r),u=await l(f)||{},h=d(n,u,i,s,e,g,o,c),x=JSON.stringify(u,null,p),S=JSON.stringify(h,null,p);m.push({path:f,updated:S!==x,newTranslations:h,existingTranslations:u})}}}return m}export{g as getTranslations};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isSimpleTemplateLiteral as e,getObjectPropValue as t,getObjectProperty as r}from"./ast-utils.js";class n{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;constructor(e,t,r,n,i,
|
|
1
|
+
import{isSimpleTemplateLiteral as e,getObjectPropValue as t,getObjectProperty as r}from"./ast-utils.js";class n{pluginContext;config;logger;expressionResolver;objectKeys=new Set;getCurrentFile;getCurrentCode;constructor(e,t,r,n,i,o){this.config=e,this.pluginContext=t,this.logger=r,this.expressionResolver=n,this.getCurrentFile=i,this.getCurrentCode=o}getLocationFromSpan(e){if(!e||"number"!=typeof e.start)return;const t=this.getCurrentCode(),r=e.start,n=t.substring(0,r).split("\n");return{line:n.length,column:n[n.length-1].length}}handleCallExpression(n,i){const o=this.getFunctionName(n.callee);if(!o)return;const s=i(o),l=this.config.extract.functions||["t","*.t"];let a=void 0!==s;if(!a)for(const e of l)if(e.startsWith("*.")){if(o.endsWith(e.substring(1))){a=!0;break}}else if(e===o){a=!0;break}if(!a||0===n.arguments.length)return;const{keysToProcess:u,isSelectorAPI:f}=this.handleCallExpressionArgument(n,0);if(0===u.length)return;let c=!1;const p=this.config.extract.pluralSeparator??"_";for(let e=0;e<u.length;e++)u[e].endsWith(`${p}ordinal`)&&(c=!0,u[e]=u[e].slice(0,-8));let y,g;if(n.arguments.length>1){const t=n.arguments[1].expression;"ObjectExpression"===t.type?g=t:"StringLiteral"===t.type?y=t.value:"TemplateLiteral"===t.type&&e(t)&&(y=t.quasis[0].cooked)}if(n.arguments.length>2){const e=n.arguments[2].expression;"ObjectExpression"===e.type&&(g=e)}const h=g?t(g,"defaultValue"):void 0,d="string"==typeof h?h:y,x=e=>{if(!e||!Array.isArray(e.properties))return!1;for(const t of e.properties)if(t&&"KeyValueProperty"===t.type&&t.key){const e="Identifier"===t.key.type&&t.key.value||"StringLiteral"===t.key.type&&t.key.value;if("string"==typeof e&&e.startsWith("defaultValue"))return!0}return!1},k="string"==typeof d||x(g),v=x(g),$=Boolean(v||"string"==typeof d&&!("string"==typeof(m=d)&&/{{\s*count\s*}}/.test(m)));var m;for(let e=0;e<u.length;e++){let i,o=u[e];if(g){const e=t(g,"ns");"string"==typeof e&&(i=e)}const l=this.config.extract.nsSeparator??":";if(!i&&l&&o.includes(l)){const e=o.split(l);if(i=e.shift(),o=e.join(l),!o||""===o.trim()){this.logger.warn(`Skipping key that became empty after namespace removal: '${i}${l}'`);continue}}!i&&s?.defaultNs&&(i=s.defaultNs),i||(i=this.config.extract.defaultNS);let a=o;if(s?.keyPrefix){const e=this.config.extract.keySeparator??".";if(a=!1!==e?s.keyPrefix.endsWith(e)?`${s.keyPrefix}${o}`:`${s.keyPrefix}${e}${o}`:`${s.keyPrefix}${o}`,!1!==e){if(a.split(e).some(e=>""===e.trim())){this.logger.warn(`Skipping key with empty segments: '${a}' (keyPrefix: '${s.keyPrefix}', key: '${o}')`);continue}}}const p=e===u.length-1&&d||o;if(g){const e=r(g,"context"),n=[];if("StringLiteral"===e?.value?.type||"NumericLiteral"===e?.value.type||"BooleanLiteral"===e?.value.type){const t=`${e.value.value}`,r=this.config.extract.contextSeparator??"_";""!==t&&n.push({key:`${a}${r}${t}`,ns:i,defaultValue:p,explicitDefault:k})}else if(e?.value){const t=this.expressionResolver.resolvePossibleContextStringValues(e.value),r=this.config.extract.contextSeparator??"_";t.length>0&&t.forEach(e=>{n.push({key:`${a}${r}${e}`,ns:i,defaultValue:p,explicitDefault:k})}),n.push({key:a,ns:i,defaultValue:p,explicitDefault:k,keyAcceptingContext:a})}const o=e=>{if(e){if("KeyValueProperty"===e.type&&e.key){if("Identifier"===e.key.type)return e.key.value;if("StringLiteral"===e.key.type)return e.key.value}return"KeyValueProperty"===e.type&&e.value&&"Identifier"===e.value.type?e.key&&"Identifier"===e.key.type?e.key.value:void 0:"ShorthandProperty"!==e.type&&"Identifier"!==e.type||!e.value?e.key&&"string"==typeof e.key?e.key:void 0:e.value}},s=(()=>{if(!g||!Array.isArray(g.properties))return!1;for(const e of g.properties){if("count"===o(e))return!0}return!1})(),l=(()=>{if(!g||!Array.isArray(g.properties))return!1;for(const e of g.properties){if("ordinal"===o(e))return!("KeyValueProperty"!==e.type||!e.value||"BooleanLiteral"!==e.value.type)&&Boolean(e.value.value)}return!1})();if(s||c){try{const e=c?"ordinal":"cardinal",t=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let r=!1;try{const n=new Intl.PluralRules(t,{type:e}).resolvedOptions().pluralCategories;1===n.length&&"other"===n[0]&&(r=!0)}catch{}if(!r){const t=new Set;for(const r of this.config.locales)try{new Intl.PluralRules(r,{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}catch{new Intl.PluralRules("en",{type:e}).resolvedOptions().pluralCategories.forEach(e=>t.add(e))}const n=Array.from(t).sort();1===n.length&&"other"===n[0]&&(r=!0)}if(r){if(n.length>0)for(const e of n)this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,hasCount:!0,isOrdinal:c});else this.pluginContext.addKey({key:a,ns:i,defaultValue:p,hasCount:!0,isOrdinal:c});continue}}catch(e){}this.config.extract.disablePlurals?n.length>0?n.forEach(this.pluginContext.addKey):this.pluginContext.addKey({key:a,ns:i,defaultValue:p,explicitDefault:k}):this.handlePluralKeys(a,i,g,l||c,d,$);continue}if(n.length>0){n.forEach(this.pluginContext.addKey);continue}!0===t(g,"returnObjects")&&this.objectKeys.add(a)}f&&this.objectKeys.add(a);{const e=n.span?this.getLocationFromSpan(n.span):void 0;this.pluginContext.addKey({key:a,ns:i,defaultValue:p,explicitDefault:k,locations:e?[{file:this.getCurrentFile(),line:e.line,column:e.column}]:void 0})}}}handleCallExpressionArgument(e,t){const r=e.arguments[t].expression,n=[];let i=!1;if("ArrowFunctionExpression"===r.type){const e=this.extractKeyFromSelector(r);e&&(n.push(e),i=!0)}else if("ArrayExpression"===r.type)for(const e of r.elements)e?.expression&&n.push(...this.expressionResolver.resolvePossibleKeyStringValues(e.expression));else n.push(...this.expressionResolver.resolvePossibleKeyStringValues(r));return{keysToProcess:n.filter(e=>!!e),isSelectorAPI:i}}extractKeyFromSelector(e){let t=e.body;if("BlockStatement"===t.type){const e=t.stmts.find(e=>"ReturnStatement"===e.type);if("ReturnStatement"!==e?.type||!e.argument)return null;t=e.argument}let r=t;const n=[];for(;"MemberExpression"===r.type;){const e=r.property;if("Identifier"===e.type)n.unshift(e.value);else{if("Computed"!==e.type||"StringLiteral"!==e.expression.type)return null;n.unshift(e.expression.value)}r=r.object}if(n.length>0){const e=this.config.extract.keySeparator,t="string"==typeof e?e:".";return n.join(t)}return null}handlePluralKeys(e,n,i,o,s,l){try{const a=o?"ordinal":"cardinal",u=new Set;for(const e of this.config.locales)try{const t=new Intl.PluralRules(e,{type:a});t.resolvedOptions().pluralCategories.forEach(e=>u.add(e))}catch(e){const t=new Intl.PluralRules("en",{type:a});t.resolvedOptions().pluralCategories.forEach(e=>u.add(e))}const f=Array.from(u).sort(),c=this.config.extract.pluralSeparator??"_",p=t(i,"defaultValue"),y=t(i,`defaultValue${c}other`),g=t(i,`defaultValue${c}ordinal${c}other`),h=r(i,"context"),d=[];if(h?.value){const t=this.expressionResolver.resolvePossibleContextStringValues(h.value);if(t.length>0)if("StringLiteral"===h.value.type)for(const r of t)r.length>0&&d.push({key:e,context:r});else{for(const r of t)r.length>0&&d.push({key:e,context:r});!1!==this.config.extract?.generateBasePluralForms&&d.push({key:e})}else d.push({key:e})}else d.push({key:e});const x=this.config.extract?.primaryLanguage||(Array.isArray(this.config.locales)?this.config.locales[0]:void 0)||"en";let k=!1;try{const e=new Intl.PluralRules(x,{type:a}).resolvedOptions().pluralCategories;1===e.length&&"other"===e[0]&&(k=!0)}catch{k=!1}if(k||1===f.length&&"other"===f[0]){for(const{key:e,context:r}of d){const a=t(i,`defaultValue${c}other`);let u;u="string"==typeof a?a:"string"==typeof p?p:"string"==typeof s?s:r?`${e}_${r}`:e;const f=this.config.extract.contextSeparator??"_",y=r?`${e}${f}${r}`:e;this.pluginContext.addKey({key:y,ns:n,defaultValue:u,hasCount:!0,isOrdinal:o,explicitDefault:Boolean(l||"string"==typeof a)})}return}for(const{key:r,context:a}of d)for(const u of f){const f=t(i,o?`defaultValue${c}ordinal${c}${u}`:`defaultValue${c}${u}`);let h,d;if(h="string"==typeof f?f:"one"===u&&"string"==typeof p?p:"one"===u&&"string"==typeof s?s:o&&"string"==typeof g?g:o||"string"!=typeof y?"string"==typeof p?p:"string"==typeof s?s:r:y,a){const e=this.config.extract.contextSeparator??"_";d=o?`${r}${e}${a}${c}ordinal${c}${u}`:`${r}${e}${a}${c}${u}`}else d=o?`${r}${c}ordinal${c}${u}`:`${r}${c}${u}`;this.pluginContext.addKey({key:d,ns:n,defaultValue:h,hasCount:!0,isOrdinal:o,explicitDefault:Boolean(l||"string"==typeof f||"string"==typeof y),keyAcceptingContext:void 0!==a?e:void 0})}}catch(r){this.logger.warn(`Could not determine plural rules for language "${this.config.extract?.primaryLanguage}". Falling back to simple key extraction.`);const o=s||t(i,"defaultValue");this.pluginContext.addKey({key:e,ns:n,defaultValue:"string"==typeof o?o:e})}}getFunctionName(e){if("Identifier"===e.type)return e.value;if("MemberExpression"===e.type){const t=[];let r=e;for(;"MemberExpression"===r.type;){if("Identifier"!==r.property.type)return null;t.unshift(r.property.value),r=r.object}if("ThisExpression"===r.type)t.unshift("this");else{if("Identifier"!==r.type)return null;t.unshift(r.value)}return t.join(".")}return null}}export{n as CallExpressionHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extractFromTransComponent as e}from"./jsx-parser.js";import{getObjectPropValue as t}from"./ast-utils.js";class n{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;constructor(e,t,n,s
|
|
1
|
+
import{extractFromTransComponent as e}from"./jsx-parser.js";import{getObjectPropValue as t}from"./ast-utils.js";class n{config;pluginContext;expressionResolver;getCurrentFile;getCurrentCode;constructor(e,t,n,o,s){this.config=e,this.pluginContext=t,this.expressionResolver=n,this.getCurrentFile=o,this.getCurrentCode=s}getLocationFromSpan(e){if(!e||"number"!=typeof e.start)return;const t=this.getCurrentCode(),n=e.start,o=t.substring(0,n).split("\n");return{line:o.length,column:o[o.length-1].length}}handleJSXElement(t,n){const o=this.getElementName(t);if(o&&(this.config.extract.transComponents||["Trans"]).includes(o)){const o=e(t,this.config),s=[];if(o){if(o.keyExpression){const e=this.expressionResolver.resolvePossibleKeyStringValues(o.keyExpression);s.push(...e)}else s.push(o.serializedChildren);let e;const{contextExpression:i,optionsNode:a,defaultValue:l,hasCount:r,isOrdinal:u,serializedChildren:f}=o,c=t.span?this.getLocationFromSpan(t.span):void 0,p=c?[{file:this.getCurrentFile(),line:c.line,column:c.column}]:void 0;if(o.ns){const{ns:t}=o;e=s.map(e=>({key:e,ns:t,defaultValue:l||f,hasCount:r,isOrdinal:u,locations:p}))}else{e=s.map(e=>{const t=this.config.extract.nsSeparator??":";let n;if(t&&e.includes(t)){let o;[n,...o]=e.split(t),e=o.join(t)}return{key:e,ns:n,defaultValue:l||f,hasCount:r,isOrdinal:u,explicitDefault:o.explicitDefault,locations:p}});const i=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"t"===e.name.value);if("JSXAttribute"===i?.type&&"JSXExpressionContainer"===i.value?.type&&"Identifier"===i.value.expression.type){const t=n(i.value.expression.value);t?.defaultNs&&e.forEach(e=>{e.ns||(e.ns=t.defaultNs)})}}if(e.forEach(e=>{e.ns||(e.ns=this.config.extract.defaultNS)}),i&&r)if(this.config.extract.disablePlurals){const t=this.expressionResolver.resolvePossibleContextStringValues(i),n=this.config.extract.contextSeparator??"_";if(t.length>0)if("StringLiteral"===i.type)for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}else{e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})});for(const o of t)for(const t of e){const e=`${t.key}${n}${o}`;this.pluginContext.addKey({key:e,ns:t.ns,defaultValue:t.defaultValue,locations:t.locations})}}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),o=!!n,s=this.expressionResolver.resolvePossibleContextStringValues(i),l=this.config.extract.contextSeparator??"_";if(s.length>0){e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,a,void 0,e.locations,e.key));for(const t of s)for(const n of e){const e=`${n.key}${l}${t}`;this.generatePluralKeysForTrans(e,n.defaultValue,n.ns,o,a,n.explicitDefault,n.locations,n.key)}}else e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,a,e.explicitDefault,e.locations))}else if(i){const t=this.expressionResolver.resolvePossibleContextStringValues(i),n=this.config.extract.contextSeparator??"_";if(t.length>0){for(const o of t)for(const{key:t,ns:s,defaultValue:i,locations:a}of e)this.pluginContext.addKey({key:`${t}${n}${o}`,ns:s,defaultValue:i,locations:a,keyAcceptingContext:t});"StringLiteral"!==i.type&&e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations,keyAcceptingContext:e.key})})}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}else if(r)if(this.config.extract.disablePlurals)e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})});else{const n=t.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),o=!!n;e.forEach(e=>this.generatePluralKeysForTrans(e.key,e.defaultValue,e.ns,o,a,e.explicitDefault,e.locations))}else e.forEach(e=>{this.pluginContext.addKey({key:e.key,ns:e.ns,defaultValue:e.defaultValue,locations:e.locations})})}}}generatePluralKeysForTrans(e,n,o,s,i,a,l,r){try{const u=s?"ordinal":"cardinal",f=new Intl.PluralRules(this.config.extract?.primaryLanguage,{type:u}).resolvedOptions().pluralCategories,c=this.config.extract.pluralSeparator??"_";let p,d;if(i&&(p=t(i,`defaultValue${c}other`),d=t(i,`defaultValue${c}ordinal${c}other`)),1===f.length&&"other"===f[0]){const u=i?t(i,`defaultValue${c}other`):void 0,f="string"==typeof u?u:"string"==typeof n?n:e;return void this.pluginContext.addKey({key:e,ns:o,defaultValue:f,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(a||"string"==typeof u||"string"==typeof p),locations:l,keyAcceptingContext:r})}for(const u of f){const f=i?t(i,s?`defaultValue${c}ordinal${c}${u}`:`defaultValue${c}${u}`):void 0;let y;y="string"==typeof f?f:"one"===u&&"string"==typeof n?n:s&&"string"==typeof d?d:s||"string"!=typeof p?"string"==typeof n?n:e:p;const g=s?`${e}${c}ordinal${c}${u}`:`${e}${c}${u}`;this.pluginContext.addKey({key:g,ns:o,defaultValue:y,hasCount:!0,isOrdinal:s,explicitDefault:Boolean(a||"string"==typeof f||"string"==typeof p),locations:l,keyAcceptingContext:r})}}catch(t){this.pluginContext.addKey({key:e,ns:o,defaultValue:n,locations:l})}}getElementName(e){if("Identifier"===e.opening.name.type)return e.opening.name.value;if("JSXMemberExpression"===e.opening.name.type){let t=e.opening.name;const n=[];for(;"JSXMemberExpression"===t.type;)"Identifier"===t.property.type&&n.unshift(t.property.value),t=t.object;return"Identifier"===t.type&&n.unshift(t.value),n.join(".")}}}export{n as JSXHandler};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getObjectProperty 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 r(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?i(e.value.expression):void 0}function s(n,s){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 u;l||"JSXAttribute"!==a?.type||"JSXExpressionContainer"!==a.value?.type||"ObjectExpression"!==a.value.expression.type||(u=e(a.value.expression,"count"));const y=!!l||!!u,f=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),c="JSXAttribute"===f?.type&&"JSXExpressionContainer"===f.value?.type&&"ObjectExpression"===f.value.expression.type?f.value.expression:void 0,v=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),S=!!v,d=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let g="JSXAttribute"===d?.type&&"JSXExpressionContainer"===d.value?.type?d.value.expression:"JSXAttribute"===d?.type&&"StringLiteral"===d.value?.type?d.value:void 0;const x=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let m;if(m="JSXAttribute"===x?.type?r(x):void 0,c&&(void 0===m&&(m=t(c,"ns")),void 0===g)){const t=e(c,"context");t?.value&&(g=t.value)}const J=function(e,t){if(!e||0===e.length)return"";const n=new Set(t.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),r=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function s(e,t,o=!1){if(!e||!e.length)return;let p=0,l=e.length-1;for(;p<=l&&r(e[p]);)p++;for(;l>=p&&r(e[l]);)l--;const a=p<=l?e.slice(p,l+1):[],u=a.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<a.length;e++){const p=a[e];if(p)if("JSXText"!==p.type){if("JSXExpressionContainer"===p.type){if(o&&!u&&p.expression){const e=p.expression.type;if("ObjectExpression"===e){const e=p.expression.properties&&p.expression.properties[0];if(e&&"KeyValueProperty"===e.type)continue}const t=i(p.expression);if(void 0!==t){if(!(/^\s*$/.test(t)&&!t.includes("\n")))continue}else if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const n=i(p.expression);if(void 0!==n){const i=/^\s*$/.test(n)&&!n.includes("\n"),s=a[e-1],o=a[e+1];if(i){const n=a[e+2];if(o&&"JSXText"===o.type&&r(o)&&n&&("JSXElement"===n.type||"JSXFragment"===n.type)){const t=a[e-1],n=a[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue;const i=!o||"JSXText"===o.type&&!r(o);if(s&&"JSXText"===s.type&&i){const e=t[t.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+p.expression.value;continue}}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue}}t.push(p);continue}if("JSXElement"===p.type){const e=p.opening&&p.opening.name&&"Identifier"===p.opening.name.type?p.opening.name.value:void 0;if(e&&n.has(e)){!(!p.opening||!p.opening.selfClosing)&&t.push(p),s(p.children||[],t,!1)}else t.push(p),s(p.children||[],t,!0);continue}"JSXFragment"!==p.type||s(p.children||[],t,o)}else{if(o&&!u)continue;if(o&&r(p))continue;if(r(p)){const n=a[e-1],i=a[e+1];if(n&&("JSXElement"===n.type||"JSXFragment"===n.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const r=t[t.length-1],s=a[e-1];if(r){if(s&&"JSXExpressionContainer"===s.type)continue;if("JSXText"===r.type&&s&&"JSXText"===s.type){r.value=String(r.value)+p.value;continue}}}if(o&&u&&0===e)continue;t.push(p)}}}const o=[];s(e,o,!1);const p=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function l(e,t){if(!e||0===e.length)return"";let s="",a=!1;for(let u=0;u<e.length;u++){const y=e[u];if(y)if("JSXText"!==y.type){if("JSXExpressionContainer"===y.type){const e=y.expression;if(!e)continue;const t=i(e);if(void 0!==t)s+=t;else if("Identifier"===e.type)s+=`{{${e.value}}}`;else if("ObjectExpression"===e.type){const t=e.properties[0];t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type?s+=`{{${t.key.value}}}`:t&&"Identifier"===t.type?s+=`{{${t.value}}}`:s+="{{value}}"}else"MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type?s+=`{{${e.property.value}}}`:"CallExpression"===e.type&&"Identifier"===e.callee?.type?s+=`{{${e.callee.value}}}`:s+="{{value}}";a=!1;continue}if("JSXElement"===y.type){let i;if(y.opening&&y.opening.name&&"Identifier"===y.opening.name.type&&(i=y.opening.name.value),i&&n.has(i)){const n=l(y.children||[],t),r=!(!y.opening||!y.opening.selfClosing),o=""!==String(n).trim();if(r||!o){const t=e[u-1];t&&"JSXText"===t.type&&/\n\s*$/.test(t.value)&&(s=s.replace(/\s+$/,"")),s+=`<${i}/>`,a=!0}else s+=`<${i}>${n}</${i}>`,a=!1}else{const e=y.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(y),n=l(e,void 0);s+=`<${t}>${p(n)}</${t}>`,a=!1}else{const i=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)){!(!t.opening||!t.opening.selfClosing)&&i.set(t,r++)}else i.set(t,r++)}const u=t&&t.has(y)?t.get(y):o.indexOf(y),f=l(e,i.size?i:void 0);s+=`<${u}>${p(f)}</${u}>`,a=!1}}continue}"JSXFragment"!==y.type||(s+=l(y.children||[]),a=!1)}else{if(r(y))continue;a?(s+=y.value.replace(/^\s+/,""),a=!1):s+=y.value}}return s}const a=l(e);return String(a).replace(/\s+/g," ").trim()}(n.children,s);let X;const E="JSXAttribute"===p?.type?r(p):void 0;if(void 0!==E)X=E;else{const e=s.extract.defaultValue;X="string"==typeof e?e:""}let b,h;if("JSXAttribute"===o?.type){if("StringLiteral"===o.value?.type){if(b=o.value,h=b.value,!h||""===h.trim())return null;if(m&&"StringLiteral"===b.type){const e=s.extract.nsSeparator??":",t=b.value;if(e&&t.startsWith(`${m}${e}`)){if(h=t.slice(`${m}${e}`.length),!h||""===h.trim())return null;b={...b,value:h}}}}else"JSXExpressionContainer"===o.value?.type&&"JSXEmptyExpression"!==o.value.expression.type&&(b=o.value.expression);if(!b)return null}p||!h||J.trim()?!p&&J.trim()&&(X=J):X=h;return{keyExpression:b,serializedChildren:J,ns:m,defaultValue:X,hasCount:y,isOrdinal:S,contextExpression:g,optionsNode:c,explicitDefault:void 0!==E||(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})(c)}}export{s as extractFromTransComponent};
|
|
1
|
+
import{getObjectProperty 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 r(e){return"StringLiteral"===e.value?.type?e.value.value:"JSXExpressionContainer"===e.value?.type?i(e.value.expression):void 0}function s(n,s){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 u;l||"JSXAttribute"!==a?.type||"JSXExpressionContainer"!==a.value?.type||"ObjectExpression"!==a.value.expression.type||(u=e(a.value.expression,"count"));const y=!!l||!!u,f=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"tOptions"===e.name.value),c="JSXAttribute"===f?.type&&"JSXExpressionContainer"===f.value?.type&&"ObjectExpression"===f.value.expression.type?f.value.expression:void 0,v=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ordinal"===e.name.value),S=!!v,d=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"context"===e.name.value);let g="JSXAttribute"===d?.type&&"JSXExpressionContainer"===d.value?.type?d.value.expression:"JSXAttribute"===d?.type&&"StringLiteral"===d.value?.type?d.value:void 0;const x=n.opening.attributes?.find(e=>"JSXAttribute"===e.type&&"Identifier"===e.name.type&&"ns"===e.name.value);let m;if(m="JSXAttribute"===x?.type?r(x):void 0,c&&(void 0===m&&(m=t(c,"ns")),void 0===g)){const t=e(c,"context");t?.value&&(g=t.value)}const J=function(e,t){if(!e||0===e.length)return"";const n=new Set(t.extract.transKeepBasicHtmlNodesFor??["br","strong","i","p"]),r=e=>e&&"JSXText"===e.type&&/^\s*$/.test(e.value)&&e.value.includes("\n");function s(e,t,o=!1){if(!e||!e.length)return;let p=0,l=e.length-1;for(;p<=l&&r(e[p]);)p++;for(;l>=p&&r(e[l]);)l--;const a=p<=l?e.slice(p,l+1):[],u=a.some(e=>e&&("JSXElement"===e.type||"JSXFragment"===e.type));for(let e=0;e<a.length;e++){const p=a[e];if(p)if("JSXText"!==p.type){if("JSXExpressionContainer"===p.type){if(o&&!u&&p.expression){const e=p.expression.type;if("ObjectExpression"===e){const e=p.expression.properties&&p.expression.properties[0];if(e&&"KeyValueProperty"===e.type)continue}const t=i(p.expression);if(void 0!==t){if(!(/^\s*$/.test(t)&&!t.includes("\n")))continue}else if("Identifier"===e||"MemberExpression"===e||"CallExpression"===e)continue}const n=i(p.expression);if(void 0!==n){const i=/^\s*$/.test(n)&&!n.includes("\n"),s=a[e-1],o=a[e+1];if(i){const n=a[e+2];if(o&&"JSXText"===o.type&&r(o)&&n&&("JSXElement"===n.type||"JSXFragment"===n.type)){const t=a[e-1],n=a[e-2];if(!t||"JSXText"!==t.type&&n&&"JSXExpressionContainer"===n.type)continue}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue;const i=!o||"JSXText"===o.type&&!r(o);if(s&&"JSXText"===s.type&&i){const e=t[t.length-1];if(e&&"JSXText"===e.type){e.value=String(e.value)+p.expression.value;continue}}if(s&&("JSXElement"===s.type||"JSXFragment"===s.type)&&o&&"JSXText"===o.type&&r(o))continue}}t.push(p);continue}if("JSXElement"===p.type){const e=p.opening&&p.opening.name&&"Identifier"===p.opening.name.type?p.opening.name.value:void 0;if(e&&n.has(e)){!(!p.opening||!p.opening.selfClosing)&&t.push(p),s(p.children||[],t,!1)}else t.push(p),s(p.children||[],t,!0);continue}"JSXFragment"!==p.type||s(p.children||[],t,o)}else{if(o&&!u)continue;if(o&&r(p))continue;if(r(p)){const n=a[e-1],i=a[e+1];if(n&&("JSXElement"===n.type||"JSXFragment"===n.type)&&i&&("JSXElement"===i.type||"JSXFragment"===i.type))continue;const r=t[t.length-1],s=a[e-1];if(r){if(s&&"JSXExpressionContainer"===s.type)continue;if("JSXText"===r.type&&s&&"JSXText"===s.type){r.value=String(r.value)+p.value;continue}}}if(o&&u&&0===e)continue;t.push(p)}}}const o=[];s(e,o,!1);const p=e=>String(e).replace(/^\s*\n\s*/g,"").replace(/\s*\n\s*$/g,"");function l(e,t){if(!e||0===e.length)return"";let s="",a=!1;for(let u=0;u<e.length;u++){const y=e[u];if(y)if("JSXText"!==y.type){if("JSXExpressionContainer"===y.type){const e=y.expression;if(!e)continue;const t=i(e);if(void 0!==t)s+=t;else if("Identifier"===e.type)s+=`{{${e.value}}}`;else if("ObjectExpression"===e.type){const t=e.properties[0];t&&"KeyValueProperty"===t.type&&t.key&&"Identifier"===t.key.type?s+=`{{${t.key.value}}}`:t&&"Identifier"===t.type?s+=`{{${t.value}}}`:s+="{{value}}"}else"MemberExpression"===e.type&&e.property&&"Identifier"===e.property.type?s+=`{{${e.property.value}}}`:"CallExpression"===e.type&&"Identifier"===e.callee?.type?s+=`{{${e.callee.value}}}`:s+="{{value}}";a=!1;continue}if("JSXElement"===y.type){let i;if(y.opening&&y.opening.name&&"Identifier"===y.opening.name.type&&(i=y.opening.name.value),i&&n.has(i)){const n=l(y.children||[],t),r=!(!y.opening||!y.opening.selfClosing),o=""!==String(n).trim();if(r||!o){const t=e[u-1];t&&"JSXText"===t.type&&/\n\s*$/.test(t.value)&&(s=s.replace(/\s+$/,"")),s+=`<${i} />`,a=!0}else s+=`<${i}>${n}</${i}>`,a=!1}else{const e=y.children||[];if(e.some(e=>e&&("JSXText"===e.type||"JSXExpressionContainer"===e.type)&&-1!==o.indexOf(e))){const t=o.indexOf(y),n=l(e,void 0);s+=`<${t}>${p(n)}</${t}>`,a=!1}else{const i=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)){!(!t.opening||!t.opening.selfClosing)&&i.set(t,r++)}else i.set(t,r++)}const u=t&&t.has(y)?t.get(y):o.indexOf(y),f=l(e,i.size?i:void 0);s+=`<${u}>${p(f)}</${u}>`,a=!1}}continue}"JSXFragment"!==y.type||(s+=l(y.children||[]),a=!1)}else{if(r(y))continue;a?(s+=y.value.replace(/^\s+/,""),a=!1):s+=y.value}}return s}const a=l(e);return String(a).replace(/\s+/g," ").trim()}(n.children,s);let X;const E="JSXAttribute"===p?.type?r(p):void 0;if(void 0!==E)X=E;else{const e=s.extract.defaultValue;X="string"==typeof e?e:""}let b,h;if("JSXAttribute"===o?.type){if("StringLiteral"===o.value?.type){if(b=o.value,h=b.value,!h||""===h.trim())return null;if(m&&"StringLiteral"===b.type){const e=s.extract.nsSeparator??":",t=b.value;if(e&&t.startsWith(`${m}${e}`)){if(h=t.slice(`${m}${e}`.length),!h||""===h.trim())return null;b={...b,value:h}}}}else"JSXExpressionContainer"===o.value?.type&&"JSXEmptyExpression"!==o.value.expression.type&&(b=o.value.expression);if(!b)return null}p||!h||J.trim()?!p&&J.trim()&&(X=J):X=h;return{keyExpression:b,serializedChildren:J,ns:m,defaultValue:X,hasCount:y,isOrdinal:S,contextExpression:g,optionsNode:c,explicitDefault:void 0!==E||(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})(c)}}export{s as extractFromTransComponent};
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -22,7 +22,7 @@ const program = new Command()
|
|
|
22
22
|
program
|
|
23
23
|
.name('i18next-cli')
|
|
24
24
|
.description('A unified, high-performance i18next CLI.')
|
|
25
|
-
.version('1.
|
|
25
|
+
.version('1.23.1')
|
|
26
26
|
|
|
27
27
|
// new: global config override option
|
|
28
28
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)')
|
|
@@ -16,6 +16,70 @@ function globToRegex (glob: string): RegExp {
|
|
|
16
16
|
return new RegExp(regexString)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Checks if an existing key is a context variant of a base key that accepts context.
|
|
21
|
+
* This function handles complex cases where:
|
|
22
|
+
* - The key might have plural suffixes (_one, _other, etc.)
|
|
23
|
+
* - The context value itself might contain the separator (e.g., mc_laren)
|
|
24
|
+
*
|
|
25
|
+
* @param existingKey - The key from the translation file to check
|
|
26
|
+
* @param keysAcceptingContext - Set of base keys that were used with context in source code
|
|
27
|
+
* @param pluralSeparator - The separator used for plural forms (default: '_')
|
|
28
|
+
* @param contextSeparator - The separator used for context variants (default: '_')
|
|
29
|
+
* @returns true if the existing key is a context variant of a key accepting context
|
|
30
|
+
*/
|
|
31
|
+
function isContextVariantOfAcceptingKey (
|
|
32
|
+
existingKey: string,
|
|
33
|
+
keysAcceptingContext: ReadonlySet<string>,
|
|
34
|
+
pluralSeparator: string,
|
|
35
|
+
contextSeparator: string
|
|
36
|
+
): boolean {
|
|
37
|
+
if (keysAcceptingContext.size === 0) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Try to extract the base key from this existing key by removing context and/or plural suffixes
|
|
42
|
+
let potentialBaseKey = existingKey
|
|
43
|
+
|
|
44
|
+
// First, try removing plural suffixes if present
|
|
45
|
+
const pluralForms = ['zero', 'one', 'two', 'few', 'many', 'other']
|
|
46
|
+
for (const form of pluralForms) {
|
|
47
|
+
if (potentialBaseKey.endsWith(`${pluralSeparator}${form}`)) {
|
|
48
|
+
potentialBaseKey = potentialBaseKey.slice(0, -(pluralSeparator.length + form.length))
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
if (potentialBaseKey.endsWith(`${pluralSeparator}ordinal${pluralSeparator}${form}`)) {
|
|
52
|
+
potentialBaseKey = potentialBaseKey.slice(0, -(pluralSeparator.length + 'ordinal'.length + pluralSeparator.length + form.length))
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Then, try removing the context suffix to get the base key
|
|
58
|
+
// We need to check all possible base keys since the context value itself might contain separators
|
|
59
|
+
// For example: 'formula_one_mc_laren' could be:
|
|
60
|
+
// - base: 'formula_one_mc', context: 'laren'
|
|
61
|
+
// - base: 'formula_one', context: 'mc_laren' ← correct
|
|
62
|
+
// - base: 'formula', context: 'one_mc_laren'
|
|
63
|
+
const parts = potentialBaseKey.split(contextSeparator)
|
|
64
|
+
if (parts.length > 1) {
|
|
65
|
+
// Try removing 1, 2, 3... parts from the end to find a matching base key
|
|
66
|
+
for (let i = 1; i < parts.length; i++) {
|
|
67
|
+
const baseWithoutContext = parts.slice(0, -i).join(contextSeparator)
|
|
68
|
+
if (keysAcceptingContext.has(baseWithoutContext)) {
|
|
69
|
+
return true
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Also check if the key itself (after removing plural suffix) accepts context
|
|
75
|
+
// This handles cases like 'friend_other' where 'friend' accepts context
|
|
76
|
+
if (keysAcceptingContext.has(potentialBaseKey)) {
|
|
77
|
+
return true
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
|
|
19
83
|
/**
|
|
20
84
|
* Recursively sorts the keys of an object.
|
|
21
85
|
*/
|
|
@@ -119,8 +183,20 @@ function buildNewTranslationsForNs (
|
|
|
119
183
|
defaultValue: emptyDefaultValue = '',
|
|
120
184
|
pluralSeparator = '_',
|
|
121
185
|
contextSeparator = '_',
|
|
186
|
+
preserveContextVariants = false,
|
|
122
187
|
} = config.extract
|
|
123
188
|
|
|
189
|
+
// Build a set of base keys that accept context (only if preserveContextVariants is enabled)
|
|
190
|
+
// These are keys that were called with a context parameter in the source code
|
|
191
|
+
const keysAcceptingContext = new Set<string>()
|
|
192
|
+
if (preserveContextVariants) {
|
|
193
|
+
for (const { keyAcceptingContext } of nsKeys) {
|
|
194
|
+
if (keyAcceptingContext) {
|
|
195
|
+
keysAcceptingContext.add(keyAcceptingContext)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
124
200
|
// Get the plural categories for the target language
|
|
125
201
|
const targetLanguagePluralCategories = new Set<string>()
|
|
126
202
|
// Track cardinal plural categories separately so we can special-case single-"other" languages
|
|
@@ -271,10 +347,18 @@ function buildNewTranslationsForNs (
|
|
|
271
347
|
? {}
|
|
272
348
|
: JSON.parse(JSON.stringify(existingTranslations))
|
|
273
349
|
|
|
274
|
-
// Preserve keys that match the configured patterns
|
|
350
|
+
// Preserve keys that match the configured patterns OR are context variants of keys accepting context
|
|
275
351
|
const existingKeys = getNestedKeys(existingTranslations, keySeparator ?? '.')
|
|
276
352
|
for (const existingKey of existingKeys) {
|
|
277
|
-
|
|
353
|
+
const shouldPreserve = shouldPreserveExistingKey(existingKey)
|
|
354
|
+
const isContextVariant = !shouldPreserve && isContextVariantOfAcceptingKey(
|
|
355
|
+
existingKey,
|
|
356
|
+
keysAcceptingContext,
|
|
357
|
+
pluralSeparator,
|
|
358
|
+
contextSeparator
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
if (shouldPreserve || (preserveContextVariants && isContextVariant)) {
|
|
278
362
|
const value = getNestedValue(existingTranslations, existingKey, keySeparator ?? '.')
|
|
279
363
|
setNestedValue(newTranslations, existingKey, value, keySeparator ?? '.')
|
|
280
364
|
}
|
|
@@ -232,9 +232,15 @@ export class CallExpressionHandler {
|
|
|
232
232
|
contextValues.forEach(context => {
|
|
233
233
|
keysWithContext.push({ key: `${finalKey}${contextSeparator}${context}`, ns, defaultValue: dv, explicitDefault: explicitDefaultForBase })
|
|
234
234
|
})
|
|
235
|
-
// For dynamic context, also add the base key as a fallback
|
|
236
|
-
keysWithContext.push({ key: finalKey, ns, defaultValue: dv, explicitDefault: explicitDefaultForBase })
|
|
237
235
|
}
|
|
236
|
+
// For dynamic context, also add the base key as a fallback
|
|
237
|
+
keysWithContext.push({
|
|
238
|
+
key: finalKey,
|
|
239
|
+
ns,
|
|
240
|
+
defaultValue: dv,
|
|
241
|
+
explicitDefault: explicitDefaultForBase,
|
|
242
|
+
keyAcceptingContext: finalKey
|
|
243
|
+
})
|
|
238
244
|
}
|
|
239
245
|
|
|
240
246
|
// 2. Handle Plurals
|
|
@@ -691,7 +697,9 @@ export class CallExpressionHandler {
|
|
|
691
697
|
// - the extractor marked the source as explicitly providing plural defaults
|
|
692
698
|
// - OR a plural-specific default was provided in the options (specificDefault/otherDefault)
|
|
693
699
|
// Do NOT treat the presence of a general base defaultValueFromCall as making variants explicit.
|
|
694
|
-
explicitDefault: Boolean(explicitDefaultFromSource || typeof specificDefault === 'string' || typeof otherDefault === 'string')
|
|
700
|
+
explicitDefault: Boolean(explicitDefaultFromSource || typeof specificDefault === 'string' || typeof otherDefault === 'string'),
|
|
701
|
+
// If this is a context variant, track the base key (without context or plural suffixes)
|
|
702
|
+
keyAcceptingContext: context !== undefined ? key : undefined
|
|
695
703
|
})
|
|
696
704
|
}
|
|
697
705
|
}
|
|
@@ -184,7 +184,8 @@ export class JSXHandler {
|
|
|
184
184
|
key: extractedKey.key,
|
|
185
185
|
ns: extractedKey.ns,
|
|
186
186
|
defaultValue: extractedKey.defaultValue,
|
|
187
|
-
locations: extractedKey.locations
|
|
187
|
+
locations: extractedKey.locations,
|
|
188
|
+
keyAcceptingContext: extractedKey.key
|
|
188
189
|
})
|
|
189
190
|
})
|
|
190
191
|
for (const context of contextValues) {
|
|
@@ -226,14 +227,15 @@ export class JSXHandler {
|
|
|
226
227
|
|
|
227
228
|
// Generate all combinations of context and plural forms
|
|
228
229
|
if (contextValues.length > 0) {
|
|
229
|
-
// Generate base plural forms (no context)
|
|
230
|
-
extractedKeys.forEach(extractedKey => this.generatePluralKeysForTrans(extractedKey.key, extractedKey.defaultValue, extractedKey.ns, isOrdinal, optionsNode, undefined, extractedKey.locations))
|
|
230
|
+
// Generate base plural forms (no context) - these also accept context
|
|
231
|
+
extractedKeys.forEach(extractedKey => this.generatePluralKeysForTrans(extractedKey.key, extractedKey.defaultValue, extractedKey.ns, isOrdinal, optionsNode, undefined, extractedKey.locations, extractedKey.key))
|
|
231
232
|
|
|
232
233
|
// Generate context + plural combinations
|
|
233
234
|
for (const context of contextValues) {
|
|
234
235
|
for (const extractedKey of extractedKeys) {
|
|
235
236
|
const contextKey = `${extractedKey.key}${contextSeparator}${context}`
|
|
236
|
-
|
|
237
|
+
// The base key that accepts context is extractedKey.key (without the context suffix)
|
|
238
|
+
this.generatePluralKeysForTrans(contextKey, extractedKey.defaultValue, extractedKey.ns, isOrdinal, optionsNode, extractedKey.explicitDefault, extractedKey.locations, extractedKey.key)
|
|
237
239
|
}
|
|
238
240
|
}
|
|
239
241
|
} else {
|
|
@@ -253,7 +255,8 @@ export class JSXHandler {
|
|
|
253
255
|
key: `${key}${contextSeparator}${context}`,
|
|
254
256
|
ns,
|
|
255
257
|
defaultValue,
|
|
256
|
-
locations
|
|
258
|
+
locations,
|
|
259
|
+
keyAcceptingContext: key
|
|
257
260
|
})
|
|
258
261
|
}
|
|
259
262
|
}
|
|
@@ -264,7 +267,8 @@ export class JSXHandler {
|
|
|
264
267
|
key: extractedKey.key,
|
|
265
268
|
ns: extractedKey.ns,
|
|
266
269
|
defaultValue: extractedKey.defaultValue,
|
|
267
|
-
locations: extractedKey.locations
|
|
270
|
+
locations: extractedKey.locations,
|
|
271
|
+
keyAcceptingContext: extractedKey.key
|
|
268
272
|
})
|
|
269
273
|
})
|
|
270
274
|
}
|
|
@@ -327,8 +331,9 @@ export class JSXHandler {
|
|
|
327
331
|
* @param ns - Namespace for the keys
|
|
328
332
|
* @param isOrdinal - Whether to generate ordinal plural forms
|
|
329
333
|
* @param optionsNode - Optional tOptions object expression for plural-specific defaults
|
|
330
|
-
* @param explicitDefaultFromSource - Whether the default was explicitly provided
|
|
334
|
+
* @param explicitDefaultFromSource - Whether the default was explicitly provided
|
|
331
335
|
* @param locations - Source location information for this key
|
|
336
|
+
* @param keyAcceptingContext - The base key that accepts context (if this is a context variant)
|
|
332
337
|
*/
|
|
333
338
|
private generatePluralKeysForTrans (
|
|
334
339
|
key: string,
|
|
@@ -337,7 +342,8 @@ export class JSXHandler {
|
|
|
337
342
|
isOrdinal: boolean,
|
|
338
343
|
optionsNode?: ObjectExpression,
|
|
339
344
|
explicitDefaultFromSource?: boolean,
|
|
340
|
-
locations?: Array<{ file: string, line?: number, column?: number }
|
|
345
|
+
locations?: Array<{ file: string, line?: number, column?: number }>,
|
|
346
|
+
keyAcceptingContext?: string
|
|
341
347
|
): void {
|
|
342
348
|
try {
|
|
343
349
|
const type = isOrdinal ? 'ordinal' : 'cardinal'
|
|
@@ -367,7 +373,8 @@ export class JSXHandler {
|
|
|
367
373
|
hasCount: true,
|
|
368
374
|
isOrdinal,
|
|
369
375
|
explicitDefault: Boolean(explicitDefaultFromSource || typeof specificDefault === 'string' || typeof otherDefault === 'string'),
|
|
370
|
-
locations
|
|
376
|
+
locations,
|
|
377
|
+
keyAcceptingContext
|
|
371
378
|
})
|
|
372
379
|
return
|
|
373
380
|
}
|
|
@@ -413,7 +420,9 @@ export class JSXHandler {
|
|
|
413
420
|
// - the extractor indicated the default was explicit on the source element
|
|
414
421
|
// - OR a plural-specific default was provided in tOptions (specificDefault/otherDefault)
|
|
415
422
|
explicitDefault: Boolean(explicitDefaultFromSource || typeof specificDefault === 'string' || typeof otherDefault === 'string'),
|
|
416
|
-
locations
|
|
423
|
+
locations,
|
|
424
|
+
// Pass through the base key that accepts context (if any)
|
|
425
|
+
keyAcceptingContext
|
|
417
426
|
})
|
|
418
427
|
}
|
|
419
428
|
} catch (e) {
|
|
@@ -620,7 +620,7 @@ function serializeJSXChildren (children: any[], config: I18nextToolkitConfig): s
|
|
|
620
620
|
if (prevOriginal && prevOriginal.type === 'JSXText' && /\n\s*$/.test(prevOriginal.value)) {
|
|
621
621
|
out = out.replace(/\s+$/, '')
|
|
622
622
|
}
|
|
623
|
-
out += `<${tag}/>`
|
|
623
|
+
out += `<${tag} />`
|
|
624
624
|
lastWasSelfClosing = true
|
|
625
625
|
} else {
|
|
626
626
|
out += `<${tag}>${inner}</${tag}>`
|
package/src/types.ts
CHANGED
|
@@ -84,6 +84,14 @@ export interface I18nextToolkitConfig {
|
|
|
84
84
|
/** Glob patterns for keys to preserve even if not found in source (for dynamic keys) */
|
|
85
85
|
preservePatterns?: string[];
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* When true, preserves all context variants of keys that use context parameters.
|
|
89
|
+
* For example, if 'friend' is used with context, all variants like 'friend_male',
|
|
90
|
+
* 'friend_female', etc. are preserved even if not explicitly found in source code.
|
|
91
|
+
* (default: false)
|
|
92
|
+
*/
|
|
93
|
+
preserveContextVariants?: boolean;
|
|
94
|
+
|
|
87
95
|
/** Whether to sort keys alphabetically in output files, or a comparator function to customize the order (default: true) */
|
|
88
96
|
sort?: boolean | ((a: ExtractedKey, b: ExtractedKey) => number);
|
|
89
97
|
|
|
@@ -329,6 +337,14 @@ export interface ExtractedKey {
|
|
|
329
337
|
line?: number
|
|
330
338
|
column?: number
|
|
331
339
|
}>
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* The base key (without context/plural suffixes) when this key accepts context.
|
|
343
|
+
* For example, if the key is 'friend_male' and it has context, this would be 'friend'.
|
|
344
|
+
* This is used to preserve all context variants in translation files.
|
|
345
|
+
* Empty/undefined if the key doesn't use context.
|
|
346
|
+
*/
|
|
347
|
+
keyAcceptingContext?: string;
|
|
332
348
|
}
|
|
333
349
|
|
|
334
350
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAukBnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EAAE,uBAA+B,EAAE,GAAE;IAAE,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9E,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAgH9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-expression-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/call-expression-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA6C,MAAM,WAAW,CAAA;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAgB,SAAS,EAAE,MAAM,aAAa,CAAA;AACvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,qBAAa,qBAAqB;IAChC,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,kBAAkB,CAAoB;IACvC,UAAU,cAAoB;IACrC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAc;gBAGlC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,MAAM,MAAM,EAC5B,cAAc,EAAE,MAAM,MAAM;IAU9B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"call-expression-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/call-expression-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA6C,MAAM,WAAW,CAAA;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAgB,SAAS,EAAE,MAAM,aAAa,CAAA;AACvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,qBAAa,qBAAqB;IAChC,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,kBAAkB,CAAoB;IACvC,UAAU,cAAoB;IACrC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,cAAc,CAAc;gBAGlC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC7C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,MAAM,MAAM,EAC5B,cAAc,EAAE,MAAM,MAAM;IAU9B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,GAAG,IAAI;IAkWxG;;;;;;OAMG;IACH,OAAO,CAAC,4BAA4B;IA8BpC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,sBAAsB;IA2C9B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,gBAAgB;IA6LxB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;CA2BxB"}
|
|
@@ -33,8 +33,9 @@ export declare class JSXHandler {
|
|
|
33
33
|
* @param ns - Namespace for the keys
|
|
34
34
|
* @param isOrdinal - Whether to generate ordinal plural forms
|
|
35
35
|
* @param optionsNode - Optional tOptions object expression for plural-specific defaults
|
|
36
|
-
* @param explicitDefaultFromSource - Whether the default was explicitly provided
|
|
36
|
+
* @param explicitDefaultFromSource - Whether the default was explicitly provided
|
|
37
37
|
* @param locations - Source location information for this key
|
|
38
|
+
* @param keyAcceptingContext - The base key that accepts context (if this is a context variant)
|
|
38
39
|
*/
|
|
39
40
|
private generatePluralKeysForTrans;
|
|
40
41
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAA;AAC7D,OA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7C,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,MAAM,MAAM,EAC5B,cAAc,EAAE,MAAM,MAAM;IAS9B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAe3B;;;;;;;;OAQG;IACH,gBAAgB,CAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GAAG,IAAI;IA+QjI;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,0BAA0B;IAqGlC;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;CAevB"}
|
package/types/types.d.ts
CHANGED
|
@@ -67,6 +67,13 @@ export interface I18nextToolkitConfig {
|
|
|
67
67
|
transKeepBasicHtmlNodesFor?: string[];
|
|
68
68
|
/** Glob patterns for keys to preserve even if not found in source (for dynamic keys) */
|
|
69
69
|
preservePatterns?: string[];
|
|
70
|
+
/**
|
|
71
|
+
* When true, preserves all context variants of keys that use context parameters.
|
|
72
|
+
* For example, if 'friend' is used with context, all variants like 'friend_male',
|
|
73
|
+
* 'friend_female', etc. are preserved even if not explicitly found in source code.
|
|
74
|
+
* (default: false)
|
|
75
|
+
*/
|
|
76
|
+
preserveContextVariants?: boolean;
|
|
70
77
|
/** Whether to sort keys alphabetically in output files, or a comparator function to customize the order (default: true) */
|
|
71
78
|
sort?: boolean | ((a: ExtractedKey, b: ExtractedKey) => number);
|
|
72
79
|
/** Number of spaces for JSON indentation (default: 2) */
|
|
@@ -270,6 +277,13 @@ export interface ExtractedKey {
|
|
|
270
277
|
line?: number;
|
|
271
278
|
column?: number;
|
|
272
279
|
}>;
|
|
280
|
+
/**
|
|
281
|
+
* The base key (without context/plural suffixes) when this key accepts context.
|
|
282
|
+
* For example, if the key is 'friend_male' and it has context, this would be 'friend'.
|
|
283
|
+
* This is used to preserve all context variants in translation files.
|
|
284
|
+
* Empty/undefined if the key doesn't use context.
|
|
285
|
+
*/
|
|
286
|
+
keyAcceptingContext?: string;
|
|
273
287
|
}
|
|
274
288
|
/**
|
|
275
289
|
* Result of processing translation files for a specific locale and namespace.
|
package/types/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,2DAA2D;IAC3D,OAAO,EAAE;QACP,oEAAoE;QACpE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAEzB,4DAA4D;QAC5D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAE3B,mGAAmG;QACnG,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;QAEpE;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;QAE3B,uEAAuE;QACvE,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;QAErC,8EAA8E;QAC9E,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;QAEpC,oDAAoD;QACpD,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAE1B,mDAAmD;QACnD,eAAe,CAAC,EAAE,MAAM,CAAC;QAEzB,+EAA+E;QAC/E,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAErB,4EAA4E;QAC5E,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAE3B;;;;;WAKG;QACH,mBAAm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