gtx-cli 2.0.16 → 2.0.17
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/api/checkFileTranslations.js +4 -2
- package/dist/api/downloadFile.d.ts +1 -1
- package/dist/api/downloadFile.js +2 -2
- package/dist/api/downloadFileBatch.d.ts +1 -0
- package/dist/api/downloadFileBatch.js +7 -5
- package/dist/formats/files/translate.js +4 -2
- package/dist/formats/files/upload.js +4 -2
- package/dist/formats/json/mergeJson.d.ts +1 -1
- package/dist/formats/json/mergeJson.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.0.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#514](https://github.com/generaltranslation/gt/pull/514) [`4beab58`](https://github.com/generaltranslation/gt/commit/4beab58142fa014bed5dbfc0acab03a1d1536b05) Thanks [@brian-lou](https://github.com/brian-lou)! - Fix jsonSchema conflict with transform option
|
|
8
|
+
|
|
3
9
|
## 2.0.16
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -180,6 +180,7 @@ async function checkTranslationDeployment(fileQueryData, downloadStatus, spinner
|
|
|
180
180
|
const outputPath = resolveOutputPath(fileName, locale);
|
|
181
181
|
return {
|
|
182
182
|
translationId,
|
|
183
|
+
inputPath: fileName,
|
|
183
184
|
outputPath,
|
|
184
185
|
locale,
|
|
185
186
|
fileLocale: `${fileName}:${locale}`,
|
|
@@ -187,9 +188,10 @@ async function checkTranslationDeployment(fileQueryData, downloadStatus, spinner
|
|
|
187
188
|
});
|
|
188
189
|
// Use batch download if there are multiple files
|
|
189
190
|
if (batchFiles.length > 1) {
|
|
190
|
-
const batchResult = await downloadFileBatch(batchFiles.map(({ translationId, outputPath, locale }) => ({
|
|
191
|
+
const batchResult = await downloadFileBatch(batchFiles.map(({ translationId, outputPath, inputPath, locale }) => ({
|
|
191
192
|
translationId,
|
|
192
193
|
outputPath,
|
|
194
|
+
inputPath,
|
|
193
195
|
locale,
|
|
194
196
|
})), options);
|
|
195
197
|
// Process results
|
|
@@ -206,7 +208,7 @@ async function checkTranslationDeployment(fileQueryData, downloadStatus, spinner
|
|
|
206
208
|
else if (batchFiles.length === 1) {
|
|
207
209
|
// For a single file, use the original downloadFile method
|
|
208
210
|
const file = batchFiles[0];
|
|
209
|
-
const result = await downloadFile(file.translationId, file.outputPath, file.locale, options);
|
|
211
|
+
const result = await downloadFile(file.translationId, file.outputPath, file.inputPath, file.locale, options);
|
|
210
212
|
if (result) {
|
|
211
213
|
downloadStatus.downloaded.add(file.fileLocale);
|
|
212
214
|
}
|
|
@@ -6,4 +6,4 @@ import { Settings } from '../types/index.js';
|
|
|
6
6
|
* @param maxRetries - The maximum number of retries to attempt
|
|
7
7
|
* @param retryDelay - The delay between retries in milliseconds
|
|
8
8
|
*/
|
|
9
|
-
export declare function downloadFile(translationId: string, outputPath: string, locale: string, options: Settings, maxRetries?: number, retryDelay?: number): Promise<boolean>;
|
|
9
|
+
export declare function downloadFile(translationId: string, outputPath: string, inputPath: string, locale: string, options: Settings, maxRetries?: number, retryDelay?: number): Promise<boolean>;
|
package/dist/api/downloadFile.js
CHANGED
|
@@ -12,7 +12,7 @@ import { TextDecoder } from 'node:util';
|
|
|
12
12
|
* @param maxRetries - The maximum number of retries to attempt
|
|
13
13
|
* @param retryDelay - The delay between retries in milliseconds
|
|
14
14
|
*/
|
|
15
|
-
export async function downloadFile(translationId, outputPath, locale, options, maxRetries = 3, retryDelay = 1000) {
|
|
15
|
+
export async function downloadFile(translationId, outputPath, inputPath, locale, options, maxRetries = 3, retryDelay = 1000) {
|
|
16
16
|
let retries = 0;
|
|
17
17
|
while (retries <= maxRetries) {
|
|
18
18
|
try {
|
|
@@ -29,7 +29,7 @@ export async function downloadFile(translationId, outputPath, locale, options, m
|
|
|
29
29
|
if (jsonSchema) {
|
|
30
30
|
const originalContent = fs.readFileSync(outputPath, 'utf8');
|
|
31
31
|
if (originalContent) {
|
|
32
|
-
data = mergeJson(originalContent,
|
|
32
|
+
data = mergeJson(originalContent, inputPath, options.options, [
|
|
33
33
|
{
|
|
34
34
|
translatedContent: data,
|
|
35
35
|
targetLocale: locale,
|
|
@@ -17,6 +17,7 @@ export async function downloadFileBatch(files, options, maxRetries = 3, retryDel
|
|
|
17
17
|
const result = { successful: [], failed: [] };
|
|
18
18
|
// Create a map of translationId to outputPath for easier lookup
|
|
19
19
|
const outputPathMap = new Map(files.map((file) => [file.translationId, file.outputPath]));
|
|
20
|
+
const inputPathMap = new Map(files.map((file) => [file.translationId, file.inputPath]));
|
|
20
21
|
const localeMap = new Map(files.map((file) => [file.translationId, file.locale]));
|
|
21
22
|
while (retries <= maxRetries) {
|
|
22
23
|
try {
|
|
@@ -28,9 +29,10 @@ export async function downloadFileBatch(files, options, maxRetries = 3, retryDel
|
|
|
28
29
|
try {
|
|
29
30
|
const translationId = file.id;
|
|
30
31
|
const outputPath = outputPathMap.get(translationId);
|
|
32
|
+
const inputPath = inputPathMap.get(translationId);
|
|
31
33
|
const locale = localeMap.get(translationId);
|
|
32
|
-
if (!outputPath) {
|
|
33
|
-
logWarning(`No output path found for file: ${translationId}`);
|
|
34
|
+
if (!outputPath || !inputPath) {
|
|
35
|
+
logWarning(`No input/output path found for file: ${translationId}`);
|
|
34
36
|
result.failed.push(translationId);
|
|
35
37
|
continue;
|
|
36
38
|
}
|
|
@@ -41,11 +43,11 @@ export async function downloadFileBatch(files, options, maxRetries = 3, retryDel
|
|
|
41
43
|
}
|
|
42
44
|
let data = file.data;
|
|
43
45
|
if (options.options?.jsonSchema && locale) {
|
|
44
|
-
const jsonSchema = validateJsonSchema(options.options,
|
|
46
|
+
const jsonSchema = validateJsonSchema(options.options, inputPath);
|
|
45
47
|
if (jsonSchema) {
|
|
46
|
-
const originalContent = fs.readFileSync(
|
|
48
|
+
const originalContent = fs.readFileSync(inputPath, 'utf8');
|
|
47
49
|
if (originalContent) {
|
|
48
|
-
data = mergeJson(originalContent,
|
|
50
|
+
data = mergeJson(originalContent, inputPath, options.options, [
|
|
49
51
|
{
|
|
50
52
|
translatedContent: file.data,
|
|
51
53
|
targetLocale: locale,
|
|
@@ -132,6 +132,7 @@ async function processInitialTranslations(translations = [], fileMapping, option
|
|
|
132
132
|
}
|
|
133
133
|
return {
|
|
134
134
|
translationId: id,
|
|
135
|
+
inputPath: fileName,
|
|
135
136
|
outputPath,
|
|
136
137
|
fileLocale: `${fileName}:${locale}`,
|
|
137
138
|
locale,
|
|
@@ -143,9 +144,10 @@ async function processInitialTranslations(translations = [], fileMapping, option
|
|
|
143
144
|
}
|
|
144
145
|
// Use batch download if there are multiple files
|
|
145
146
|
if (batchFiles.length > 1) {
|
|
146
|
-
const batchResult = await downloadFileBatch(batchFiles.map(({ translationId, outputPath, locale }) => ({
|
|
147
|
+
const batchResult = await downloadFileBatch(batchFiles.map(({ translationId, outputPath, inputPath, locale }) => ({
|
|
147
148
|
translationId,
|
|
148
149
|
outputPath,
|
|
150
|
+
inputPath,
|
|
149
151
|
locale,
|
|
150
152
|
})), options);
|
|
151
153
|
// Process results
|
|
@@ -162,7 +164,7 @@ async function processInitialTranslations(translations = [], fileMapping, option
|
|
|
162
164
|
else if (batchFiles.length === 1) {
|
|
163
165
|
// For a single file, use the original downloadFile method
|
|
164
166
|
const file = batchFiles[0];
|
|
165
|
-
const result = await downloadFile(file.translationId, file.outputPath, file.locale, options);
|
|
167
|
+
const result = await downloadFile(file.translationId, file.outputPath, file.inputPath, file.locale, options);
|
|
166
168
|
if (result) {
|
|
167
169
|
downloadStatus.downloaded.add(file.fileLocale);
|
|
168
170
|
}
|
|
@@ -147,6 +147,7 @@ async function processInitialTranslations(translations = [], fileMapping, option
|
|
|
147
147
|
return {
|
|
148
148
|
translationId: id,
|
|
149
149
|
outputPath,
|
|
150
|
+
inputPath: fileName,
|
|
150
151
|
fileLocale: `${fileName}:${locale}`,
|
|
151
152
|
locale,
|
|
152
153
|
};
|
|
@@ -157,9 +158,10 @@ async function processInitialTranslations(translations = [], fileMapping, option
|
|
|
157
158
|
}
|
|
158
159
|
// Use batch download if there are multiple files
|
|
159
160
|
if (batchFiles.length > 1) {
|
|
160
|
-
const batchResult = await downloadFileBatch(batchFiles.map(({ translationId, outputPath, locale }) => ({
|
|
161
|
+
const batchResult = await downloadFileBatch(batchFiles.map(({ translationId, outputPath, inputPath, locale }) => ({
|
|
161
162
|
translationId,
|
|
162
163
|
outputPath,
|
|
164
|
+
inputPath,
|
|
163
165
|
locale,
|
|
164
166
|
})), options);
|
|
165
167
|
// Process results
|
|
@@ -176,7 +178,7 @@ async function processInitialTranslations(translations = [], fileMapping, option
|
|
|
176
178
|
else if (batchFiles.length === 1) {
|
|
177
179
|
// For a single file, use the original downloadFile method
|
|
178
180
|
const file = batchFiles[0];
|
|
179
|
-
const result = await downloadFile(file.translationId, file.outputPath, file.locale, options);
|
|
181
|
+
const result = await downloadFile(file.translationId, file.outputPath, file.inputPath, file.locale, options);
|
|
180
182
|
if (result) {
|
|
181
183
|
downloadStatus.downloaded.add(file.fileLocale);
|
|
182
184
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AdditionalOptions, SourceObjectOptions } from '../../types/index.js';
|
|
2
|
-
export declare function mergeJson(originalContent: string,
|
|
2
|
+
export declare function mergeJson(originalContent: string, inputPath: string, options: AdditionalOptions, targets: {
|
|
3
3
|
translatedContent: string;
|
|
4
4
|
targetLocale: string;
|
|
5
5
|
}[], defaultLocale: string): string[];
|
|
@@ -4,8 +4,8 @@ import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPoin
|
|
|
4
4
|
import { JSONPath } from 'jsonpath-plus';
|
|
5
5
|
import { getLocaleProperties } from 'generaltranslation';
|
|
6
6
|
import { replaceLocalePlaceholders } from '../utils.js';
|
|
7
|
-
export function mergeJson(originalContent,
|
|
8
|
-
const jsonSchema = validateJsonSchema(options,
|
|
7
|
+
export function mergeJson(originalContent, inputPath, options, targets, defaultLocale) {
|
|
8
|
+
const jsonSchema = validateJsonSchema(options, inputPath);
|
|
9
9
|
if (!jsonSchema) {
|
|
10
10
|
return targets.map((target) => target.translatedContent);
|
|
11
11
|
}
|
|
@@ -14,7 +14,7 @@ export function mergeJson(originalContent, filePath, options, targets, defaultLo
|
|
|
14
14
|
originalJson = JSON.parse(originalContent);
|
|
15
15
|
}
|
|
16
16
|
catch {
|
|
17
|
-
logError(`Invalid JSON file: ${
|
|
17
|
+
logError(`Invalid JSON file: ${inputPath}`);
|
|
18
18
|
exit(1);
|
|
19
19
|
}
|
|
20
20
|
// Handle include
|