auto-translate-json-library 1.3.8 → 1.4.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
4
4
  "description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
5
5
  "main": "./build/src/index.js",
6
6
  "bin": {
@@ -8,6 +8,8 @@
8
8
  "atj": "./build/src/bin/cli.js"
9
9
  },
10
10
  "types": "./build/src/index.d.ts",
11
+ "files": ["build",
12
+ "README.md"],
11
13
  "scripts": {
12
14
  "prepare": "tsc",
13
15
  "build": "tsc",
@@ -49,21 +51,21 @@
49
51
  ],
50
52
  "license": "MIT",
51
53
  "devDependencies": {
52
- "@biomejs/biome": "1.5.3",
53
- "@topce/typescript": "5.3.1",
54
+ "@biomejs/biome": "1.6.2",
55
+ "@topce/typescript": "5.5.0",
54
56
  "@types/minimist": "1.2.5",
55
- "@types/node": "20.11.24",
57
+ "@types/node": "20.11.30",
56
58
  "@types/yargs": "17.0.32",
57
59
  "ts-node": "10.9.2"
58
60
  },
59
61
  "dependencies": {
60
- "@aws-sdk/client-translate": "3.525.0",
62
+ "@aws-sdk/client-translate": "3.540.0",
61
63
  "@google-cloud/translate": "8.1.0",
62
- "axios": "1.6.7",
64
+ "axios": "1.6.8",
63
65
  "dotenv": "16.4.5",
64
66
  "form-data": "4.0.0",
65
67
  "minimist": "1.2.8",
66
- "openai": "4.28.4",
68
+ "openai": "4.29.2",
67
69
  "picocolors": "1.0.0",
68
70
  "uuid": "9.0.1",
69
71
  "yargs": "17.7.2"
@@ -1,4 +1,4 @@
1
- import { ITranslate } from "./translate.interface";
1
+ import type { ITranslate } from "./translate.interface";
2
2
  export declare class AWSTranslate implements ITranslate {
3
3
  private accessKeyId;
4
4
  private secretAccessKey;
@@ -1,4 +1,4 @@
1
- import { ITranslate } from "./translate.interface";
1
+ import type { ITranslate } from "./translate.interface";
2
2
  export declare class AzureTranslate implements ITranslate {
3
3
  private subscriptionKey;
4
4
  private subscriptionRegion;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  var _a, _b, _c, _d, _e, _f, _g, _h;
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- const path_1 = __importDefault(require("path"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
9
  const minimist_1 = __importDefault(require("minimist"));
10
10
  const picocolors_1 = __importDefault(require("picocolors"));
11
11
  const package_json_1 = require("../../package.json");
@@ -108,9 +108,9 @@ switch (engine) {
108
108
  break;
109
109
  }
110
110
  case "openai": {
111
- const openaiApiKey = process.env.ATJ_OPENAI_API_KEY;
111
+ const openaiApiKey = process.env.ATJ_OPEN_AI_SECRET_KEY;
112
112
  if (!openaiApiKey) {
113
- console.error(picocolors_1.default.red("❌ Openai api key not found in environment variable ATJ_OPENAI_API_KEY"));
113
+ console.error(picocolors_1.default.red("❌ Openai api key not found in environment variable ATJ_OPEN_AI_SECRET_KEY"));
114
114
  process.exit(1);
115
115
  }
116
116
  config.translationKeyInfo = {
@@ -159,7 +159,7 @@ config.sourceLocale = sourceLocale;
159
159
  config.keepTranslations = keepTranslations ? "keep" : "retranslate";
160
160
  config.keepExtraTranslations = keepExtraTranslations ? "keep" : "remove";
161
161
  config.mode = mode;
162
- const sourcePath = path_1.default.join(process.cwd(), inputPath);
162
+ const sourcePath = node_path_1.default.join(process.cwd(), inputPath);
163
163
  console.log(picocolors_1.default.green(`🌐 Translating ${sourcePath}`));
164
164
  (0, lib_1.translate)(sourcePath, config).catch((error) => {
165
165
  console.error(picocolors_1.default.red("❌ Translate error:\n"), error);
@@ -1,4 +1,4 @@
1
- import { ITranslate } from "./translate.interface";
1
+ import type { ITranslate } from "./translate.interface";
2
2
  export declare class DeepLTranslate implements ITranslate {
3
3
  private subscriptionKey;
4
4
  private type;
@@ -1,4 +1,4 @@
1
- import { TranslationFile } from "./translate.interface";
1
+ import type { TranslationFile } from "./translate.interface";
2
2
  export interface IFiles {
3
3
  sourceLocale: string;
4
4
  targetLocales: Array<string>;
@@ -33,8 +33,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.Files = exports.saveJsonToLocale = exports.loadJsonFromLocale = exports.readFileAsync = void 0;
36
- const fs = __importStar(require("fs"));
37
- const path = __importStar(require("path"));
36
+ const fs = __importStar(require("node:fs"));
37
+ const path = __importStar(require("node:path"));
38
38
  const readFileAsync = (filename) => new Promise((resolve, reject) => {
39
39
  const exist = fs.existsSync(filename);
40
40
  if (!exist)
@@ -1,5 +1,5 @@
1
- import { IFiles } from "./files";
2
- import { TranslationFile } from "./translate.interface";
1
+ import { type IFiles } from "./files";
2
+ import type { TranslationFile } from "./translate.interface";
3
3
  export declare class FolderFiles implements IFiles {
4
4
  folderPath: string;
5
5
  sourceLocale: string;
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.FolderFiles = void 0;
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
27
+ const fs = __importStar(require("node:fs"));
28
+ const path = __importStar(require("node:path"));
29
29
  const files_1 = require("./files");
30
30
  class FolderFiles {
31
31
  constructor(filePath) {
@@ -1,4 +1,4 @@
1
- import { ITranslate } from "./translate.interface";
1
+ import type { ITranslate } from "./translate.interface";
2
2
  export declare class GoogleTranslate implements ITranslate {
3
3
  private googleTranslate;
4
4
  private supportedLanguages;
@@ -1,2 +1,2 @@
1
- import { Configuration } from "./config";
1
+ import type { Configuration } from "./config";
2
2
  export declare function translate(sourceFile: string, config: Configuration): Promise<void>;
package/build/src/lib.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.translate = void 0;
12
+ exports.translate = translate;
13
13
  // The module 'vscode' contains the VS Code extensibility API
14
14
  // Import the module and reference it with the alias vscode in your code below
15
15
  const files_1 = require("./files");
@@ -101,7 +101,6 @@ function translate(sourceFile, config) {
101
101
  }
102
102
  });
103
103
  }
104
- exports.translate = translate;
105
104
  const readFiles = (filePath, mode) => {
106
105
  try {
107
106
  const files = mode === "file" ? new files_1.Files(filePath) : new folderFiles_1.FolderFiles(filePath);
@@ -117,9 +116,9 @@ const readFiles = (filePath, mode) => {
117
116
  return null;
118
117
  }
119
118
  };
120
- function recurseNode(source, original, keepTranslations, keepExtras, sourceLocale, locale, translateEngine, ignorePrefix = "", isArray = false) {
121
- var _a;
122
- return __awaiter(this, void 0, void 0, function* () {
119
+ function recurseNode(source_1, original_1, keepTranslations_1, keepExtras_1, sourceLocale_1, locale_1, translateEngine_1) {
120
+ return __awaiter(this, arguments, void 0, function* (source, original, keepTranslations, keepExtras, sourceLocale, locale, translateEngine, ignorePrefix = "", isArray = false) {
121
+ var _a;
123
122
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
124
123
  const destination = isArray ? [] : {};
125
124
  // defaults
@@ -1,4 +1,4 @@
1
- import { ITranslate } from "./translate.interface";
1
+ import type { ITranslate } from "./translate.interface";
2
2
  export declare class OpenAITranslate implements ITranslate {
3
3
  private model;
4
4
  private maxTokens;
@@ -167,10 +167,18 @@ class OpenAITranslate {
167
167
  console.log(response.choices[0].message.content);
168
168
  }
169
169
  catch (_a) {
170
- // disable type script compiler for next line
171
- // @ts-ignore
172
- response = JSON.parse(response);
173
- console.log(response.choices[0].message.content);
170
+ try {
171
+ // for local server sometimes does not return response in json format
172
+ // disable type script compiler for next line
173
+ // @ts-ignore
174
+ response = JSON.parse(response);
175
+ console.log(response.choices[0].message.content);
176
+ }
177
+ catch (error) {
178
+ console.error(error);
179
+ console.log("can not parse response");
180
+ console.log(response);
181
+ }
174
182
  }
175
183
  if (response.choices[0].message.content !== null) {
176
184
  result = util_1.Util.replaceArgumentsWithNumbers(args, response.choices[0].message.content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
4
4
  "description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
5
5
  "main": "./build/src/index.js",
6
6
  "bin": {
@@ -8,6 +8,8 @@
8
8
  "atj": "./build/src/bin/cli.js"
9
9
  },
10
10
  "types": "./build/src/index.d.ts",
11
+ "files": ["build",
12
+ "README.md"],
11
13
  "scripts": {
12
14
  "prepare": "tsc",
13
15
  "build": "tsc",
@@ -49,21 +51,21 @@
49
51
  ],
50
52
  "license": "MIT",
51
53
  "devDependencies": {
52
- "@biomejs/biome": "1.5.3",
53
- "@topce/typescript": "5.3.1",
54
+ "@biomejs/biome": "1.6.2",
55
+ "@topce/typescript": "5.5.0",
54
56
  "@types/minimist": "1.2.5",
55
- "@types/node": "20.11.24",
57
+ "@types/node": "20.11.30",
56
58
  "@types/yargs": "17.0.32",
57
59
  "ts-node": "10.9.2"
58
60
  },
59
61
  "dependencies": {
60
- "@aws-sdk/client-translate": "3.525.0",
62
+ "@aws-sdk/client-translate": "3.540.0",
61
63
  "@google-cloud/translate": "8.1.0",
62
- "axios": "1.6.7",
64
+ "axios": "1.6.8",
63
65
  "dotenv": "16.4.5",
64
66
  "form-data": "4.0.0",
65
67
  "minimist": "1.2.8",
66
- "openai": "4.28.4",
68
+ "openai": "4.29.2",
67
69
  "picocolors": "1.0.0",
68
70
  "uuid": "9.0.1",
69
71
  "yargs": "17.7.2"