gt 2.10.3 → 2.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/react/jsx/utils/constants.d.ts +2 -0
- package/dist/react/jsx/utils/constants.js +7 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +3 -2
- package/dist/react/jsx/utils/parseStringFunction.d.ts +4 -4
- package/dist/react/jsx/utils/parseStringFunction.js +9 -9
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.10.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1113](https://github.com/generaltranslation/gt/pull/1113) [`7e2bbc5`](https://github.com/generaltranslation/gt/commit/7e2bbc575d9d2bcc358bfa11c880a7bf4aac8636) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: add string translation function t()
|
|
8
|
+
|
|
3
9
|
## 2.10.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "2.10.
|
|
1
|
+
export declare const PACKAGE_VERSION = "2.10.4";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
export const PACKAGE_VERSION = '2.10.
|
|
2
|
+
export const PACKAGE_VERSION = '2.10.4';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const DECLARE_VAR_FUNCTION = "declareVar";
|
|
2
2
|
export declare const DECLARE_STATIC_FUNCTION = "declareStatic";
|
|
3
3
|
export declare const MSG_REGISTRATION_FUNCTION = "msg";
|
|
4
|
+
export declare const T_REGISTRATION_FUNCTION = "t";
|
|
4
5
|
export declare const INLINE_TRANSLATION_HOOK = "useGT";
|
|
5
6
|
export declare const INLINE_TRANSLATION_HOOK_ASYNC = "getGT";
|
|
6
7
|
export declare const INLINE_MESSAGE_HOOK = "useMessages";
|
|
@@ -9,6 +10,7 @@ export declare const TRANSLATION_COMPONENT = "T";
|
|
|
9
10
|
export declare const STATIC_COMPONENT = "Static";
|
|
10
11
|
export declare const BRANCH_COMPONENT = "Branch";
|
|
11
12
|
export declare const GT_TRANSLATION_FUNCS: string[];
|
|
13
|
+
export declare const STRING_REGISTRATION_FUNCS: readonly ["msg", "t"];
|
|
12
14
|
export declare const VARIABLE_COMPONENTS: string[];
|
|
13
15
|
export declare const GT_ATTRIBUTES_WITH_SUGAR: readonly ["$id", "$context", "$maxChars"];
|
|
14
16
|
export declare const GT_ATTRIBUTES: readonly ["id", "context", "maxChars", "$id", "$context", "$maxChars"];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const DECLARE_VAR_FUNCTION = 'declareVar';
|
|
2
2
|
export const DECLARE_STATIC_FUNCTION = 'declareStatic';
|
|
3
3
|
export const MSG_REGISTRATION_FUNCTION = 'msg';
|
|
4
|
+
export const T_REGISTRATION_FUNCTION = 't';
|
|
4
5
|
export const INLINE_TRANSLATION_HOOK = 'useGT';
|
|
5
6
|
export const INLINE_TRANSLATION_HOOK_ASYNC = 'getGT';
|
|
6
7
|
export const INLINE_MESSAGE_HOOK = 'useMessages';
|
|
@@ -15,6 +16,7 @@ export const GT_TRANSLATION_FUNCS = [
|
|
|
15
16
|
INLINE_MESSAGE_HOOK,
|
|
16
17
|
INLINE_MESSAGE_HOOK_ASYNC,
|
|
17
18
|
MSG_REGISTRATION_FUNCTION,
|
|
19
|
+
T_REGISTRATION_FUNCTION,
|
|
18
20
|
DECLARE_VAR_FUNCTION,
|
|
19
21
|
DECLARE_STATIC_FUNCTION,
|
|
20
22
|
TRANSLATION_COMPONENT,
|
|
@@ -26,6 +28,11 @@ export const GT_TRANSLATION_FUNCS = [
|
|
|
26
28
|
BRANCH_COMPONENT,
|
|
27
29
|
'Plural',
|
|
28
30
|
];
|
|
31
|
+
// GT String translation functions
|
|
32
|
+
export const STRING_REGISTRATION_FUNCS = [
|
|
33
|
+
MSG_REGISTRATION_FUNCTION,
|
|
34
|
+
T_REGISTRATION_FUNCTION,
|
|
35
|
+
];
|
|
29
36
|
// Valid variable components
|
|
30
37
|
export const VARIABLE_COMPONENTS = [
|
|
31
38
|
'Var',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import traverseModule from '@babel/traverse';
|
|
2
|
-
import { GT_TRANSLATION_FUNCS, INLINE_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK_ASYNC, INLINE_MESSAGE_HOOK, INLINE_MESSAGE_HOOK_ASYNC, MSG_REGISTRATION_FUNCTION, TRANSLATION_COMPONENT, } from '../../jsx/utils/constants.js';
|
|
2
|
+
import { GT_TRANSLATION_FUNCS, INLINE_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK_ASYNC, INLINE_MESSAGE_HOOK, INLINE_MESSAGE_HOOK_ASYNC, MSG_REGISTRATION_FUNCTION, T_REGISTRATION_FUNCTION, TRANSLATION_COMPONENT, } from '../../jsx/utils/constants.js';
|
|
3
3
|
import { extractImportName } from './parseAst.js';
|
|
4
4
|
// Handle CommonJS/ESM interop
|
|
5
5
|
const traverse = traverseModule.default || traverseModule;
|
|
@@ -23,7 +23,8 @@ export function getPathsAndAliases(ast, pkgs) {
|
|
|
23
23
|
name.original === INLINE_TRANSLATION_HOOK_ASYNC ||
|
|
24
24
|
name.original === INLINE_MESSAGE_HOOK ||
|
|
25
25
|
name.original === INLINE_MESSAGE_HOOK_ASYNC ||
|
|
26
|
-
name.original === MSG_REGISTRATION_FUNCTION
|
|
26
|
+
name.original === MSG_REGISTRATION_FUNCTION ||
|
|
27
|
+
name.original === T_REGISTRATION_FUNCTION) {
|
|
27
28
|
inlineTranslationPaths.push({
|
|
28
29
|
localName: name.local,
|
|
29
30
|
path,
|
|
@@ -18,13 +18,13 @@ export declare function resolveVariableAliases(scope: Scope, variableName: strin
|
|
|
18
18
|
* Main entry point for parsing translation strings from useGT() and getGT() calls.
|
|
19
19
|
*
|
|
20
20
|
* Supports complex patterns including:
|
|
21
|
-
* 1. Direct calls: const
|
|
22
|
-
* 2. Translation callback prop drilling: const
|
|
21
|
+
* 1. Direct calls: const gt = useGT(); gt('hello');
|
|
22
|
+
* 2. Translation callback prop drilling: const gt = useGT(); getInfo(gt); where getInfo uses gt() internally
|
|
23
23
|
* 3. Cross-file function calls: imported functions that receive the translation callback as a parameter
|
|
24
24
|
*
|
|
25
25
|
* Example flow:
|
|
26
|
-
* - const
|
|
27
|
-
* - const { home } = getInfo(
|
|
26
|
+
* - const gt = useGT();
|
|
27
|
+
* - const { home } = getInfo(gt); // getInfo is imported from './constants'
|
|
28
28
|
* - This will parse constants.ts to find translation calls within getInfo function
|
|
29
29
|
*/
|
|
30
30
|
export declare function parseStrings(importName: string, originalName: string, path: NodePath, config: ParsingConfig, output: ParsingOutput): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
|
-
import {
|
|
2
|
+
import { INLINE_TRANSLATION_HOOK, INLINE_TRANSLATION_HOOK_ASYNC, INLINE_MESSAGE_HOOK, INLINE_MESSAGE_HOOK_ASYNC, STRING_REGISTRATION_FUNCS, } from './constants.js';
|
|
3
3
|
import { warnAsyncUseGT, warnSyncGetGT } from '../../../console/index.js';
|
|
4
4
|
import traverseModule from '@babel/traverse';
|
|
5
5
|
// Handle CommonJS/ESM interop
|
|
@@ -260,13 +260,13 @@ function processFunctionInFile(filePath, functionName, argIndex, config, state,
|
|
|
260
260
|
* Main entry point for parsing translation strings from useGT() and getGT() calls.
|
|
261
261
|
*
|
|
262
262
|
* Supports complex patterns including:
|
|
263
|
-
* 1. Direct calls: const
|
|
264
|
-
* 2. Translation callback prop drilling: const
|
|
263
|
+
* 1. Direct calls: const gt = useGT(); gt('hello');
|
|
264
|
+
* 2. Translation callback prop drilling: const gt = useGT(); getInfo(gt); where getInfo uses gt() internally
|
|
265
265
|
* 3. Cross-file function calls: imported functions that receive the translation callback as a parameter
|
|
266
266
|
*
|
|
267
267
|
* Example flow:
|
|
268
|
-
* - const
|
|
269
|
-
* - const { home } = getInfo(
|
|
268
|
+
* - const gt = useGT();
|
|
269
|
+
* - const { home } = getInfo(gt); // getInfo is imported from './constants'
|
|
270
270
|
* - This will parse constants.ts to find translation calls within getInfo function
|
|
271
271
|
*/
|
|
272
272
|
export function parseStrings(importName, originalName, path, config, output) {
|
|
@@ -274,9 +274,9 @@ export function parseStrings(importName, originalName, path, config, output) {
|
|
|
274
274
|
const importMap = buildImportMap(path.scope.getProgramParent().path);
|
|
275
275
|
const referencePaths = path.scope.bindings[importName]?.referencePaths || [];
|
|
276
276
|
for (const refPath of referencePaths) {
|
|
277
|
-
// Handle msg() calls directly without variable assignment
|
|
278
|
-
if (originalName
|
|
279
|
-
const
|
|
277
|
+
// Handle msg(), t() calls directly without variable assignment
|
|
278
|
+
if (STRING_REGISTRATION_FUNCS.includes(originalName)) {
|
|
279
|
+
const stringRegistrationConfig = {
|
|
280
280
|
parsingOptions: config.parsingOptions,
|
|
281
281
|
file: config.file,
|
|
282
282
|
ignoreInlineMetadata: false,
|
|
@@ -288,7 +288,7 @@ export function parseStrings(importName, originalName, path, config, output) {
|
|
|
288
288
|
// Check if this is a direct call to msg('string')
|
|
289
289
|
if (refPath.parent.type === 'CallExpression' &&
|
|
290
290
|
refPath.parent.callee === refPath.node) {
|
|
291
|
-
processTranslationCall(refPath,
|
|
291
|
+
processTranslationCall(refPath, stringRegistrationConfig, output);
|
|
292
292
|
}
|
|
293
293
|
continue;
|
|
294
294
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.4",
|
|
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.1.2",
|
|
113
114
|
"generaltranslation": "8.1.16",
|
|
114
|
-
"gt-remark": "1.0.5"
|
|
115
|
-
"@generaltranslation/python-extractor": "0.1.2"
|
|
115
|
+
"gt-remark": "1.0.5"
|
|
116
116
|
},
|
|
117
117
|
"devDependencies": {
|
|
118
118
|
"@babel/types": "^7.28.4",
|