gt 2.8.1 → 2.8.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,15 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1098](https://github.com/generaltranslation/gt/pull/1098) [`612ace4`](https://github.com/generaltranslation/gt/commit/612ace4bb30aaa3406b949931c8ffdb3f43ebd9f) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: upload supporting composite json
8
+
9
+ - Updated dependencies [[`1793010`](https://github.com/generaltranslation/gt/commit/1793010ea33ceceba307832195433ff3b7f1143e)]:
10
+ - generaltranslation@8.1.15
11
+ - @generaltranslation/python-extractor@0.1.1
12
+
3
13
  ## 2.8.1
4
14
 
5
15
  ### Patch Changes
@@ -5,6 +5,8 @@ import { getRelative, readFile } from '../../fs/findFilepath.js';
5
5
  import { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';
6
6
  import sanitizeFileContent from '../../utils/sanitizeFileContent.js';
7
7
  import { parseJson } from '../../formats/json/parseJson.js';
8
+ import { extractJson } from '../../formats/json/extractJson.js';
9
+ import { validateJsonSchema } from '../../formats/json/utils.js';
8
10
  import { runUploadFilesWorkflow } from '../../workflows/upload.js';
9
11
  import { existsSync, readFileSync } from 'node:fs';
10
12
  import { createFileMapping } from '../../formats/files/fileMapping.js';
@@ -25,6 +27,7 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
25
27
  // Collect all files to translate
26
28
  const allFiles = [];
27
29
  const additionalOptions = settings.options || {};
30
+ const compositeJsonFiles = new Map();
28
31
  // Process JSON files
29
32
  if (filePaths.json) {
30
33
  if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) {
@@ -34,6 +37,10 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
34
37
  const content = readFile(filePath);
35
38
  const parsedJson = parseJson(content, filePath, additionalOptions, settings.defaultLocale);
36
39
  const relativePath = getRelative(filePath);
40
+ const jsonSchema = validateJsonSchema(additionalOptions, filePath);
41
+ if (jsonSchema?.composite) {
42
+ compositeJsonFiles.set(relativePath, { filePath, content });
43
+ }
37
44
  return {
38
45
  content: parsedJson,
39
46
  fileName: relativePath,
@@ -112,19 +119,38 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
112
119
  versionId: file.versionId,
113
120
  };
114
121
  const translations = [];
122
+ const compositeInfo = compositeJsonFiles.get(file.fileName);
115
123
  for (const locale of locales) {
116
- const translatedFileName = fileMapping[locale][file.fileName];
117
- if (translatedFileName && existsSync(translatedFileName)) {
118
- const translatedContent = readFileSync(translatedFileName, 'utf8');
119
- translations.push({
120
- content: translatedContent,
121
- fileName: file.fileName,
122
- fileFormat: file.fileFormat,
123
- dataFormat: file.dataFormat,
124
- locale,
125
- fileId: file.fileId,
126
- versionId: file.versionId,
127
- });
124
+ if (compositeInfo) {
125
+ // Composite JSON: extract translations from the same source file
126
+ const extracted = extractJson(compositeInfo.content, compositeInfo.filePath, additionalOptions, locale, settings.defaultLocale);
127
+ if (extracted) {
128
+ translations.push({
129
+ content: extracted,
130
+ fileName: file.fileName,
131
+ fileFormat: file.fileFormat,
132
+ dataFormat: file.dataFormat,
133
+ locale,
134
+ fileId: file.fileId,
135
+ versionId: file.versionId,
136
+ });
137
+ }
138
+ }
139
+ else {
140
+ // Non-composite: look for separate translation files
141
+ const translatedFileName = fileMapping[locale]?.[file.fileName];
142
+ if (translatedFileName && existsSync(translatedFileName)) {
143
+ const translatedContent = readFileSync(translatedFileName, 'utf8');
144
+ translations.push({
145
+ content: translatedContent,
146
+ fileName: file.fileName,
147
+ fileFormat: file.fileFormat,
148
+ dataFormat: file.dataFormat,
149
+ locale,
150
+ fileId: file.fileId,
151
+ versionId: file.versionId,
152
+ });
153
+ }
128
154
  }
129
155
  }
130
156
  return {
@@ -44,4 +44,11 @@ export declare function generateSourceObjectPointers(jsonSchema: {
44
44
  sourceObjectValue: any;
45
45
  sourceObjectOptions: SourceObjectOptions;
46
46
  }>;
47
+ /**
48
+ * Validate the json schema for composite or include schemas
49
+ * @param options - Additional options containing jsonSchema config
50
+ * @param filePath - The path to the file (used for matching jsonSchema)
51
+ * @returns The json schema, or null if no schema is found
52
+ * @returns exitSync(1) if the json schema is invalid
53
+ */
47
54
  export declare function validateJsonSchema(options: AdditionalOptions, filePath: string): JsonSchema | null;
@@ -125,6 +125,13 @@ export function generateSourceObjectPointers(jsonSchema, originalJson) {
125
125
  }, {});
126
126
  return sourceObjectPointers;
127
127
  }
128
+ /**
129
+ * Validate the json schema for composite or include schemas
130
+ * @param options - Additional options containing jsonSchema config
131
+ * @param filePath - The path to the file (used for matching jsonSchema)
132
+ * @returns The json schema, or null if no schema is found
133
+ * @returns exitSync(1) if the json schema is invalid
134
+ */
128
135
  export function validateJsonSchema(options, filePath) {
129
136
  if (!options.jsonSchema) {
130
137
  return null;
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.8.1";
1
+ export declare const PACKAGE_VERSION = "2.8.2";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.8.1';
2
+ export const PACKAGE_VERSION = '2.8.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -110,8 +110,8 @@
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.0",
114
- "generaltranslation": "8.1.14",
113
+ "@generaltranslation/python-extractor": "0.1.1",
114
+ "generaltranslation": "8.1.15",
115
115
  "gt-remark": "1.0.5"
116
116
  },
117
117
  "devDependencies": {