gt 2.10.1 → 2.10.2
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
|
+
## 2.10.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1108](https://github.com/generaltranslation/gt/pull/1108) [`2dff603`](https://github.com/generaltranslation/gt/commit/2dff6036382040438a3fa8bbd4c2475da7617f93) Thanks [@brian-lou](https://github.com/brian-lou)! - Fix string behavior
|
|
8
|
+
|
|
3
9
|
## 2.10.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -95,6 +95,11 @@ export function extractJson(localContent, inputPath, options, targetLocale, defa
|
|
|
95
95
|
logger.warn(`No matching item found for locale ${targetLocale} at path: ${sourceObjectPointer}`);
|
|
96
96
|
continue;
|
|
97
97
|
}
|
|
98
|
+
// If the source item is a string, use it directly
|
|
99
|
+
if (typeof matchingTargetItem.sourceItem === 'string') {
|
|
100
|
+
compositeResult[sourceObjectPointer] = matchingTargetItem.sourceItem;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
98
103
|
// Extract values at the include paths
|
|
99
104
|
const extractedValues = flattenJsonWithStringFilter(matchingTargetItem.sourceItem, sourceObjectOptions.include);
|
|
100
105
|
// Store the extracted values
|
|
@@ -59,6 +59,11 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
|
|
|
59
59
|
// Handle composite
|
|
60
60
|
// Create a deep copy of the original JSON to avoid mutations
|
|
61
61
|
const mergedJson = structuredClone(originalJson);
|
|
62
|
+
// Pre-parse all target contents ONCE (avoid re-parsing per pointer)
|
|
63
|
+
const parsedTargets = targets.map((target) => ({
|
|
64
|
+
...target,
|
|
65
|
+
parsedContent: JSON.parse(target.translatedContent),
|
|
66
|
+
}));
|
|
62
67
|
// Create mapping of sourceObjectPointer to SourceObjectOptions
|
|
63
68
|
const sourceObjectPointers = generateSourceObjectPointers(jsonSchema.composite, originalJson);
|
|
64
69
|
// Find the source object
|
|
@@ -91,9 +96,8 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
|
|
|
91
96
|
// 10. Remove all items for the target locale (they can be identified by the key)
|
|
92
97
|
const indiciesToRemove = new Set();
|
|
93
98
|
const itemsToAdd = [];
|
|
94
|
-
for (const target of
|
|
95
|
-
|
|
96
|
-
let targetItems = targetJson[sourceObjectPointer];
|
|
99
|
+
for (const target of parsedTargets) {
|
|
100
|
+
let targetItems = target.parsedContent[sourceObjectPointer];
|
|
97
101
|
// 1. Get the target items
|
|
98
102
|
if (!targetItems) {
|
|
99
103
|
// If no translation can be found, a transformation may need to happen still
|
|
@@ -196,21 +200,28 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
|
|
|
196
200
|
// 5. Override the source item with the translated values
|
|
197
201
|
// 6. Apply additional mutations to the sourceItem
|
|
198
202
|
// 7. Merge the source item with the original JSON (if the source item is not a new item)
|
|
199
|
-
for (const target of
|
|
200
|
-
const targetJson = JSON.parse(target.translatedContent);
|
|
203
|
+
for (const target of parsedTargets) {
|
|
201
204
|
// 1. Get the target items
|
|
202
|
-
let targetItems =
|
|
203
|
-
if (
|
|
205
|
+
let targetItems = target.parsedContent[sourceObjectPointer];
|
|
206
|
+
if (targetItems == null) {
|
|
204
207
|
targetItems = {};
|
|
205
208
|
}
|
|
206
209
|
// 2. Find the source item for the target locale
|
|
207
210
|
const matchingTargetItem = findMatchingItemObject(useCanonicalLocaleKeys
|
|
208
211
|
? gt.resolveCanonicalLocale(target.targetLocale)
|
|
209
212
|
: target.targetLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue);
|
|
213
|
+
const mutateSourceItemKey = matchingTargetItem.keyParentProperty;
|
|
214
|
+
// If the source item is a string, use the translated string directly
|
|
215
|
+
if (typeof defaultLocaleSourceItem === 'string') {
|
|
216
|
+
if (typeof targetItems === 'string') {
|
|
217
|
+
sourceObjectValue[mutateSourceItemKey] = targetItems;
|
|
218
|
+
}
|
|
219
|
+
// If no translation found, leave the locale slot unchanged
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
210
222
|
// If the target locale has a matching source item, use it to mutate the source item
|
|
211
223
|
// Otherwise, fallback to the default locale source item
|
|
212
224
|
const mutateSourceItem = structuredClone(defaultLocaleSourceItem);
|
|
213
|
-
const mutateSourceItemKey = matchingTargetItem.keyParentProperty;
|
|
214
225
|
// 3. Merge the target items with the source item (if there are transformations to perform)
|
|
215
226
|
const mergedItems = {
|
|
216
227
|
...(sourceObjectOptions.transform ? defaultLocaleSourceItem : {}),
|
|
@@ -104,6 +104,11 @@ export function parseJson(content, filePath, options, defaultLocale, filterStrin
|
|
|
104
104
|
return exitSync(1);
|
|
105
105
|
}
|
|
106
106
|
const { sourceItem } = matchingItem;
|
|
107
|
+
// If the source item is a string, use it directly
|
|
108
|
+
if (typeof sourceItem === 'string') {
|
|
109
|
+
sourceObjectsToTranslate[sourceObjectPointer] = sourceItem;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
107
112
|
// Get the fields to translate from the includes
|
|
108
113
|
const flatten = filterStrings ? flattenJsonWithStringFilter : flattenJson;
|
|
109
114
|
const itemsToTranslate = flatten(sourceItem, sourceObjectOptions.include);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "2.10.
|
|
1
|
+
export declare const PACKAGE_VERSION = "2.10.2";
|
|
@@ -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.2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.2",
|
|
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",
|