gtx-cli 1.2.22 → 1.2.24-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 1.2.23
4
+
5
+ ### Patch Changes
6
+
7
+ - [#336](https://github.com/generaltranslation/gt/pull/336) [`d22c287`](https://github.com/generaltranslation/gt/commit/d22c2871f1b474bc6cf981621a37400a92b4bbff) Thanks [@brian-lou](https://github.com/brian-lou)! - Fix string translation fallback function tracing when translating
8
+
3
9
  ## 1.2.22
4
10
 
5
11
  ### Patch Changes
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.checkFileTranslations = checkFileTranslations;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const console_1 = require("../console");
9
- const generaltranslation_1 = require("generaltranslation");
9
+ const generaltranslation_1 = __importDefault(require("generaltranslation"));
10
10
  const downloadFile_1 = require("./downloadFile");
11
11
  const downloadFileBatch_1 = require("./downloadFileBatch");
12
12
  /**
@@ -132,21 +132,21 @@ function generateStatusSuffixText(downloadStatus, fileQueryData) {
132
132
  // Add completed locales
133
133
  if (status.completed.size > 0) {
134
134
  const completedCodes = Array.from(status.completed)
135
- .map((locale) => (0, generaltranslation_1.getLocaleProperties)(locale).code)
135
+ .map((locale) => generaltranslation_1.default.getLocaleProperties(locale).code)
136
136
  .join(', ');
137
137
  localeStatuses.push(chalk_1.default.green(`${completedCodes}`));
138
138
  }
139
139
  // Add failed locales
140
140
  if (status.failed.size > 0) {
141
141
  const failedCodes = Array.from(status.failed)
142
- .map((locale) => (0, generaltranslation_1.getLocaleProperties)(locale).code)
142
+ .map((locale) => generaltranslation_1.default.getLocaleProperties(locale).code)
143
143
  .join(', ');
144
144
  localeStatuses.push(chalk_1.default.red(`${failedCodes}`));
145
145
  }
146
146
  // Add pending locales
147
147
  if (status.pending.size > 0) {
148
148
  const pendingCodes = Array.from(status.pending)
149
- .map((locale) => (0, generaltranslation_1.getLocaleProperties)(locale).code)
149
+ .map((locale) => generaltranslation_1.default.getLocaleProperties(locale).code)
150
150
  .join(', ');
151
151
  localeStatuses.push(chalk_1.default.yellow(`${pendingCodes}`));
152
152
  }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.waitForUpdates = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const console_1 = require("../console");
9
- const generaltranslation_1 = require("generaltranslation");
9
+ const generaltranslation_1 = __importDefault(require("generaltranslation"));
10
10
  /**
11
11
  * Waits for translations to be deployed to the General Translation API
12
12
  * @param apiKey - The API key for the General Translation API
@@ -47,7 +47,7 @@ const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDura
47
47
  chalk_1.default.green(`[${availableLocales.length}/${locales.length}]`) +
48
48
  ` translations completed`,
49
49
  ...availableLocales.map((locale) => {
50
- const localeProperties = (0, generaltranslation_1.getLocaleProperties)(locale);
50
+ const localeProperties = generaltranslation_1.default.getLocaleProperties(locale);
51
51
  return `Translation completed for ${chalk_1.default.green(localeProperties.name)} (${chalk_1.default.green(localeProperties.code)})`;
52
52
  }),
53
53
  ];
@@ -1,23 +1,26 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.validateSettings = validateSettings;
4
- const generaltranslation_1 = require("generaltranslation");
7
+ const generaltranslation_1 = __importDefault(require("generaltranslation"));
5
8
  const console_1 = require("../console");
6
9
  function validateSettings(settings) {
7
10
  // Validate locales
8
11
  for (const locale of settings.locales) {
9
- if (!(0, generaltranslation_1.isValidLocale)(locale)) {
12
+ if (!generaltranslation_1.default.isValidLocale(locale)) {
10
13
  (0, console_1.logErrorAndExit)(`Provided locales: "${settings?.locales?.join()}", ${locale} is not a valid locale!`);
11
14
  }
12
15
  }
13
- if (settings.defaultLocale && !(0, generaltranslation_1.isValidLocale)(settings.defaultLocale)) {
16
+ if (settings.defaultLocale && !generaltranslation_1.default.isValidLocale(settings.defaultLocale)) {
14
17
  (0, console_1.logErrorAndExit)(`defaultLocale: ${settings.defaultLocale} is not a valid locale!`);
15
18
  }
16
19
  // defaultLocale cannot be a superset of any other locale
17
20
  if (settings.defaultLocale &&
18
- settings.locales.some((locale) => (0, generaltranslation_1.isSupersetLocale)(settings.defaultLocale, locale) &&
19
- !(0, generaltranslation_1.isSupersetLocale)(locale, settings.defaultLocale))) {
20
- const locale = settings.locales.find((locale) => (0, generaltranslation_1.isSupersetLocale)(settings.defaultLocale, locale));
21
+ settings.locales.some((locale) => generaltranslation_1.default.isSupersetLocale(settings.defaultLocale, locale) &&
22
+ !generaltranslation_1.default.isSupersetLocale(locale, settings.defaultLocale))) {
23
+ const locale = settings.locales.find((locale) => generaltranslation_1.default.isSupersetLocale(settings.defaultLocale, locale));
21
24
  (0, console_1.logErrorAndExit)(`defaultLocale: ${settings.defaultLocale} is a superset of another locale (${locale})! Please change the defaultLocale to a more specific locale.`);
22
25
  }
23
26
  }
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseNextConfig = parseNextConfig;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
- const generaltranslation_1 = require("generaltranslation");
8
+ const generaltranslation_1 = __importDefault(require("generaltranslation"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
10
  /**
11
11
  * Extracts projectId, defaultLocale, and locales from a next.config.js file.
@@ -42,7 +42,7 @@ async function parseNextConfig(filePath) {
42
42
  .filter((locale) => typeof locale === 'string')
43
43
  : undefined;
44
44
  // Ensure approvedLocales is an array of strings
45
- const validLocales = locales && locales.every((locale) => (0, generaltranslation_1.isValidLocale)(locale))
45
+ const validLocales = locales && locales.every((locale) => generaltranslation_1.default.isValidLocale(locale))
46
46
  ? locales
47
47
  : undefined;
48
48
  // Return the extracted values if they pass type checks or return null
@@ -38,7 +38,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.attributes = void 0;
40
40
  exports.parseStrings = parseStrings;
41
- const generaltranslation_1 = require("generaltranslation");
42
41
  const t = __importStar(require("@babel/types"));
43
42
  const evaluateJsx_1 = require("../evaluateJsx");
44
43
  const console_1 = require("../../../console");
@@ -77,8 +76,6 @@ function parseStrings(importName, path, updates, errors, file) {
77
76
  const source = arg.type === 'StringLiteral'
78
77
  ? arg.value
79
78
  : arg.quasis[0].value.raw;
80
- // split the string into content (same as runtime behavior)
81
- const content = (0, generaltranslation_1.splitStringToContent)(source);
82
79
  // get metadata and id from options
83
80
  const options = tPath.parent.arguments[1];
84
81
  const metadata = {};
@@ -102,7 +99,7 @@ function parseStrings(importName, path, updates, errors, file) {
102
99
  }
103
100
  updates.push({
104
101
  dataFormat: 'JSX',
105
- source: content,
102
+ source,
106
103
  metadata,
107
104
  });
108
105
  }
@@ -6,12 +6,12 @@ export declare const attributes: string[];
6
6
  *
7
7
  * Supports complex patterns including:
8
8
  * 1. Direct calls: const t = useGT(); t('hello');
9
- * 2. Function parameters: const t = useGT(); getInfo(t); where getInfo uses t() internally
10
- * 3. Cross-file function calls: imported functions that receive t as a parameter
9
+ * 2. Translation callback prop drilling: const t = useGT(); getInfo(t); where getInfo uses t() internally
10
+ * 3. Cross-file function calls: imported functions that receive the translation callback as a parameter
11
11
  *
12
12
  * Example flow:
13
13
  * - const t = useGT();
14
14
  * - const { home } = getInfo(t); // getInfo is imported from './constants'
15
- * - This will parse constants.ts to find t() calls within getInfo function
15
+ * - This will parse constants.ts to find translation calls within getInfo function
16
16
  */
17
17
  export declare function parseStrings(importName: string, path: NodePath, updates: Updates, errors: string[], file: string): void;
@@ -38,7 +38,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.attributes = void 0;
40
40
  exports.parseStrings = parseStrings;
41
- const generaltranslation_1 = require("generaltranslation");
42
41
  const t = __importStar(require("@babel/types"));
43
42
  const evaluateJsx_1 = require("../evaluateJsx");
44
43
  const console_1 = require("../../../console");
@@ -67,8 +66,6 @@ function processTranslationCall(tPath, updates, errors, file) {
67
66
  if (arg.type === 'StringLiteral' ||
68
67
  (t.isTemplateLiteral(arg) && arg.expressions.length === 0)) {
69
68
  const source = arg.type === 'StringLiteral' ? arg.value : arg.quasis[0].value.raw;
70
- // split the string into content (same as runtime behavior)
71
- const content = (0, generaltranslation_1.splitStringToContent)(source);
72
69
  // get metadata and id from options
73
70
  const options = tPath.parent.arguments[1];
74
71
  const metadata = {};
@@ -91,7 +88,7 @@ function processTranslationCall(tPath, updates, errors, file) {
91
88
  }
92
89
  updates.push({
93
90
  dataFormat: 'JSX',
94
- source: content,
91
+ source,
95
92
  metadata,
96
93
  });
97
94
  }
@@ -105,21 +102,163 @@ function processTranslationCall(tPath, updates, errors, file) {
105
102
  }
106
103
  }
107
104
  /**
108
- * Finds all usages of a function parameter within a function's scope and processes
109
- * any translation calls made with that parameter.
105
+ * Extracts the parameter name from a function parameter node, handling TypeScript annotations.
106
+ */
107
+ function extractParameterName(param) {
108
+ if (t.isIdentifier(param)) {
109
+ return param.name;
110
+ }
111
+ return null;
112
+ }
113
+ /**
114
+ * Builds a map of imported function names to their import paths from a given program path.
115
+ * Handles both named imports and default imports.
116
+ *
117
+ * Example: import { getInfo } from './constants' -> Map { 'getInfo' => './constants' }
118
+ * Example: import utils from './utils' -> Map { 'utils' => './utils' }
119
+ */
120
+ function buildImportMap(programPath) {
121
+ const importMap = new Map();
122
+ programPath.traverse({
123
+ ImportDeclaration(importPath) {
124
+ if (t.isStringLiteral(importPath.node.source)) {
125
+ const importSource = importPath.node.source.value;
126
+ importPath.node.specifiers.forEach((spec) => {
127
+ if (t.isImportSpecifier(spec) &&
128
+ t.isIdentifier(spec.imported) &&
129
+ t.isIdentifier(spec.local)) {
130
+ importMap.set(spec.local.name, importSource);
131
+ }
132
+ else if (t.isImportDefaultSpecifier(spec) &&
133
+ t.isIdentifier(spec.local)) {
134
+ importMap.set(spec.local.name, importSource);
135
+ }
136
+ });
137
+ }
138
+ },
139
+ });
140
+ return importMap;
141
+ }
142
+ /**
143
+ * Recursively resolves variable assignments to find all aliases of a translation callback parameter.
144
+ * Handles cases like: const t = translate; const a = translate; const b = a; const c = b;
145
+ *
146
+ * @param scope The scope to search within
147
+ * @param variableName The variable name to resolve
148
+ * @param visited Set to track already visited variables to prevent infinite loops
149
+ * @returns Array of all variable names that reference the original translation callback
150
+ */
151
+ function resolveVariableAliases(scope, variableName, visited = new Set()) {
152
+ if (visited.has(variableName)) {
153
+ return []; // Prevent infinite loops
154
+ }
155
+ visited.add(variableName);
156
+ const aliases = [variableName];
157
+ const binding = scope.bindings[variableName];
158
+ if (binding) {
159
+ // Look for variable declarations that assign this variable to another name
160
+ // Example: const t = translate; or const a = t;
161
+ for (const [otherVarName, otherBinding] of Object.entries(scope.bindings)) {
162
+ if (otherVarName === variableName || visited.has(otherVarName))
163
+ continue;
164
+ const otherBindingTyped = otherBinding;
165
+ if (otherBindingTyped.path &&
166
+ otherBindingTyped.path.isVariableDeclarator() &&
167
+ otherBindingTyped.path.node.init &&
168
+ t.isIdentifier(otherBindingTyped.path.node.init) &&
169
+ otherBindingTyped.path.node.init.name === variableName) {
170
+ // Found an alias: const otherVarName = variableName;
171
+ const nestedAliases = resolveVariableAliases(scope, otherVarName, visited);
172
+ aliases.push(...nestedAliases);
173
+ }
174
+ }
175
+ }
176
+ return aliases;
177
+ }
178
+ /**
179
+ * Handles how translation callbacks are used within code.
180
+ * This covers both direct translation calls (t('hello')) and prop drilling
181
+ * where the translation callback is passed to other functions (getData(t)).
182
+ */
183
+ function handleFunctionCall(tPath, updates, errors, file, importMap) {
184
+ if (tPath.parent.type === 'CallExpression' &&
185
+ tPath.parent.callee === tPath.node) {
186
+ // Direct translation call: t('hello')
187
+ processTranslationCall(tPath, updates, errors, file);
188
+ }
189
+ else if (tPath.parent.type === 'CallExpression' &&
190
+ t.isExpression(tPath.node) &&
191
+ tPath.parent.arguments.includes(tPath.node)) {
192
+ // Parameter passed to another function: getData(t)
193
+ const argIndex = tPath.parent.arguments.indexOf(tPath.node);
194
+ const callee = tPath.parent.callee;
195
+ if (t.isIdentifier(callee)) {
196
+ const calleeBinding = tPath.scope.getBinding(callee.name);
197
+ if (calleeBinding && calleeBinding.path.isFunction()) {
198
+ const functionPath = calleeBinding.path;
199
+ processFunctionIfMatches(callee.name, argIndex, functionPath.node, functionPath, updates, errors, file);
200
+ }
201
+ // Handle arrow functions assigned to variables: const getData = (t) => {...}
202
+ else if (calleeBinding &&
203
+ calleeBinding.path.isVariableDeclarator() &&
204
+ calleeBinding.path.node.init &&
205
+ (t.isArrowFunctionExpression(calleeBinding.path.node.init) ||
206
+ t.isFunctionExpression(calleeBinding.path.node.init))) {
207
+ const initPath = calleeBinding.path.get('init');
208
+ processFunctionIfMatches(callee.name, argIndex, calleeBinding.path.node.init, initPath, updates, errors, file);
209
+ }
210
+ // If not found locally, check if it's an imported function
211
+ else if (importMap.has(callee.name)) {
212
+ const importPath = importMap.get(callee.name);
213
+ const resolvedPath = resolveImportPath(file, importPath);
214
+ if (resolvedPath) {
215
+ findFunctionInFile(resolvedPath, callee.name, argIndex, updates, errors);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+ /**
222
+ * Processes a user-defined function that receives a translation callback as a parameter.
223
+ * Validates the function has enough parameters and traces how the translation callback
224
+ * is used within that function's body.
225
+ */
226
+ function processFunctionIfMatches(_functionName, argIndex, functionNode, functionPath, updates, errors, filePath) {
227
+ if (functionNode.params.length > argIndex) {
228
+ const param = functionNode.params[argIndex];
229
+ const paramName = extractParameterName(param);
230
+ if (paramName) {
231
+ findFunctionParameterUsage(functionPath, paramName, updates, errors, filePath);
232
+ }
233
+ }
234
+ }
235
+ /**
236
+ * Finds all usages of a translation callback parameter within a user-defined function's scope.
237
+ * Processes both direct translation calls and cases where the translation callback is passed
238
+ * to other functions (prop drilling).
110
239
  *
111
240
  * Example: In function getInfo(t) { return t('hello'); }, this finds the t('hello') call.
241
+ * Example: In function getData(t) { return getFooter(t); }, this finds and traces into getFooter.
112
242
  */
113
243
  function findFunctionParameterUsage(functionPath, parameterName, updates, errors, file) {
114
244
  // Look for the function body and find all usages of the parameter
115
245
  if (functionPath.isFunction()) {
116
246
  const functionScope = functionPath.scope;
117
- const binding = functionScope.bindings[parameterName];
118
- if (binding) {
119
- binding.referencePaths.forEach((refPath) => {
120
- processTranslationCall(refPath, updates, errors, file);
121
- });
122
- }
247
+ // Resolve all aliases of the translation callback parameter
248
+ // Example: translate -> [translate, t, a, b] for const t = translate; const a = t; const b = a;
249
+ const allParameterNames = resolveVariableAliases(functionScope, parameterName);
250
+ // Build import map for this function's scope to handle cross-file calls
251
+ const programPath = functionPath.scope.getProgramParent().path;
252
+ const importMap = buildImportMap(programPath);
253
+ // Process references for all parameter names and their aliases
254
+ allParameterNames.forEach((name) => {
255
+ const binding = functionScope.bindings[name];
256
+ if (binding) {
257
+ binding.referencePaths.forEach((refPath) => {
258
+ handleFunctionCall(refPath, updates, errors, file, importMap);
259
+ });
260
+ }
261
+ });
123
262
  }
124
263
  }
125
264
  /**
@@ -164,12 +303,31 @@ function resolveImportPath(currentFile, importPath) {
164
303
  return resolve.sync(importPath, { basedir, extensions });
165
304
  }
166
305
  catch {
306
+ // If resolution fails, try to manually replace .js/.jsx with .ts/.tsx for source files
307
+ if (importPath.endsWith('.js')) {
308
+ const tsPath = importPath.replace(/\.js$/, '.ts');
309
+ try {
310
+ return resolve.sync(tsPath, { basedir, extensions });
311
+ }
312
+ catch {
313
+ // Continue to return null
314
+ }
315
+ }
316
+ else if (importPath.endsWith('.jsx')) {
317
+ const tsxPath = importPath.replace(/\.jsx$/, '.tsx');
318
+ try {
319
+ return resolve.sync(tsxPath, { basedir, extensions });
320
+ }
321
+ catch {
322
+ // Continue to return null
323
+ }
324
+ }
167
325
  return null;
168
326
  }
169
327
  }
170
328
  /**
171
- * Searches for a specific function in a file and analyzes how a particular parameter
172
- * (at argIndex position) is used within that function for translation calls.
329
+ * Searches for a specific user-defined function in a file and analyzes how a translation callback
330
+ * parameter (at argIndex position) is used within that function.
173
331
  *
174
332
  * Handles multiple function declaration patterns:
175
333
  * - function getInfo(t) { ... }
@@ -186,25 +344,8 @@ function findFunctionInFile(filePath, functionName, argIndex, updates, errors) {
186
344
  (0, traverse_1.default)(ast, {
187
345
  // Handle function declarations: function getInfo(t) { ... }
188
346
  FunctionDeclaration(path) {
189
- if (path.node.id?.name === functionName &&
190
- path.node.params.length > argIndex) {
191
- const param = path.node.params[argIndex];
192
- if (t.isIdentifier(param)) {
193
- findFunctionParameterUsage(path, param.name, updates, errors, filePath);
194
- }
195
- }
196
- },
197
- // Handle exported function declarations: export function getInfo(t) { ... }
198
- ExportNamedDeclaration(path) {
199
- if (path.node.declaration &&
200
- t.isFunctionDeclaration(path.node.declaration)) {
201
- const func = path.node.declaration;
202
- if (func.id?.name === functionName && func.params.length > argIndex) {
203
- const param = func.params[argIndex];
204
- if (t.isIdentifier(param)) {
205
- findFunctionParameterUsage(path.get('declaration'), param.name, updates, errors, filePath);
206
- }
207
- }
347
+ if (path.node.id?.name === functionName) {
348
+ processFunctionIfMatches(functionName, argIndex, path.node, path, updates, errors, filePath);
208
349
  }
209
350
  },
210
351
  // Handle variable declarations: const getInfo = (t) => { ... }
@@ -213,13 +354,9 @@ function findFunctionInFile(filePath, functionName, argIndex, updates, errors) {
213
354
  path.node.id.name === functionName &&
214
355
  path.node.init &&
215
356
  (t.isArrowFunctionExpression(path.node.init) ||
216
- t.isFunctionExpression(path.node.init)) &&
217
- path.node.init.params.length > argIndex) {
218
- const param = path.node.init.params[argIndex];
219
- if (t.isIdentifier(param)) {
220
- const initPath = path.get('init');
221
- findFunctionParameterUsage(initPath, param.name, updates, errors, filePath);
222
- }
357
+ t.isFunctionExpression(path.node.init))) {
358
+ const initPath = path.get('init');
359
+ processFunctionIfMatches(functionName, argIndex, path.node.init, initPath, updates, errors, filePath);
223
360
  }
224
361
  },
225
362
  });
@@ -233,35 +370,17 @@ function findFunctionInFile(filePath, functionName, argIndex, updates, errors) {
233
370
  *
234
371
  * Supports complex patterns including:
235
372
  * 1. Direct calls: const t = useGT(); t('hello');
236
- * 2. Function parameters: const t = useGT(); getInfo(t); where getInfo uses t() internally
237
- * 3. Cross-file function calls: imported functions that receive t as a parameter
373
+ * 2. Translation callback prop drilling: const t = useGT(); getInfo(t); where getInfo uses t() internally
374
+ * 3. Cross-file function calls: imported functions that receive the translation callback as a parameter
238
375
  *
239
376
  * Example flow:
240
377
  * - const t = useGT();
241
378
  * - const { home } = getInfo(t); // getInfo is imported from './constants'
242
- * - This will parse constants.ts to find t() calls within getInfo function
379
+ * - This will parse constants.ts to find translation calls within getInfo function
243
380
  */
244
381
  function parseStrings(importName, path, updates, errors, file) {
245
382
  // First, collect all imports in this file to track cross-file function calls
246
- const importMap = new Map(); // functionName -> importPath
247
- path.scope.getProgramParent().path.traverse({
248
- ImportDeclaration(importPath) {
249
- if (t.isStringLiteral(importPath.node.source)) {
250
- const importSource = importPath.node.source.value;
251
- importPath.node.specifiers.forEach((spec) => {
252
- if (t.isImportSpecifier(spec) &&
253
- t.isIdentifier(spec.imported) &&
254
- t.isIdentifier(spec.local)) {
255
- importMap.set(spec.local.name, importSource);
256
- }
257
- else if (t.isImportDefaultSpecifier(spec) &&
258
- t.isIdentifier(spec.local)) {
259
- importMap.set(spec.local.name, importSource);
260
- }
261
- });
262
- }
263
- },
264
- });
383
+ const importMap = buildImportMap(path.scope.getProgramParent().path);
265
384
  const referencePaths = path.scope.bindings[importName]?.referencePaths || [];
266
385
  for (const refPath of referencePaths) {
267
386
  // Find call expressions of useGT() / await getGT()
@@ -280,40 +399,7 @@ function parseStrings(importName, path, updates, errors, file) {
280
399
  const variableScope = effectiveParent.scope;
281
400
  const tReferencePaths = variableScope.bindings[tFuncName]?.referencePaths || [];
282
401
  for (const tPath of tReferencePaths) {
283
- // Check if this is a direct call to the translation function
284
- if (tPath.parent.type === 'CallExpression' &&
285
- tPath.parent.callee === tPath.node) {
286
- processTranslationCall(tPath, updates, errors, file);
287
- }
288
- // Check if this is being passed as an argument to another function
289
- else if (tPath.parent.type === 'CallExpression' &&
290
- t.isExpression(tPath.node) &&
291
- tPath.parent.arguments.includes(tPath.node)) {
292
- // Find which parameter position this is
293
- const argIndex = tPath.parent.arguments.indexOf(tPath.node);
294
- // Try to find the function definition being called
295
- const callee = tPath.parent.callee;
296
- if (t.isIdentifier(callee)) {
297
- // Look for function declarations or function expressions with this name
298
- const calleeBinding = tPath.scope.getBinding(callee.name);
299
- if (calleeBinding && calleeBinding.path.isFunction()) {
300
- const functionPath = calleeBinding.path;
301
- const params = functionPath.node.params;
302
- if (params[argIndex] && t.isIdentifier(params[argIndex])) {
303
- const paramName = params[argIndex].name;
304
- findFunctionParameterUsage(functionPath, paramName, updates, errors, file);
305
- }
306
- }
307
- // If not found locally, check if it's an imported function
308
- else if (importMap.has(callee.name)) {
309
- const importPath = importMap.get(callee.name);
310
- const resolvedPath = resolveImportPath(file, importPath);
311
- if (resolvedPath) {
312
- findFunctionInFile(resolvedPath, callee.name, argIndex, updates, errors);
313
- }
314
- }
315
- }
316
- }
402
+ handleFunctionCall(tPath, updates, errors, file, importMap);
317
403
  }
318
404
  }
319
405
  }
@@ -9,7 +9,6 @@ const node_path_1 = __importDefault(require("node:path"));
9
9
  const os_1 = __importDefault(require("os"));
10
10
  const esbuild_1 = require("esbuild");
11
11
  const flattenDictionary_1 = __importDefault(require("../utils/flattenDictionary"));
12
- const generaltranslation_1 = require("generaltranslation");
13
12
  const loadJSON_1 = __importDefault(require("../../fs/loadJSON"));
14
13
  const id_1 = require("generaltranslation/id");
15
14
  const getEntryAndMetadata_1 = __importDefault(require("../utils/getEntryAndMetadata"));
@@ -55,14 +54,13 @@ async function createDictionaryUpdates(options, dictionaryPath, esbuildConfig) {
55
54
  for (const id of Object.keys(dictionary)) {
56
55
  const { entry, metadata: props, // context, etc.
57
56
  } = (0, getEntryAndMetadata_1.default)(dictionary[id]);
58
- const source = (0, generaltranslation_1.splitStringToContent)(entry);
59
57
  const context = props?.context;
60
58
  const metadata = {
61
59
  id,
62
60
  ...(context && { context }),
63
61
  // This hash isn't actually used by the GT API, just for consistency sake
64
62
  hash: (0, id_1.hashJsxChildren)({
65
- source,
63
+ source: entry,
66
64
  ...(context && { context }),
67
65
  ...(id && { id }),
68
66
  dataFormat: 'JSX',
@@ -70,7 +68,7 @@ async function createDictionaryUpdates(options, dictionaryPath, esbuildConfig) {
70
68
  };
71
69
  updates.push({
72
70
  dataFormat: 'JSX',
73
- source,
71
+ source: entry,
74
72
  metadata,
75
73
  });
76
74
  }
@@ -7,7 +7,7 @@ exports.getDesiredLocales = getDesiredLocales;
7
7
  const internal_1 = require("generaltranslation/internal");
8
8
  const console_1 = require("../console");
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
- const generaltranslation_1 = require("generaltranslation");
10
+ const generaltranslation_1 = __importDefault(require("generaltranslation"));
11
11
  async function getDesiredLocales() {
12
12
  // Ask for the default locale
13
13
  const defaultLocale = await (0, console_1.promptText)({
@@ -24,7 +24,7 @@ async function getDesiredLocales() {
24
24
  return 'Please enter at least one locale';
25
25
  }
26
26
  for (const locale of localeList) {
27
- if (!(0, generaltranslation_1.isValidLocale)(locale)) {
27
+ if (!generaltranslation_1.default.isValidLocale(locale)) {
28
28
  return 'Please enter a valid locale (e.g., en, fr, es)';
29
29
  }
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "1.2.22",
3
+ "version": "1.2.24-alpha.0",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -79,7 +79,7 @@
79
79
  "esbuild": "^0.25.4",
80
80
  "fast-glob": "^3.3.3",
81
81
  "form-data": "^4.0.2",
82
- "generaltranslation": "^6.2.10",
82
+ "generaltranslation": "^7.0.0-alpha.0",
83
83
  "open": "^10.1.1",
84
84
  "ora": "^8.2.0",
85
85
  "resolve": "^1.22.10",