gtx-cli 2.1.21 → 2.2.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 +11 -0
- package/dist/api/checkFileTranslations.js +1 -1
- package/dist/api/downloadFileBatch.js +4 -1
- package/dist/api/uploadFiles.d.ts +1 -1
- package/dist/api/uploadFiles.js +6 -21
- package/dist/config/generateSettings.js +1 -0
- package/dist/config/validateSettings.js +3 -2
- package/dist/formats/files/upload.js +1 -1
- package/dist/next/config/parseNextConfig.js +2 -2
- package/dist/setup/userInput.js +2 -2
- package/dist/types/index.d.ts +2 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#638](https://github.com/generaltranslation/gt/pull/638) [`16bf30d`](https://github.com/generaltranslation/gt/commit/16bf30d70a0599ec863305f4f7a5a0852dd07e5d) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: add locale aliasing
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`16bf30d`](https://github.com/generaltranslation/gt/commit/16bf30d70a0599ec863305f4f7a5a0852dd07e5d)]:
|
|
12
|
+
- generaltranslation@7.5.0
|
|
13
|
+
|
|
3
14
|
## 2.1.21
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -182,7 +182,7 @@ async function checkTranslationDeployment(fileQueryData, downloadStatus, spinner
|
|
|
182
182
|
// Prepare batch download data
|
|
183
183
|
const batchFiles = readyTranslations
|
|
184
184
|
.map((translation) => {
|
|
185
|
-
const locale = translation.locale;
|
|
185
|
+
const locale = gt.resolveAliasLocale(translation.locale);
|
|
186
186
|
const fileName = translation.fileName;
|
|
187
187
|
const translationId = translation.id;
|
|
188
188
|
const outputPath = resolveOutputPath(fileName, locale);
|
|
@@ -20,7 +20,10 @@ export async function downloadFileBatch(files, options, maxRetries = 3, retryDel
|
|
|
20
20
|
// Create a map of translationId to outputPath for easier lookup
|
|
21
21
|
const outputPathMap = new Map(files.map((file) => [file.translationId, file.outputPath]));
|
|
22
22
|
const inputPathMap = new Map(files.map((file) => [file.translationId, file.inputPath]));
|
|
23
|
-
const localeMap = new Map(files.map((file) => [
|
|
23
|
+
const localeMap = new Map(files.map((file) => [
|
|
24
|
+
file.translationId,
|
|
25
|
+
gt.resolveAliasLocale(file.locale),
|
|
26
|
+
]));
|
|
24
27
|
while (retries <= maxRetries) {
|
|
25
28
|
try {
|
|
26
29
|
// Download the files
|
package/dist/api/uploadFiles.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { createSpinner, exit, logMessage } from '../console/logging.js';
|
|
3
|
+
import { gt } from '../utils/gt.js';
|
|
3
4
|
/**
|
|
4
5
|
* Uploads multiple files to the API
|
|
5
6
|
* @param files - Array of file objects to upload
|
|
@@ -16,31 +17,15 @@ export async function uploadFiles(files, options) {
|
|
|
16
17
|
.join('\n'));
|
|
17
18
|
const spinner = createSpinner('dots');
|
|
18
19
|
spinner.start(`Uploading ${files.length} file${files.length !== 1 ? 's' : ''} to General Translation...`);
|
|
19
|
-
const uploadData = {
|
|
20
|
-
data: files.map((file) => ({
|
|
21
|
-
source: file.source,
|
|
22
|
-
translations: file.translations,
|
|
23
|
-
})),
|
|
24
|
-
sourceLocale: options.defaultLocale,
|
|
25
|
-
...(options.modelProvider && { modelProvider: options.modelProvider }),
|
|
26
|
-
};
|
|
27
20
|
try {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
'x-gt-api-key': options.apiKey,
|
|
34
|
-
'x-gt-project-id': options.projectId,
|
|
35
|
-
},
|
|
21
|
+
const result = gt.uploadFiles(files, {
|
|
22
|
+
...options,
|
|
23
|
+
sourceLocale: options.defaultLocale,
|
|
36
24
|
});
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
throw new Error(`Failed to upload files: ${response.statusText} (${response.status})`);
|
|
39
|
-
}
|
|
40
25
|
spinner.stop(chalk.green('Files uploaded successfully'));
|
|
41
|
-
return
|
|
26
|
+
return result;
|
|
42
27
|
}
|
|
43
|
-
catch
|
|
28
|
+
catch {
|
|
44
29
|
spinner.stop(chalk.red('An unexpected error occurred while uploading files'));
|
|
45
30
|
exit(1);
|
|
46
31
|
}
|
|
@@ -165,6 +165,7 @@ export async function generateSettings(options, cwd = process.cwd()) {
|
|
|
165
165
|
apiKey: mergedOptions.apiKey,
|
|
166
166
|
baseUrl: mergedOptions.baseUrl,
|
|
167
167
|
sourceLocale: mergedOptions.defaultLocale,
|
|
168
|
+
customMapping: mergedOptions.customMapping,
|
|
168
169
|
});
|
|
169
170
|
return mergedOptions;
|
|
170
171
|
}
|
|
@@ -5,11 +5,12 @@ import path from 'node:path';
|
|
|
5
5
|
export function validateSettings(settings) {
|
|
6
6
|
// Validate locales
|
|
7
7
|
for (const locale of settings.locales) {
|
|
8
|
-
if (!isValidLocale(locale)) {
|
|
8
|
+
if (!isValidLocale(locale, settings.customMapping)) {
|
|
9
9
|
logErrorAndExit(`Provided locales: "${settings?.locales?.join()}", ${locale} is not a valid locale!`);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
if (settings.defaultLocale &&
|
|
12
|
+
if (settings.defaultLocale &&
|
|
13
|
+
!isValidLocale(settings.defaultLocale, settings.customMapping)) {
|
|
13
14
|
logErrorAndExit(`defaultLocale: ${settings.defaultLocale} is not a valid locale!`);
|
|
14
15
|
}
|
|
15
16
|
// defaultLocale cannot be a superset of any other locale
|
|
@@ -130,7 +130,7 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
|
|
|
130
130
|
});
|
|
131
131
|
try {
|
|
132
132
|
// Send all files in a single API call
|
|
133
|
-
|
|
133
|
+
await uploadFiles(uploadData, options);
|
|
134
134
|
}
|
|
135
135
|
catch (error) {
|
|
136
136
|
logErrorAndExit(`Error uploading files: ${error}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import { isValidLocale } from 'generaltranslation';
|
|
3
2
|
import path from 'node:path';
|
|
3
|
+
import { gt } from '../../utils/gt.js';
|
|
4
4
|
/**
|
|
5
5
|
* Extracts projectId, defaultLocale, and locales from a next.config.js file.
|
|
6
6
|
* @param {string} filePath - The path to the next.config.js file.
|
|
@@ -36,7 +36,7 @@ export async function parseNextConfig(filePath) {
|
|
|
36
36
|
.filter((locale) => typeof locale === 'string')
|
|
37
37
|
: undefined;
|
|
38
38
|
// Ensure approvedLocales is an array of strings
|
|
39
|
-
const validLocales = locales && locales.every((locale) => isValidLocale(locale))
|
|
39
|
+
const validLocales = locales && locales.every((locale) => gt.isValidLocale(locale))
|
|
40
40
|
? locales
|
|
41
41
|
: undefined;
|
|
42
42
|
// Return the extracted values if they pass type checks or return null
|
package/dist/setup/userInput.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { libraryDefaultLocale } from 'generaltranslation/internal';
|
|
2
2
|
import { promptText } from '../console/logging.js';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
-
import {
|
|
4
|
+
import { gt } from '../utils/gt.js';
|
|
5
5
|
export async function getDesiredLocales() {
|
|
6
6
|
// Ask for the default locale
|
|
7
7
|
const defaultLocale = await promptText({
|
|
@@ -18,7 +18,7 @@ export async function getDesiredLocales() {
|
|
|
18
18
|
return 'Please enter at least one locale';
|
|
19
19
|
}
|
|
20
20
|
for (const locale of localeList) {
|
|
21
|
-
if (!isValidLocale(locale)) {
|
|
21
|
+
if (!gt.isValidLocale(locale)) {
|
|
22
22
|
return 'Please enter a valid locale (e.g., en, fr, es)';
|
|
23
23
|
}
|
|
24
24
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CustomMapping } from 'generaltranslation/types';
|
|
1
2
|
import { SUPPORTED_FILE_EXTENSIONS } from '../formats/files/supportedFiles.js';
|
|
2
3
|
export type { Updates } from 'generaltranslation/types';
|
|
3
4
|
export type Options = {
|
|
@@ -113,6 +114,7 @@ export type Settings = {
|
|
|
113
114
|
projectId?: string;
|
|
114
115
|
defaultLocale: string;
|
|
115
116
|
locales: string[];
|
|
117
|
+
customMapping?: CustomMapping;
|
|
116
118
|
files: {
|
|
117
119
|
resolvedPaths: ResolvedFiles;
|
|
118
120
|
placeholderPaths: ResolvedFiles;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"esbuild": "^0.25.4",
|
|
88
88
|
"fast-glob": "^3.3.3",
|
|
89
89
|
"form-data": "^4.0.4",
|
|
90
|
-
"generaltranslation": "^7.
|
|
90
|
+
"generaltranslation": "^7.5.0",
|
|
91
91
|
"json-pointer": "^0.6.2",
|
|
92
92
|
"jsonpath-plus": "^10.3.0",
|
|
93
93
|
"jsonpointer": "^5.0.1",
|