gtx-cli 1.1.6 → 1.1.7-alpha.1
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/dist/api/sendFiles.d.ts +2 -1
- package/dist/api/sendFiles.js +1 -0
- package/dist/cli/base.js +6 -69
- package/dist/cli/react.js +4 -11
- package/dist/formats/files/translate.d.ts +9 -5
- package/dist/formats/files/translate.js +88 -43
- package/dist/formats/gt/save.js +2 -2
- package/dist/formats/json/save.d.ts +1 -0
- package/dist/formats/json/save.js +1 -0
- package/dist/formats/json/translate.d.ts +1 -0
- package/dist/formats/json/translate.js +1 -0
- package/dist/fs/config/parseFilesConfig.js +18 -22
- package/dist/types/index.d.ts +4 -0
- package/package.json +1 -1
package/dist/api/sendFiles.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Settings } from '../types';
|
|
2
|
-
import { FileFormats } from '../types/data';
|
|
2
|
+
import { FileFormats, DataFormat } from '../types/data';
|
|
3
3
|
export interface FileToTranslate {
|
|
4
4
|
content: string;
|
|
5
5
|
fileName: string;
|
|
6
6
|
fileFormat: FileFormats;
|
|
7
|
+
dataFormat: DataFormat;
|
|
7
8
|
}
|
|
8
9
|
type ApiOptions = Settings & {
|
|
9
10
|
publish: boolean;
|
package/dist/api/sendFiles.js
CHANGED
|
@@ -35,6 +35,7 @@ function sendFiles(files, options) {
|
|
|
35
35
|
files.forEach((file, index) => {
|
|
36
36
|
formData.append(`file${index}`, new Blob([file.content]), file.fileName);
|
|
37
37
|
formData.append(`fileFormat${index}`, file.fileFormat);
|
|
38
|
+
formData.append(`fileDataFormat${index}`, file.dataFormat); // Only used when translating JSON files
|
|
38
39
|
formData.append(`fileName${index}`, file.fileName);
|
|
39
40
|
});
|
|
40
41
|
// Add number of files
|
package/dist/cli/base.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -52,17 +19,15 @@ const console_2 = require("../console/console");
|
|
|
52
19
|
const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
|
|
53
20
|
const prompts_1 = require("@inquirer/prompts");
|
|
54
21
|
const generaltranslation_1 = require("generaltranslation");
|
|
55
|
-
const findFilepath_1 =
|
|
22
|
+
const findFilepath_1 = __importDefault(require("../fs/findFilepath"));
|
|
56
23
|
const errors_1 = require("../console/errors");
|
|
57
24
|
const path_1 = __importDefault(require("path"));
|
|
58
25
|
const fs_1 = __importDefault(require("fs"));
|
|
59
|
-
const translate_1 = require("../formats/json/translate");
|
|
60
26
|
const utils_1 = require("../fs/utils");
|
|
61
27
|
const generateSettings_1 = require("../config/generateSettings");
|
|
62
28
|
const chalk_1 = __importDefault(require("chalk"));
|
|
63
29
|
const internal_1 = require("generaltranslation/internal");
|
|
64
|
-
const
|
|
65
|
-
const SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];
|
|
30
|
+
const translate_1 = require("../formats/files/translate");
|
|
66
31
|
class BaseCLI {
|
|
67
32
|
// Constructor is shared amongst all CLI class types
|
|
68
33
|
constructor(library, additionalModules) {
|
|
@@ -134,36 +99,8 @@ class BaseCLI {
|
|
|
134
99
|
dataFormat = 'JSX';
|
|
135
100
|
}
|
|
136
101
|
const { resolvedPaths: sourceFiles, placeholderPaths, transformPaths, } = settings.files;
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
// Only translate JSON files if not using gt-react or gt-next
|
|
140
|
-
// ReactCLI will handle the JSON files differently
|
|
141
|
-
if (this.library !== 'gt-react' && this.library !== 'gt-next') {
|
|
142
|
-
const rawSource = (0, findFilepath_1.readFile)(sourceFiles.json[0]);
|
|
143
|
-
if (!rawSource) {
|
|
144
|
-
console.error(errors_1.noSourceFileError);
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
if (!dataFormat) {
|
|
148
|
-
console.error(errors_1.noDataFormatError);
|
|
149
|
-
process.exit(1);
|
|
150
|
-
}
|
|
151
|
-
else if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) {
|
|
152
|
-
console.error(errors_1.noSupportedDataFormatError);
|
|
153
|
-
process.exit(1);
|
|
154
|
-
}
|
|
155
|
-
const source = JSON.parse(rawSource);
|
|
156
|
-
yield (0, translate_1.translateJson)(source, settings, dataFormat, placeholderPaths);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (sourceFiles.mdx || sourceFiles.md) {
|
|
160
|
-
if (sourceFiles.mdx) {
|
|
161
|
-
yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, transformPaths, 'MDX', settings);
|
|
162
|
-
}
|
|
163
|
-
if (sourceFiles.md) {
|
|
164
|
-
yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, transformPaths, 'MD', settings);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
102
|
+
// Process all file types at once with a single call
|
|
103
|
+
yield (0, translate_1.translateFiles)(sourceFiles, placeholderPaths, transformPaths, dataFormat, settings);
|
|
167
104
|
});
|
|
168
105
|
}
|
|
169
106
|
setupInitCommand() {
|
|
@@ -261,8 +198,8 @@ class BaseCLI {
|
|
|
261
198
|
defaultLocale,
|
|
262
199
|
locales: locales.split(' '),
|
|
263
200
|
files: {
|
|
264
|
-
|
|
265
|
-
|
|
201
|
+
gt: {
|
|
202
|
+
output: translationsDirWithFormat,
|
|
266
203
|
},
|
|
267
204
|
},
|
|
268
205
|
});
|
package/dist/cli/react.js
CHANGED
|
@@ -401,13 +401,6 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
401
401
|
if (options.dictionary) {
|
|
402
402
|
sourceFile = options.dictionary;
|
|
403
403
|
}
|
|
404
|
-
else {
|
|
405
|
-
// If it is not provided, use the first json file in the files object
|
|
406
|
-
const resolvedFiles = options.files.resolvedPaths;
|
|
407
|
-
if (resolvedFiles.json) {
|
|
408
|
-
sourceFile = resolvedFiles.json[0];
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
404
|
// Separate defaultLocale from locales
|
|
412
405
|
options.locales = options.locales.filter((locale) => locale !== options.defaultLocale);
|
|
413
406
|
// validate timeout
|
|
@@ -431,8 +424,8 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
431
424
|
process.exit(1);
|
|
432
425
|
}
|
|
433
426
|
}
|
|
434
|
-
// If files.
|
|
435
|
-
if (!((_b = (_a = settings.files) === null || _a === void 0 ? void 0 : _a.resolvedPaths) === null || _b === void 0 ? void 0 : _b.
|
|
427
|
+
// If files.gt.output is not provided in the config, publish the translations
|
|
428
|
+
if (!((_b = (_a = settings.files) === null || _a === void 0 ? void 0 : _a.resolvedPaths) === null || _b === void 0 ? void 0 : _b.gt)) {
|
|
436
429
|
options.publish = true;
|
|
437
430
|
}
|
|
438
431
|
if (options.dryRun) {
|
|
@@ -448,8 +441,8 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
448
441
|
throw new Error('No General Translation Project ID found. Use the --project-id flag to provide one.');
|
|
449
442
|
const updateResponse = yield (0, sendUpdates_1.sendUpdates)(updates, Object.assign(Object.assign({}, settings), { publish: options.publish, wait: options.wait, timeout: options.timeout, dataFormat: 'JSX' }));
|
|
450
443
|
const versionId = updateResponse === null || updateResponse === void 0 ? void 0 : updateResponse.versionId;
|
|
451
|
-
// Save translations to local directory if files.
|
|
452
|
-
if (versionId && options.files.placeholderPaths.
|
|
444
|
+
// Save translations to local directory if files.gt.output is provided
|
|
445
|
+
if (versionId && options.files.placeholderPaths.gt) {
|
|
453
446
|
console.log();
|
|
454
447
|
const translations = yield (0, fetchTranslations_1.fetchTranslations)(settings.baseUrl, settings.apiKey, versionId);
|
|
455
448
|
(0, save_1.saveTranslations)(translations, options.files.placeholderPaths, 'JSX');
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ResolvedFiles, Settings, TransformFiles } from '../../types';
|
|
2
|
-
import {
|
|
2
|
+
import { DataFormat } from '../../types/data';
|
|
3
3
|
/**
|
|
4
|
-
* Sends
|
|
5
|
-
* @param
|
|
4
|
+
* Sends multiple files to the API for translation
|
|
5
|
+
* @param filePaths - Resolved file paths for different file types
|
|
6
|
+
* @param placeholderPaths - Placeholder paths for translated files
|
|
7
|
+
* @param transformPaths - Transform paths for file naming
|
|
8
|
+
* @param fileFormat - Format of the files
|
|
9
|
+
* @param dataFormat - Format of the data within the files
|
|
6
10
|
* @param options - Translation options including API settings
|
|
7
|
-
* @returns
|
|
11
|
+
* @returns Promise that resolves when translation is complete
|
|
8
12
|
*/
|
|
9
|
-
export declare function translateFiles(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, transformPaths: TransformFiles,
|
|
13
|
+
export declare function translateFiles(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, transformPaths: TransformFiles, dataFormat: DataFormat | undefined, options: Settings): Promise<void>;
|
|
@@ -15,68 +15,113 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.translateFiles = translateFiles;
|
|
16
16
|
const checkFileTranslations_1 = require("../../api/checkFileTranslations");
|
|
17
17
|
const sendFiles_1 = require("../../api/sendFiles");
|
|
18
|
+
const errors_1 = require("../../console/errors");
|
|
18
19
|
const parseFilesConfig_1 = require("../../fs/config/parseFilesConfig");
|
|
19
20
|
const findFilepath_1 = require("../../fs/findFilepath");
|
|
21
|
+
const flattenDictionary_1 = require("../../react/utils/flattenDictionary");
|
|
20
22
|
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];
|
|
21
24
|
/**
|
|
22
|
-
* Sends
|
|
23
|
-
* @param
|
|
25
|
+
* Sends multiple files to the API for translation
|
|
26
|
+
* @param filePaths - Resolved file paths for different file types
|
|
27
|
+
* @param placeholderPaths - Placeholder paths for translated files
|
|
28
|
+
* @param transformPaths - Transform paths for file naming
|
|
29
|
+
* @param fileFormat - Format of the files
|
|
30
|
+
* @param dataFormat - Format of the data within the files
|
|
24
31
|
* @param options - Translation options including API settings
|
|
25
|
-
* @returns
|
|
32
|
+
* @returns Promise that resolves when translation is complete
|
|
26
33
|
*/
|
|
27
|
-
function translateFiles(
|
|
28
|
-
return __awaiter(this,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
function translateFiles(filePaths_1, placeholderPaths_1, transformPaths_1) {
|
|
35
|
+
return __awaiter(this, arguments, void 0, function* (filePaths, placeholderPaths, transformPaths, dataFormat = 'JSX', options) {
|
|
36
|
+
// Collect all files to translate
|
|
37
|
+
const allFiles = [];
|
|
38
|
+
// Process JSON files
|
|
39
|
+
if (filePaths.json) {
|
|
40
|
+
if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) {
|
|
41
|
+
console.error(errors_1.noSupportedDataFormatError);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
const jsonFiles = filePaths.json.map((filePath) => {
|
|
45
|
+
const content = (0, findFilepath_1.readFile)(filePath);
|
|
46
|
+
const json = JSON.parse(content);
|
|
47
|
+
// Just to validate the JSON is valid
|
|
48
|
+
(0, flattenDictionary_1.flattenJsonDictionary)(json);
|
|
49
|
+
const relativePath = (0, findFilepath_1.getRelative)(filePath);
|
|
50
|
+
return {
|
|
51
|
+
content,
|
|
52
|
+
fileName: relativePath,
|
|
53
|
+
fileFormat: 'JSON',
|
|
54
|
+
dataFormat,
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
allFiles.push(...jsonFiles);
|
|
35
58
|
}
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
// Process MDX files
|
|
60
|
+
if (filePaths.mdx) {
|
|
61
|
+
const mdxFiles = filePaths.mdx.map((filePath) => {
|
|
62
|
+
const content = (0, findFilepath_1.readFile)(filePath);
|
|
63
|
+
const relativePath = (0, findFilepath_1.getRelative)(filePath);
|
|
64
|
+
return {
|
|
65
|
+
content,
|
|
66
|
+
fileName: relativePath,
|
|
67
|
+
fileFormat: 'MDX',
|
|
68
|
+
dataFormat,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
allFiles.push(...mdxFiles);
|
|
38
72
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.error('No files to translate');
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const files = sourcePaths.map((filePath) => {
|
|
73
|
+
// Process MD files
|
|
74
|
+
if (filePaths.md) {
|
|
75
|
+
const mdFiles = filePaths.md.map((filePath) => {
|
|
46
76
|
const content = (0, findFilepath_1.readFile)(filePath);
|
|
47
77
|
const relativePath = (0, findFilepath_1.getRelative)(filePath);
|
|
48
78
|
return {
|
|
49
79
|
content,
|
|
50
80
|
fileName: relativePath,
|
|
51
|
-
fileFormat,
|
|
81
|
+
fileFormat: 'MD',
|
|
82
|
+
dataFormat,
|
|
52
83
|
};
|
|
53
84
|
});
|
|
54
|
-
|
|
85
|
+
allFiles.push(...mdFiles);
|
|
86
|
+
}
|
|
87
|
+
if (allFiles.length === 0) {
|
|
88
|
+
console.error('No files to translate');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
// Send all files in a single API call
|
|
93
|
+
const response = yield (0, sendFiles_1.sendFiles)(allFiles, Object.assign(Object.assign({}, options), { publish: false, wait: true }));
|
|
55
94
|
const { data, locales } = response;
|
|
95
|
+
// Create file mapping for all file types
|
|
56
96
|
const fileMapping = {};
|
|
57
97
|
for (const locale of locales) {
|
|
58
98
|
const translatedPaths = (0, parseFilesConfig_1.resolveLocaleFiles)(placeholderPaths, locale);
|
|
59
|
-
let translatedFiles = translatedPaths[typeIndex];
|
|
60
|
-
if (!translatedFiles) {
|
|
61
|
-
continue; // shouldn't happen; typing
|
|
62
|
-
}
|
|
63
|
-
const transformPath = transformPaths[typeIndex];
|
|
64
|
-
if (transformPath) {
|
|
65
|
-
translatedFiles = translatedFiles.map((filePath) => {
|
|
66
|
-
const directory = path_1.default.dirname(filePath);
|
|
67
|
-
const fileName = path_1.default.basename(filePath);
|
|
68
|
-
const baseName = fileName.split('.')[0];
|
|
69
|
-
const transformedFileName = transformPath
|
|
70
|
-
.replace('*', baseName)
|
|
71
|
-
.replace('[locale]', locale);
|
|
72
|
-
return path_1.default.join(directory, transformedFileName);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
99
|
const localeMapping = {};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
100
|
+
// Process each file type
|
|
101
|
+
for (const typeIndex of ['json', 'mdx', 'md']) {
|
|
102
|
+
if (!filePaths[typeIndex] || !translatedPaths[typeIndex])
|
|
103
|
+
continue;
|
|
104
|
+
const sourcePaths = filePaths[typeIndex];
|
|
105
|
+
let translatedFiles = translatedPaths[typeIndex];
|
|
106
|
+
if (!translatedFiles)
|
|
107
|
+
continue;
|
|
108
|
+
const transformPath = transformPaths[typeIndex];
|
|
109
|
+
if (transformPath) {
|
|
110
|
+
translatedFiles = translatedFiles.map((filePath) => {
|
|
111
|
+
const directory = path_1.default.dirname(filePath);
|
|
112
|
+
const fileName = path_1.default.basename(filePath);
|
|
113
|
+
const baseName = fileName.split('.')[0];
|
|
114
|
+
const transformedFileName = transformPath
|
|
115
|
+
.replace('*', baseName)
|
|
116
|
+
.replace('[locale]', locale);
|
|
117
|
+
return path_1.default.join(directory, transformedFileName);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (let i = 0; i < sourcePaths.length; i++) {
|
|
121
|
+
const sourceFile = (0, findFilepath_1.getRelative)(sourcePaths[i]);
|
|
122
|
+
const translatedFile = (0, findFilepath_1.getRelative)(translatedFiles[i]);
|
|
123
|
+
localeMapping[sourceFile] = translatedFile;
|
|
124
|
+
}
|
|
80
125
|
}
|
|
81
126
|
fileMapping[locale] = localeMapping;
|
|
82
127
|
}
|
|
@@ -85,7 +130,7 @@ function translateFiles(filePaths, placeholderPaths, transformPaths, fileFormat,
|
|
|
85
130
|
});
|
|
86
131
|
}
|
|
87
132
|
catch (error) {
|
|
88
|
-
console.error('Error translating
|
|
133
|
+
console.error('Error translating files:', error);
|
|
89
134
|
}
|
|
90
135
|
});
|
|
91
136
|
}
|
package/dist/formats/gt/save.js
CHANGED
|
@@ -18,11 +18,11 @@ function saveTranslations(translations, placeholderPaths, dataFormat) {
|
|
|
18
18
|
for (const translation of translations) {
|
|
19
19
|
const locale = translation.locale;
|
|
20
20
|
const translationFiles = (0, parseFilesConfig_1.resolveLocaleFiles)(placeholderPaths, locale);
|
|
21
|
-
if (!translationFiles.
|
|
21
|
+
if (!translationFiles.gt) {
|
|
22
22
|
console.error(errors_1.noFilesError);
|
|
23
23
|
process.exit(1);
|
|
24
24
|
}
|
|
25
|
-
const filepath = translationFiles.
|
|
25
|
+
const filepath = translationFiles.gt;
|
|
26
26
|
const translationData = translation.translation;
|
|
27
27
|
// Ensure directory exists
|
|
28
28
|
fs_1.default.mkdirSync(path_1.default.dirname(filepath), { recursive: true });
|
|
@@ -6,5 +6,6 @@ import { ResolvedFiles } from '../../types';
|
|
|
6
6
|
* @param translations - The translations to save
|
|
7
7
|
* @param filePath - The file path to save the translations to
|
|
8
8
|
* @param dataFormat - The data format to save the translations as
|
|
9
|
+
* @deprecated Use saveFiles instead
|
|
9
10
|
*/
|
|
10
11
|
export declare function saveTranslations(translations: RetrievedTranslations, placeholderPaths: ResolvedFiles, dataFormat: DataFormat): void;
|
|
@@ -13,6 +13,7 @@ const errors_1 = require("../../console/errors");
|
|
|
13
13
|
* @param translations - The translations to save
|
|
14
14
|
* @param filePath - The file path to save the translations to
|
|
15
15
|
* @param dataFormat - The data format to save the translations as
|
|
16
|
+
* @deprecated Use saveFiles instead
|
|
16
17
|
*/
|
|
17
18
|
function saveTranslations(translations, placeholderPaths, dataFormat) {
|
|
18
19
|
for (const translation of translations) {
|
|
@@ -12,5 +12,6 @@ import { ResolvedFiles } from '../../types';
|
|
|
12
12
|
* @param config - The config file path
|
|
13
13
|
* @param translationsDir - The directory to save the translations to
|
|
14
14
|
* @param fileType - The file type to save the translations as (file extension)
|
|
15
|
+
* @deprecated Use translateFiles instead
|
|
15
16
|
*/
|
|
16
17
|
export declare function translateJson(sourceJson: any, settings: Settings, dataFormat: DataFormat, placeholderPaths: ResolvedFiles): Promise<void>;
|
|
@@ -25,6 +25,7 @@ const save_1 = require("./save");
|
|
|
25
25
|
* @param config - The config file path
|
|
26
26
|
* @param translationsDir - The directory to save the translations to
|
|
27
27
|
* @param fileType - The file type to save the translations as (file extension)
|
|
28
|
+
* @deprecated Use translateFiles instead
|
|
28
29
|
*/
|
|
29
30
|
function translateJson(sourceJson, settings, dataFormat, placeholderPaths) {
|
|
30
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -16,7 +16,7 @@ const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
|
16
16
|
* @returns The resolved files
|
|
17
17
|
*/
|
|
18
18
|
function resolveLocaleFiles(files, locale) {
|
|
19
|
-
var _a, _b, _c;
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
20
|
const result = {};
|
|
21
21
|
// Replace [locale] with locale in all paths
|
|
22
22
|
result.json = (_a = files.json) === null || _a === void 0 ? void 0 : _a.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
@@ -24,6 +24,8 @@ function resolveLocaleFiles(files, locale) {
|
|
|
24
24
|
result.md = (_b = files.md) === null || _b === void 0 ? void 0 : _b.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
25
25
|
// Replace [locale] with locale in all paths
|
|
26
26
|
result.mdx = (_c = files.mdx) === null || _c === void 0 ? void 0 : _c.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
27
|
+
// Replace [locale] with locale in all paths
|
|
28
|
+
result.gt = (_d = files.gt) === null || _d === void 0 ? void 0 : _d.replace(/\[locale\]/g, locale);
|
|
27
29
|
return result;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
@@ -35,44 +37,38 @@ function resolveLocaleFiles(files, locale) {
|
|
|
35
37
|
* @returns The resolved files
|
|
36
38
|
*/
|
|
37
39
|
function resolveFiles(files, locale) {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
39
41
|
// Initialize result object with empty arrays for each file type
|
|
40
42
|
const result = {};
|
|
41
43
|
const placeholderResult = {};
|
|
42
44
|
const transformPaths = {};
|
|
45
|
+
// Process GT files
|
|
46
|
+
if ((_a = files.gt) === null || _a === void 0 ? void 0 : _a.output) {
|
|
47
|
+
placeholderResult.gt = files.gt.output;
|
|
48
|
+
}
|
|
43
49
|
// Process JSON files
|
|
44
|
-
if ((
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
if (files.json.include.length === 1) {
|
|
50
|
-
const jsonPaths = expandGlobPatterns([files.json.include[0]], ((_b = files.json) === null || _b === void 0 ? void 0 : _b.exclude) || [], locale);
|
|
51
|
-
if (jsonPaths.resolvedPaths.length > 1) {
|
|
52
|
-
console.error('JSON glob pattern matched multiple files. Only one JSON file is supported.');
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
result.json = jsonPaths.resolvedPaths;
|
|
56
|
-
placeholderResult.json = jsonPaths.placeholderPaths;
|
|
57
|
-
}
|
|
50
|
+
if ((_b = files.json) === null || _b === void 0 ? void 0 : _b.include) {
|
|
51
|
+
const jsonPaths = expandGlobPatterns(files.json.include, ((_c = files.json) === null || _c === void 0 ? void 0 : _c.exclude) || [], locale);
|
|
52
|
+
result.json = jsonPaths.resolvedPaths;
|
|
53
|
+
placeholderResult.json = jsonPaths.placeholderPaths;
|
|
58
54
|
}
|
|
59
55
|
// Process MD files
|
|
60
|
-
if ((
|
|
61
|
-
const mdPaths = expandGlobPatterns(files.md.include, ((
|
|
56
|
+
if ((_d = files.md) === null || _d === void 0 ? void 0 : _d.include) {
|
|
57
|
+
const mdPaths = expandGlobPatterns(files.md.include, ((_e = files.md) === null || _e === void 0 ? void 0 : _e.exclude) || [], locale);
|
|
62
58
|
result.md = mdPaths.resolvedPaths;
|
|
63
59
|
placeholderResult.md = mdPaths.placeholderPaths;
|
|
64
60
|
}
|
|
65
61
|
// Process MDX files
|
|
66
|
-
if ((
|
|
67
|
-
const mdxPaths = expandGlobPatterns(files.mdx.include, ((
|
|
62
|
+
if ((_f = files.mdx) === null || _f === void 0 ? void 0 : _f.include) {
|
|
63
|
+
const mdxPaths = expandGlobPatterns(files.mdx.include, ((_g = files.mdx) === null || _g === void 0 ? void 0 : _g.exclude) || [], locale);
|
|
68
64
|
result.mdx = mdxPaths.resolvedPaths;
|
|
69
65
|
placeholderResult.mdx = mdxPaths.placeholderPaths;
|
|
70
66
|
}
|
|
71
67
|
// ==== TRANSFORMS ==== //
|
|
72
|
-
if (((
|
|
68
|
+
if (((_h = files.mdx) === null || _h === void 0 ? void 0 : _h.transform) && !Array.isArray(files.mdx.transform)) {
|
|
73
69
|
transformPaths.mdx = files.mdx.transform;
|
|
74
70
|
}
|
|
75
|
-
if (((
|
|
71
|
+
if (((_j = files.md) === null || _j === void 0 ? void 0 : _j.transform) && !Array.isArray(files.md.transform)) {
|
|
76
72
|
transformPaths.md = files.md.transform;
|
|
77
73
|
}
|
|
78
74
|
return {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -60,6 +60,9 @@ export interface ContentScanner {
|
|
|
60
60
|
}>;
|
|
61
61
|
}
|
|
62
62
|
export type FilesOptions = {
|
|
63
|
+
gt?: {
|
|
64
|
+
output: string;
|
|
65
|
+
};
|
|
63
66
|
json?: {
|
|
64
67
|
include: string[];
|
|
65
68
|
exclude?: string[];
|
|
@@ -83,6 +86,7 @@ export type ResolvedFiles = {
|
|
|
83
86
|
json?: string[];
|
|
84
87
|
md?: string[];
|
|
85
88
|
mdx?: string[];
|
|
89
|
+
gt?: string;
|
|
86
90
|
};
|
|
87
91
|
export type TransformFiles = {
|
|
88
92
|
json?: string;
|