auto-translate-json-library 1.3.9 → 1.4.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/README.MD CHANGED
@@ -9,9 +9,9 @@ not just in vs code but as a library and command line interface
9
9
 
10
10
  You can use Azure,AWS,Google,DeepL,Open AI or
11
11
  local OPEN AI compatible REST API
12
- for example [jan](https://jan.ai/) local server
13
- http://localhost:1337/v1
14
- and model mistral-ins-7b-q4
12
+ for example [ollama](https://ollama.com/)
13
+ because it is compatible with Open AI https://ollama.com/blog/openai-compatibility :
14
+
15
15
 
16
16
  ## Use as library
17
17
 
@@ -48,7 +48,16 @@ do not forget to set translation engine parameters in environment variables or .
48
48
  node node_modules\auto-translate-json-library\index.js --pivotTranslation=./translations/en.json
49
49
  ```
50
50
 
51
- if you clone repo you can use the following commands
51
+ ## Contribute
52
+
53
+ Clone repo you can use the following commands
54
+
55
+ install ollama
56
+ run ollama run llama2
57
+ rename ollama.env to .env
58
+ install
59
+ build project
60
+ and rune it
52
61
 
53
62
  ```shell
54
63
  npm i
@@ -56,6 +65,8 @@ npm run build
56
65
  node .\build\src\index.js --pivotTranslation=./tests/translations/en.json
57
66
  ```
58
67
 
68
+ After some time you should see es.json file with translation
69
+
59
70
  ## CLI PARAMETERS
60
71
 
61
72
  ```config
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "1.3.9",
3
+ "version": "1.4.1",
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");
@@ -119,8 +119,8 @@ switch (engine) {
119
119
  baseUrl: (_a = process.env.ATJ_OPEN_AI_BASE_URL) !== null && _a !== void 0 ? _a : "https://api.openai.com/v1",
120
120
  model: (_b = process.env.ATJ_OPEN_AI_MODEL) !== null && _b !== void 0 ? _b : "gpt-3.5-turbo",
121
121
  maxTokens: Number((_c = process.env.ATJ_OPEN_AI_MAX_TOKENS) !== null && _c !== void 0 ? _c : "256"),
122
- temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0"),
123
- topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "1.0"),
122
+ temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0.7"),
123
+ topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "0.9"),
124
124
  n: Number((_f = process.env.ATJ_OPEN_AI_N) !== null && _f !== void 0 ? _f : "1"),
125
125
  frequencyPenalty: Number((_g = process.env.ATJ_OPEN_AI_FREQUENCY_PENALTY) !== null && _g !== void 0 ? _g : "0"),
126
126
  presencePenalty: Number((_h = process.env.ATJ_OPEN_AI_PRESENCE_PENALTY) !== null && _h !== void 0 ? _h : "0"),
@@ -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;
@@ -102,8 +102,8 @@ function setConfigurationFromEnvironment() {
102
102
  baseUrl: (_a = process.env.ATJ_OPEN_AI_BASE_URL) !== null && _a !== void 0 ? _a : "https://api.openai.com/v1",
103
103
  model: (_b = process.env.ATJ_OPEN_AI_MODEL) !== null && _b !== void 0 ? _b : "gpt-3.5-turbo",
104
104
  maxTokens: Number((_c = process.env.ATJ_OPEN_AI_MAX_TOKENS) !== null && _c !== void 0 ? _c : "256"),
105
- temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0"),
106
- topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "1.0"),
105
+ temperature: Number((_d = process.env.ATJ_OPEN_AI_TEMPERATURE) !== null && _d !== void 0 ? _d : "0.7"),
106
+ topP: Number((_e = process.env.ATJ_OPEN_AI_TOP_P) !== null && _e !== void 0 ? _e : "0.9"),
107
107
  n: Number((_f = process.env.ATJ_OPEN_AI_N) !== null && _f !== void 0 ? _f : "1"),
108
108
  frequencyPenalty: Number((_g = process.env.ATJ_OPEN_AI_FREQUENCY_PENALTY) !== null && _g !== void 0 ? _g : "0"),
109
109
  presencePenalty: Number((_h = process.env.ATJ_OPEN_AI_PRESENCE_PENALTY) !== null && _h !== void 0 ? _h : "0"),
@@ -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;
@@ -148,9 +148,9 @@ class OpenAITranslate {
148
148
  let result = "";
149
149
  let args;
150
150
  ({ args, text } = util_1.Util.replaceContextVariables(text));
151
- const systemPrompt = `You will be provided with a sentence in English, and your task is to translate it into ${supportedLanguages[targetLocale]}`;
151
+ const systemPrompt = `You will be provided with a sentence or words in English, and your task is to translate it into ${supportedLanguages[targetLocale]}`;
152
152
  const userPrompt = text;
153
- let response = yield this.openai.chat.completions.create({
153
+ const response = yield this.openai.chat.completions.create({
154
154
  model: this.model,
155
155
  messages: [
156
156
  { role: "system", content: systemPrompt },
@@ -163,23 +163,6 @@ class OpenAITranslate {
163
163
  frequency_penalty: this.frequencyPenalty,
164
164
  presence_penalty: this.presencePenalty,
165
165
  });
166
- try {
167
- console.log(response.choices[0].message.content);
168
- }
169
- catch (_a) {
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
- }
182
- }
183
166
  if (response.choices[0].message.content !== null) {
184
167
  result = util_1.Util.replaceArgumentsWithNumbers(args, response.choices[0].message.content);
185
168
  result = result.replace(/^\n+|\n+$/g, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-translate-json-library",
3
- "version": "1.3.9",
3
+ "version": "1.4.1",
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"