gt 2.14.5 → 2.14.6
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 +9 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +44 -9
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +9 -1
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.d.ts +7 -0
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +26 -0
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +18 -2
- package/dist/react/jsx/utils/stringParsing/derivation/index.d.ts +2 -1
- package/dist/react/jsx/utils/stringParsing/derivation/index.js +16 -11
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +13 -2
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.d.ts +2 -1
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +2 -1
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts +3 -1
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +30 -10
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +19 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.d.ts +2 -1
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +4 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.14.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1173](https://github.com/generaltranslation/gt/pull/1173) [`6b0b56b`](https://github.com/generaltranslation/gt/commit/6b0b56b2253e389913fe67eb19f0ba6ebf2c7a53) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - add context derivation
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`6b0b56b`](https://github.com/generaltranslation/gt/commit/6b0b56b2253e389913fe67eb19f0ba6ebf2c7a53)]:
|
|
10
|
+
- @generaltranslation/python-extractor@0.2.7
|
|
11
|
+
|
|
3
12
|
## 2.14.5
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "2.14.
|
|
1
|
+
export declare const PACKAGE_VERSION = "2.14.6";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
export const PACKAGE_VERSION = '2.14.
|
|
2
|
+
export const PACKAGE_VERSION = '2.14.6';
|
|
@@ -24,6 +24,8 @@ import { ensureTAndVarImported, autoInsertJsxComponents, } from './autoInsertion
|
|
|
24
24
|
import path from 'node:path';
|
|
25
25
|
import { extractSourceCode } from '../extractSourceCode.js';
|
|
26
26
|
import { SURROUNDING_LINE_COUNT } from '../../../../utils/constants.js';
|
|
27
|
+
import { handleDerivation } from '../stringParsing/derivation/handleDerivation.js';
|
|
28
|
+
import { nodeToStrings } from '../parseString.js';
|
|
27
29
|
// Handle CommonJS/ESM interop
|
|
28
30
|
const traverse = traverseModule.default || traverseModule;
|
|
29
31
|
// TODO: currently we cover VariableDeclaration and FunctionDeclaration nodes, but are there others we should cover as well?
|
|
@@ -562,19 +564,52 @@ function parseJSXElement({ node, originalName, scopeNode, updates, config, state
|
|
|
562
564
|
}
|
|
563
565
|
// Create a temporary unique flag for derivable content
|
|
564
566
|
const temporaryDeriveId = `derive-temp-id-${randomUUID()}`;
|
|
567
|
+
// Resolve derive context variants if present
|
|
568
|
+
let contextVariants;
|
|
569
|
+
if (metadata._contextDeriveExpr) {
|
|
570
|
+
const contextExpr = metadata._contextDeriveExpr;
|
|
571
|
+
delete metadata._contextDeriveExpr;
|
|
572
|
+
const contextNode = handleDerivation({
|
|
573
|
+
expr: contextExpr,
|
|
574
|
+
tPath: scopeNode,
|
|
575
|
+
file: config.file,
|
|
576
|
+
parsingOptions: config.parsingOptions,
|
|
577
|
+
errors: componentErrors,
|
|
578
|
+
warnings: componentWarnings,
|
|
579
|
+
});
|
|
580
|
+
if (contextNode) {
|
|
581
|
+
contextVariants = nodeToStrings(contextNode);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
565
584
|
// <T> is valid here
|
|
566
585
|
for (const minifiedTree of minifiedTress) {
|
|
567
586
|
// Clean the tree by removing null 'c' fields from JsxElements
|
|
568
587
|
const cleanedTree = removeNullChildrenFields(minifiedTree);
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
588
|
+
if (contextVariants) {
|
|
589
|
+
for (const context of contextVariants) {
|
|
590
|
+
updates.push({
|
|
591
|
+
dataFormat: 'JSX',
|
|
592
|
+
source: cleanedTree,
|
|
593
|
+
metadata: {
|
|
594
|
+
// eslint-disable-next-line no-undef
|
|
595
|
+
...structuredClone(metadata),
|
|
596
|
+
context,
|
|
597
|
+
staticId: temporaryDeriveId,
|
|
598
|
+
},
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
updates.push({
|
|
604
|
+
dataFormat: 'JSX',
|
|
605
|
+
source: cleanedTree,
|
|
606
|
+
metadata: {
|
|
607
|
+
// eslint-disable-next-line no-undef
|
|
608
|
+
...structuredClone(metadata),
|
|
609
|
+
...(derivableTracker.isDerivable && { staticId: temporaryDeriveId }),
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
}
|
|
578
613
|
}
|
|
579
614
|
}
|
|
580
615
|
function resolveDeriveFunctionInvocationFromBinding({ calleeBinding, callee, config, state, output, }) {
|
|
@@ -7,6 +7,7 @@ import { mapAttributeName } from '../mapAttributeName.js';
|
|
|
7
7
|
import { isStaticExpression } from '../../evaluateJsx.js';
|
|
8
8
|
import { warnInvalidMaxCharsSync, warnVariablePropSync, } from '../../../../console/index.js';
|
|
9
9
|
import { isNumberLiteral } from '../isNumberLiteral.js';
|
|
10
|
+
import { containsDeriveCall } from '../stringParsing/derivation/containsDeriveCall.js';
|
|
10
11
|
// Parse the props of a <T> component
|
|
11
12
|
export function parseTProps({ openingElement, metadata, componentErrors, file, }) {
|
|
12
13
|
openingElement.attributes.forEach((attr) => {
|
|
@@ -28,7 +29,14 @@ export function parseTProps({ openingElement, metadata, componentErrors, file, }
|
|
|
28
29
|
if (GT_ATTRIBUTES.includes(attrName)) {
|
|
29
30
|
const staticAnalysis = isStaticExpression(expr);
|
|
30
31
|
if (!staticAnalysis.isStatic) {
|
|
31
|
-
|
|
32
|
+
if (mapAttributeName(attrName) === 'context' &&
|
|
33
|
+
t.isExpression(expr) &&
|
|
34
|
+
containsDeriveCall(expr)) {
|
|
35
|
+
metadata._contextDeriveExpr = expr;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
componentErrors.push(warnVariablePropSync(file, attrName, code, `${expr.loc?.start?.line}:${expr.loc?.start?.column}`));
|
|
39
|
+
}
|
|
32
40
|
}
|
|
33
41
|
// Use the derived value if available
|
|
34
42
|
if (staticAnalysis.isStatic && staticAnalysis.value !== undefined) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* Lightweight name-based check for whether an expression tree contains
|
|
4
|
+
* a derive()/declareStatic() call. Does NOT validate imports or scope —
|
|
5
|
+
* used as a fast gate before full resolution via handleDerivation().
|
|
6
|
+
*/
|
|
7
|
+
export declare function containsDeriveCall(expr: t.Expression): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { GT_DERIVE_STRING_FUNCTIONS } from '../../constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight name-based check for whether an expression tree contains
|
|
5
|
+
* a derive()/declareStatic() call. Does NOT validate imports or scope —
|
|
6
|
+
* used as a fast gate before full resolution via handleDerivation().
|
|
7
|
+
*/
|
|
8
|
+
export function containsDeriveCall(expr) {
|
|
9
|
+
if (t.isCallExpression(expr) && t.isIdentifier(expr.callee)) {
|
|
10
|
+
return GT_DERIVE_STRING_FUNCTIONS.includes(expr.callee.name);
|
|
11
|
+
}
|
|
12
|
+
if (t.isBinaryExpression(expr)) {
|
|
13
|
+
return ((t.isExpression(expr.left) && containsDeriveCall(expr.left)) ||
|
|
14
|
+
(t.isExpression(expr.right) && containsDeriveCall(expr.right)));
|
|
15
|
+
}
|
|
16
|
+
if (t.isTemplateLiteral(expr)) {
|
|
17
|
+
return expr.expressions.some((e) => t.isExpression(e) && containsDeriveCall(e));
|
|
18
|
+
}
|
|
19
|
+
if (t.isConditionalExpression(expr)) {
|
|
20
|
+
return (containsDeriveCall(expr.consequent) || containsDeriveCall(expr.alternate));
|
|
21
|
+
}
|
|
22
|
+
if (t.isParenthesizedExpression(expr)) {
|
|
23
|
+
return containsDeriveCall(expr.expression);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
@@ -262,8 +262,24 @@ function getDeriveVariants({ call, tPath, file, parsingOptions, errors, warnings
|
|
|
262
262
|
// Resolve the inner call's possible string outcomes
|
|
263
263
|
return resolveCallStringVariants(arg.argument, tPath, file, parsingOptions, errors, warnings);
|
|
264
264
|
}
|
|
265
|
-
//
|
|
266
|
-
|
|
265
|
+
// Handle call expression: derive(time())
|
|
266
|
+
if (t.isCallExpression(arg)) {
|
|
267
|
+
return resolveCallStringVariants(arg, tPath, file, parsingOptions, errors, warnings);
|
|
268
|
+
}
|
|
269
|
+
// Handle other expressions (ternary, string literal, etc.) by recursing into handleDerivation
|
|
270
|
+
const node = handleDerivation({
|
|
271
|
+
expr: arg,
|
|
272
|
+
tPath,
|
|
273
|
+
file,
|
|
274
|
+
parsingOptions,
|
|
275
|
+
errors,
|
|
276
|
+
warnings,
|
|
277
|
+
skipDeriveInvocation: true,
|
|
278
|
+
});
|
|
279
|
+
if (node) {
|
|
280
|
+
return nodeToStrings(node);
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
267
283
|
}
|
|
268
284
|
function resolveCallStringVariants(expression, tPath, file, parsingOptions, errors, warnings) {
|
|
269
285
|
// Handle function identifier calls: derive(time())
|
|
@@ -14,7 +14,7 @@ import { ParsingOutput } from '../types.js';
|
|
|
14
14
|
* @param output - Parsing output collectors
|
|
15
15
|
* @param enableRuntimeInterpolation - For template macros, enables runtime interpolation for non-derive calls
|
|
16
16
|
*/
|
|
17
|
-
export declare function deriveExpression({ tPath, expr, metadata, config, output, index, enableRuntimeInterpolation, }: {
|
|
17
|
+
export declare function deriveExpression({ tPath, expr, metadata, config, output, index, enableRuntimeInterpolation, contextVariants, }: {
|
|
18
18
|
tPath: NodePath;
|
|
19
19
|
expr: t.Expression;
|
|
20
20
|
metadata: InlineMetadata;
|
|
@@ -22,4 +22,5 @@ export declare function deriveExpression({ tPath, expr, metadata, config, output
|
|
|
22
22
|
output: ParsingOutput;
|
|
23
23
|
index?: number;
|
|
24
24
|
enableRuntimeInterpolation?: boolean;
|
|
25
|
+
contextVariants?: string[];
|
|
25
26
|
}): void;
|
|
@@ -19,7 +19,7 @@ const generate = generateModule.default || generateModule;
|
|
|
19
19
|
* @param output - Parsing output collectors
|
|
20
20
|
* @param enableRuntimeInterpolation - For template macros, enables runtime interpolation for non-derive calls
|
|
21
21
|
*/
|
|
22
|
-
export function deriveExpression({ tPath, expr, metadata, config, output, index, enableRuntimeInterpolation = false, }) {
|
|
22
|
+
export function deriveExpression({ tPath, expr, metadata, config, output, index, enableRuntimeInterpolation = false, contextVariants, }) {
|
|
23
23
|
// parse derivable expression
|
|
24
24
|
const stringNode = handleDerivation({
|
|
25
25
|
expr,
|
|
@@ -50,16 +50,21 @@ export function deriveExpression({ tPath, expr, metadata, config, output, index,
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const temporaryDeriveId = `derive-temp-id-${randomUUID()}`;
|
|
53
|
+
const contexts = contextVariants ?? [metadata.context];
|
|
53
54
|
for (const string of strings) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
for (const context of contexts) {
|
|
56
|
+
output.updates.push({
|
|
57
|
+
dataFormat: (metadata.format || 'ICU'),
|
|
58
|
+
source: string,
|
|
59
|
+
metadata: {
|
|
60
|
+
...metadata,
|
|
61
|
+
...(context != null && { context }),
|
|
62
|
+
// Add the index if an id and index is provided (for handling when registering an array of strings)
|
|
63
|
+
...(metadata.id &&
|
|
64
|
+
index != null && { id: `${metadata.id}.${index}` }),
|
|
65
|
+
staticId: temporaryDeriveId,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
}
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js
CHANGED
|
@@ -4,6 +4,7 @@ import { warnInvalidMaxCharsSync } from '../../../../../console/index.js';
|
|
|
4
4
|
import { warnInvalidFormatSync } from '../../../../../console/index.js';
|
|
5
5
|
import { warnNonStaticExpressionSync } from '../../../../../console/index.js';
|
|
6
6
|
import { GT_ATTRIBUTES_WITH_SUGAR } from '../../constants.js';
|
|
7
|
+
import { containsDeriveCall } from '../derivation/containsDeriveCall.js';
|
|
7
8
|
import generateModule from '@babel/generator';
|
|
8
9
|
import { mapAttributeName } from '../../mapAttributeName.js';
|
|
9
10
|
import pathModule from 'node:path';
|
|
@@ -59,6 +60,7 @@ export function extractStringEntryMetadata({ options, output, config, nodeLoc, s
|
|
|
59
60
|
*/
|
|
60
61
|
function extractInlineMetadata({ options, output, config, }) {
|
|
61
62
|
const metadata = {};
|
|
63
|
+
let contextDeriveExpr;
|
|
62
64
|
if (options && options.type === 'ObjectExpression') {
|
|
63
65
|
options.properties.forEach((prop) => {
|
|
64
66
|
if (prop.type === 'ObjectProperty' && prop.key.type === 'Identifier') {
|
|
@@ -67,7 +69,13 @@ function extractInlineMetadata({ options, output, config, }) {
|
|
|
67
69
|
t.isExpression(prop.value)) {
|
|
68
70
|
const result = isStaticExpression(prop.value);
|
|
69
71
|
if (!result.isStatic) {
|
|
70
|
-
|
|
72
|
+
const mappedKey = mapAttributeName(attribute);
|
|
73
|
+
if (mappedKey === 'context' && containsDeriveCall(prop.value)) {
|
|
74
|
+
contextDeriveExpr = prop.value;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
output.errors.push(warnNonStaticExpressionSync(config.file, attribute, generate(prop.value).code, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
78
|
+
}
|
|
71
79
|
}
|
|
72
80
|
if (result.isStatic &&
|
|
73
81
|
result.value != null &&
|
|
@@ -107,5 +115,8 @@ function extractInlineMetadata({ options, output, config, }) {
|
|
|
107
115
|
}
|
|
108
116
|
});
|
|
109
117
|
}
|
|
110
|
-
return
|
|
118
|
+
return {
|
|
119
|
+
...metadata,
|
|
120
|
+
...(contextDeriveExpr && { contextDeriveExpr }),
|
|
121
|
+
};
|
|
111
122
|
}
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.d.ts
CHANGED
|
@@ -12,11 +12,12 @@ import { InlineMetadata } from './extractStringEntryMetadata.js';
|
|
|
12
12
|
* @param output - The output to use
|
|
13
13
|
* @param index - Current index in array of strings being extracted
|
|
14
14
|
*/
|
|
15
|
-
export declare function handleDeriveTranslationCall({ arg, metadata, tPath, config, output, index, }: {
|
|
15
|
+
export declare function handleDeriveTranslationCall({ arg, metadata, tPath, config, output, index, contextVariants, }: {
|
|
16
16
|
arg: t.Expression;
|
|
17
17
|
metadata: InlineMetadata;
|
|
18
18
|
tPath: NodePath;
|
|
19
19
|
config: ParsingConfig;
|
|
20
20
|
output: ParsingOutput;
|
|
21
21
|
index?: number;
|
|
22
|
+
contextVariants?: string[];
|
|
22
23
|
}): void;
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js
CHANGED
|
@@ -8,7 +8,7 @@ import { deriveExpression } from '../derivation/index.js';
|
|
|
8
8
|
* @param output - The output to use
|
|
9
9
|
* @param index - Current index in array of strings being extracted
|
|
10
10
|
*/
|
|
11
|
-
export function handleDeriveTranslationCall({ arg, metadata, tPath, config, output, index, }) {
|
|
11
|
+
export function handleDeriveTranslationCall({ arg, metadata, tPath, config, output, index, contextVariants, }) {
|
|
12
12
|
deriveExpression({
|
|
13
13
|
tPath,
|
|
14
14
|
expr: arg,
|
|
@@ -16,5 +16,6 @@ export function handleDeriveTranslationCall({ arg, metadata, tPath, config, outp
|
|
|
16
16
|
config,
|
|
17
17
|
output,
|
|
18
18
|
index,
|
|
19
|
+
contextVariants,
|
|
19
20
|
});
|
|
20
21
|
}
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts
CHANGED
|
@@ -9,11 +9,13 @@ import { InlineMetadata } from './extractStringEntryMetadata.js';
|
|
|
9
9
|
* @param config - The configuration to use
|
|
10
10
|
* @param output - The output to use
|
|
11
11
|
* @param index - The index of the argument
|
|
12
|
+
* @param contextVariants - Optional derive context variants for cross-product
|
|
12
13
|
*/
|
|
13
|
-
export declare function handleLiteralTranslationCall({ arg, metadata, config, output, index, }: {
|
|
14
|
+
export declare function handleLiteralTranslationCall({ arg, metadata, config, output, index, contextVariants, }: {
|
|
14
15
|
arg: t.StringLiteral | t.TemplateLiteral;
|
|
15
16
|
metadata: InlineMetadata;
|
|
16
17
|
config: ParsingConfig;
|
|
17
18
|
output: ParsingOutput;
|
|
18
19
|
index?: number;
|
|
20
|
+
contextVariants?: string[];
|
|
19
21
|
}): void;
|
package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isValidIcu } from '../../../evaluateJsx.js';
|
|
2
2
|
import { warnInvalidIcuSync } from '../../../../../console/index.js';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
3
4
|
/**
|
|
4
5
|
* For the processTranslationCall function, this function handles the case where a string literal or template literal is used.
|
|
5
6
|
* @param arg - The argument to parse
|
|
@@ -7,8 +8,9 @@ import { warnInvalidIcuSync } from '../../../../../console/index.js';
|
|
|
7
8
|
* @param config - The configuration to use
|
|
8
9
|
* @param output - The output to use
|
|
9
10
|
* @param index - The index of the argument
|
|
11
|
+
* @param contextVariants - Optional derive context variants for cross-product
|
|
10
12
|
*/
|
|
11
|
-
export function handleLiteralTranslationCall({ arg, metadata, config, output, index, }) {
|
|
13
|
+
export function handleLiteralTranslationCall({ arg, metadata, config, output, index, contextVariants, }) {
|
|
12
14
|
// ignore dynamic content flag is triggered, check strings are valid ICU
|
|
13
15
|
const source = arg.type === 'StringLiteral' ? arg.value : arg.quasis[0].value.raw;
|
|
14
16
|
// Validate is ICU — skip for non-ICU formats
|
|
@@ -20,13 +22,31 @@ export function handleLiteralTranslationCall({ arg, metadata, config, output, in
|
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
if (contextVariants) {
|
|
26
|
+
const staticId = `derive-temp-id-${randomUUID()}`;
|
|
27
|
+
for (const context of contextVariants) {
|
|
28
|
+
output.updates.push({
|
|
29
|
+
dataFormat: (metadata.format || 'ICU'),
|
|
30
|
+
source,
|
|
31
|
+
metadata: {
|
|
32
|
+
...metadata,
|
|
33
|
+
context,
|
|
34
|
+
...(metadata.id &&
|
|
35
|
+
index != null && { id: `${metadata.id}.${index}` }),
|
|
36
|
+
staticId,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
output.updates.push({
|
|
43
|
+
dataFormat: (metadata.format || 'ICU'),
|
|
44
|
+
source,
|
|
45
|
+
metadata: {
|
|
46
|
+
...metadata,
|
|
47
|
+
// Add the index if an id and index is provided (for handling when registering an array of strings)
|
|
48
|
+
...(metadata.id && index != null && { id: `${metadata.id}.${index}` }),
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
32
52
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { routeTranslationCall } from './routeTranslationCall.js';
|
|
2
2
|
import { extractStringEntryMetadata } from './extractStringEntryMetadata.js';
|
|
3
3
|
import { SURROUNDING_LINE_COUNT } from '../../../../../utils/constants.js';
|
|
4
|
+
import { handleDerivation } from '../derivation/handleDerivation.js';
|
|
5
|
+
import { nodeToStrings } from '../../parseString.js';
|
|
4
6
|
/**
|
|
5
7
|
* Processes a single translation function call (e.g., t('hello world', { id: 'greeting' })).
|
|
6
8
|
* Extracts the translatable string content and metadata, then adds it to the updates array.
|
|
@@ -31,6 +33,22 @@ export function processTranslationCall(tPath, config, output) {
|
|
|
31
33
|
nodeLoc: tPath.parent.loc,
|
|
32
34
|
surroundingLineCount: SURROUNDING_LINE_COUNT,
|
|
33
35
|
});
|
|
36
|
+
// Resolve derive context variants if present
|
|
37
|
+
let contextVariants;
|
|
38
|
+
if (metadata.contextDeriveExpr) {
|
|
39
|
+
const contextNode = handleDerivation({
|
|
40
|
+
expr: metadata.contextDeriveExpr,
|
|
41
|
+
tPath,
|
|
42
|
+
file: config.file,
|
|
43
|
+
parsingOptions: config.parsingOptions,
|
|
44
|
+
errors: output.errors,
|
|
45
|
+
warnings: output.warnings,
|
|
46
|
+
});
|
|
47
|
+
if (contextNode) {
|
|
48
|
+
contextVariants = nodeToStrings(contextNode);
|
|
49
|
+
}
|
|
50
|
+
delete metadata.contextDeriveExpr;
|
|
51
|
+
}
|
|
34
52
|
// Route tx call to appropriate handler
|
|
35
53
|
routeTranslationCall({
|
|
36
54
|
tPath,
|
|
@@ -38,5 +56,6 @@ export function processTranslationCall(tPath, config, output) {
|
|
|
38
56
|
output,
|
|
39
57
|
arg,
|
|
40
58
|
metadata,
|
|
59
|
+
contextVariants,
|
|
41
60
|
});
|
|
42
61
|
}
|
|
@@ -14,11 +14,12 @@ import { InlineMetadata } from './extractStringEntryMetadata.js';
|
|
|
14
14
|
* @param index - The index of the argument
|
|
15
15
|
* @returns void
|
|
16
16
|
*/
|
|
17
|
-
export declare function routeTranslationCall({ tPath, config, output, arg, metadata, index, }: {
|
|
17
|
+
export declare function routeTranslationCall({ tPath, config, output, arg, metadata, index, contextVariants, }: {
|
|
18
18
|
tPath: NodePath;
|
|
19
19
|
config: ParsingConfig;
|
|
20
20
|
output: ParsingOutput;
|
|
21
21
|
arg: t.CallExpression['arguments'][number];
|
|
22
22
|
metadata: InlineMetadata;
|
|
23
23
|
index?: number;
|
|
24
|
+
contextVariants?: string[];
|
|
24
25
|
}): void;
|
|
@@ -14,7 +14,7 @@ import * as t from '@babel/types';
|
|
|
14
14
|
* @param index - The index of the argument
|
|
15
15
|
* @returns void
|
|
16
16
|
*/
|
|
17
|
-
export function routeTranslationCall({ tPath, config, output, arg, metadata, index, }) {
|
|
17
|
+
export function routeTranslationCall({ tPath, config, output, arg, metadata, index, contextVariants, }) {
|
|
18
18
|
if (t.isArrayExpression(arg) &&
|
|
19
19
|
index == null &&
|
|
20
20
|
!config.ignoreInlineListContent) {
|
|
@@ -30,6 +30,7 @@ export function routeTranslationCall({ tPath, config, output, arg, metadata, ind
|
|
|
30
30
|
arg: element,
|
|
31
31
|
index: i,
|
|
32
32
|
metadata,
|
|
33
|
+
contextVariants,
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -44,6 +45,7 @@ export function routeTranslationCall({ tPath, config, output, arg, metadata, ind
|
|
|
44
45
|
config,
|
|
45
46
|
output,
|
|
46
47
|
index,
|
|
48
|
+
contextVariants,
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
else if (arg.type === 'StringLiteral' ||
|
|
@@ -55,6 +57,7 @@ export function routeTranslationCall({ tPath, config, output, arg, metadata, ind
|
|
|
55
57
|
config,
|
|
56
58
|
output,
|
|
57
59
|
index,
|
|
60
|
+
contextVariants,
|
|
58
61
|
});
|
|
59
62
|
}
|
|
60
63
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
"unified": "^11.0.5",
|
|
111
111
|
"unist-util-visit": "^5.0.0",
|
|
112
112
|
"yaml": "^2.8.0",
|
|
113
|
-
"@generaltranslation/python-extractor": "0.2.
|
|
114
|
-
"
|
|
115
|
-
"
|
|
113
|
+
"@generaltranslation/python-extractor": "0.2.7",
|
|
114
|
+
"generaltranslation": "8.2.2",
|
|
115
|
+
"gt-remark": "1.0.7"
|
|
116
116
|
},
|
|
117
117
|
"devDependencies": {
|
|
118
118
|
"@babel/types": "^7.28.4",
|