glotto 2.8.0 → 3.0.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/README.md +86 -55
- package/esm/cli.js +49 -41
- package/esm/deno.d.ts +1 -1
- package/esm/deno.js +7 -7
- package/esm/deps/jsr.io/@std/cli/1.0.29/_data.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.js +17 -3
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.js +1 -1
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/internal/1.0.13/_os.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.js +1 -1
- package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/basename.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/constants.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/dirname.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/extname.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/format.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/from_file_url.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/glob_to_regexp.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/is_absolute.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/join.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/join_globs.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/normalize.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/normalize_glob.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/parse.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/relative.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/resolve.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/to_file_url.js +1 -1
- package/esm/deps/jsr.io/@std/path/1.1.4/to_namespaced_path.js +1 -1
- package/esm/src/contants.d.ts +2 -3
- package/esm/src/contants.d.ts.map +1 -1
- package/esm/src/contants.js +22 -13
- package/esm/src/file.d.ts +2 -7
- package/esm/src/file.d.ts.map +1 -1
- package/esm/src/file.js +1 -93
- package/esm/src/providers/anthropic.d.ts +6 -11
- package/esm/src/providers/anthropic.d.ts.map +1 -1
- package/esm/src/providers/anthropic.js +14 -103
- package/esm/src/providers/gemini.d.ts +6 -11
- package/esm/src/providers/gemini.d.ts.map +1 -1
- package/esm/src/providers/gemini.js +13 -109
- package/esm/src/providers/openai.d.ts +6 -11
- package/esm/src/providers/openai.d.ts.map +1 -1
- package/esm/src/providers/openai.js +10 -104
- package/esm/src/translator.d.ts +8 -0
- package/esm/src/translator.d.ts.map +1 -0
- package/esm/src/translator.js +200 -0
- package/esm/src/types.d.ts +28 -11
- package/esm/src/types.d.ts.map +1 -1
- package/esm/src/utilites.d.ts +1 -6
- package/esm/src/utilites.d.ts.map +1 -1
- package/esm/src/utilites.js +18 -77
- package/package.json +4 -4
- package/script/cli.js +47 -39
- package/script/deno.d.ts +1 -1
- package/script/deno.js +7 -7
- package/script/deps/jsr.io/@std/cli/1.0.29/_data.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.js +17 -3
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.js +1 -1
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/internal/1.0.13/_os.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.js +1 -1
- package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/basename.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/constants.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/dirname.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/extname.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/format.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/from_file_url.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/glob_to_regexp.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/is_absolute.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/join.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/join_globs.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/normalize.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/normalize_glob.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/parse.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/relative.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/resolve.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/to_file_url.js +1 -1
- package/script/deps/jsr.io/@std/path/1.1.4/to_namespaced_path.js +1 -1
- package/script/src/contants.d.ts +2 -3
- package/script/src/contants.d.ts.map +1 -1
- package/script/src/contants.js +23 -14
- package/script/src/file.d.ts +2 -7
- package/script/src/file.d.ts.map +1 -1
- package/script/src/file.js +2 -99
- package/script/src/providers/anthropic.d.ts +6 -11
- package/script/src/providers/anthropic.d.ts.map +1 -1
- package/script/src/providers/anthropic.js +13 -102
- package/script/src/providers/gemini.d.ts +6 -11
- package/script/src/providers/gemini.d.ts.map +1 -1
- package/script/src/providers/gemini.js +12 -108
- package/script/src/providers/openai.d.ts +6 -11
- package/script/src/providers/openai.d.ts.map +1 -1
- package/script/src/providers/openai.js +9 -103
- package/script/src/translator.d.ts +8 -0
- package/script/src/translator.d.ts.map +1 -0
- package/script/src/translator.js +209 -0
- package/script/src/types.d.ts +28 -11
- package/script/src/types.d.ts.map +1 -1
- package/script/src/utilites.d.ts +1 -6
- package/script/src/utilites.d.ts.map +1 -1
- package/script/src/utilites.js +19 -80
- package/esm/deps/jsr.io/@std/cli/1.0.27/_data.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -192
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -113
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -26
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -152
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -87
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -131
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -82
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -72
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -99
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -205
- package/esm/deps/jsr.io/@std/internal/1.0.12/_os.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/cli/1.0.27/_data.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -57
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -198
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -119
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -16
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -3
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -29
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -156
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -91
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -135
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -86
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -76
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -91
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -115
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -211
- package/script/deps/jsr.io/@std/internal/1.0.12/_os.d.ts.map +0 -1
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.js +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.js +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.js +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.js +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.js +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.js +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.js +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.js +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.js +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts +0 -0
- /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.js +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.d.ts +0 -0
- /package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.d.ts +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runBatches = exports.reconstruct = exports.decodeResponse = exports.buildBatchPrompt = exports.groupIntoBatches = exports.extractLeaves = void 0;
|
|
4
|
+
const logger_js_1 = require("./logger.js");
|
|
5
|
+
const utilites_js_1 = require("./utilites.js");
|
|
6
|
+
const contants_js_1 = require("./contants.js");
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const byteSize = (s) => encoder.encode(s).byteLength;
|
|
9
|
+
const extractLeaves = (data) => {
|
|
10
|
+
const out = [];
|
|
11
|
+
let nextId = 0;
|
|
12
|
+
const walk = (node, path) => {
|
|
13
|
+
if (node === null || typeof node !== 'object') {
|
|
14
|
+
const isString = typeof node === 'string';
|
|
15
|
+
out.push({
|
|
16
|
+
id: ++nextId,
|
|
17
|
+
path,
|
|
18
|
+
value: node,
|
|
19
|
+
translatable: isString && node.trim().length > 0,
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(node)) {
|
|
24
|
+
if (node.length === 0) {
|
|
25
|
+
out.push({ id: ++nextId, path, value: node, translatable: false });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
node.forEach((item, i) => walk(item, [...path, i]));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const entries = Object.entries(node);
|
|
32
|
+
if (entries.length === 0) {
|
|
33
|
+
out.push({ id: ++nextId, path, value: node, translatable: false });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const [k, v] of entries)
|
|
37
|
+
walk(v, [...path, k]);
|
|
38
|
+
};
|
|
39
|
+
walk(data, []);
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
exports.extractLeaves = extractLeaves;
|
|
43
|
+
const TAG_OPEN = (id) => `≪${id}≫`;
|
|
44
|
+
const TAG_CLOSE = (id) => `≪/${id}≫`;
|
|
45
|
+
const TAG_OVERHEAD_CHARS = 8;
|
|
46
|
+
const wrapEntry = (leaf) => `${TAG_OPEN(leaf.id)}${String(leaf.value)}${TAG_CLOSE(leaf.id)}`;
|
|
47
|
+
const groupIntoBatches = (leaves, maxBytes) => {
|
|
48
|
+
const translatable = leaves.filter((l) => l.translatable);
|
|
49
|
+
const batches = [];
|
|
50
|
+
let current = [];
|
|
51
|
+
let currentSize = 0;
|
|
52
|
+
for (const leaf of translatable) {
|
|
53
|
+
const valueBytes = byteSize(String(leaf.value));
|
|
54
|
+
const idChars = String(leaf.id).length;
|
|
55
|
+
const overhead = TAG_OVERHEAD_CHARS + idChars * 2 + 1;
|
|
56
|
+
const itemSize = valueBytes + overhead;
|
|
57
|
+
if (current.length > 0 && currentSize + itemSize > maxBytes) {
|
|
58
|
+
batches.push({ index: batches.length, leaves: current, byteSize: currentSize });
|
|
59
|
+
current = [];
|
|
60
|
+
currentSize = 0;
|
|
61
|
+
}
|
|
62
|
+
current.push(leaf);
|
|
63
|
+
currentSize += itemSize;
|
|
64
|
+
}
|
|
65
|
+
if (current.length > 0) {
|
|
66
|
+
batches.push({ index: batches.length, leaves: current, byteSize: currentSize });
|
|
67
|
+
}
|
|
68
|
+
return batches;
|
|
69
|
+
};
|
|
70
|
+
exports.groupIntoBatches = groupIntoBatches;
|
|
71
|
+
const buildBatchPrompt = (from, to, leaves) => {
|
|
72
|
+
const entries = leaves.map(wrapEntry).join('\n');
|
|
73
|
+
return `Translate each tagged entry below from ${from} to ${to}.
|
|
74
|
+
|
|
75
|
+
Tag format:
|
|
76
|
+
- Every entry is wrapped exactly as ≪N≫value≪/N≫, where N is the entry id (a positive integer).
|
|
77
|
+
- The opening marker is the character ≪ (U+226A), then the id, then ≫ (U+226B). The closing marker is ≪, /, the same id, then ≫.
|
|
78
|
+
- Copy these markers verbatim. Do not put spaces inside them. Do not change them to <<>>, «», <tag>, [n], or any other notation.
|
|
79
|
+
- The id must match the input id of the same entry — never renumber, merge, split, or reorder entries.
|
|
80
|
+
|
|
81
|
+
What to write back:
|
|
82
|
+
- One ≪N≫translated_value≪/N≫ block per input entry, in the same order, separated by single newlines.
|
|
83
|
+
- Translate only the text that sits between ≪N≫ and ≪/N≫.
|
|
84
|
+
- Preserve every variable ({{name}}, {name}, __VAR__, $t(...), %s, %d), HTML tag, markdown token, escape sequence, and special character inside the value.
|
|
85
|
+
- Output nothing else: no headings, no prose, no commentary, no code fences, no language labels.
|
|
86
|
+
|
|
87
|
+
Now translate the following entries:
|
|
88
|
+
${entries}`;
|
|
89
|
+
};
|
|
90
|
+
exports.buildBatchPrompt = buildBatchPrompt;
|
|
91
|
+
const TAG_PATTERNS = [
|
|
92
|
+
/≪\s*(\d+)\s*≫([\s\S]*?)≪\s*\/\s*\1\s*≫/g,
|
|
93
|
+
/<<\s*(\d+)\s*>>([\s\S]*?)<<\s*\/\s*\1\s*>>/g,
|
|
94
|
+
/«\s*(\d+)\s*»([\s\S]*?)«\s*\/\s*\1\s*»/g,
|
|
95
|
+
];
|
|
96
|
+
const decodeResponse = (text) => {
|
|
97
|
+
const map = new Map();
|
|
98
|
+
for (const pattern of TAG_PATTERNS) {
|
|
99
|
+
for (const match of text.matchAll(pattern)) {
|
|
100
|
+
const id = parseInt(match[1], 10);
|
|
101
|
+
if (!map.has(id))
|
|
102
|
+
map.set(id, match[2].trim());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return map;
|
|
106
|
+
};
|
|
107
|
+
exports.decodeResponse = decodeResponse;
|
|
108
|
+
const setPath = (root, path, value) => {
|
|
109
|
+
let node = root;
|
|
110
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
111
|
+
const key = path[i];
|
|
112
|
+
const nextKey = path[i + 1];
|
|
113
|
+
const container = node;
|
|
114
|
+
if (container[key] === undefined) {
|
|
115
|
+
container[key] = typeof nextKey === 'number' ? [] : {};
|
|
116
|
+
}
|
|
117
|
+
node = container[key];
|
|
118
|
+
}
|
|
119
|
+
node[path[path.length - 1]] = value;
|
|
120
|
+
};
|
|
121
|
+
const reconstruct = (allLeaves, translations) => {
|
|
122
|
+
if (allLeaves.length === 0)
|
|
123
|
+
return {};
|
|
124
|
+
const firstStep = allLeaves[0].path[0];
|
|
125
|
+
if (firstStep === undefined) {
|
|
126
|
+
const only = allLeaves[0];
|
|
127
|
+
return only.translatable ? translations.get(only.id) ?? only.value : only.value;
|
|
128
|
+
}
|
|
129
|
+
const root = typeof firstStep === 'number' ? [] : {};
|
|
130
|
+
for (const leaf of allLeaves) {
|
|
131
|
+
const value = leaf.translatable && translations.has(leaf.id) ? translations.get(leaf.id) : leaf.value;
|
|
132
|
+
setPath(root, leaf.path, value);
|
|
133
|
+
}
|
|
134
|
+
return root;
|
|
135
|
+
};
|
|
136
|
+
exports.reconstruct = reconstruct;
|
|
137
|
+
const runBatches = async (batches, translator, from, to, options) => {
|
|
138
|
+
const translations = new Map();
|
|
139
|
+
const failedIds = [];
|
|
140
|
+
for (let i = 0; i < batches.length; i++) {
|
|
141
|
+
const batch = batches[i];
|
|
142
|
+
const label = `[Batch ${batch.index + 1}/${batches.length}]`;
|
|
143
|
+
if (i > 0 && !options.noLimit) {
|
|
144
|
+
logger_js_1.logger.info(`Waiting ${contants_js_1.INTER_BATCH_DELAY_MS}ms before next batch (rate limit protection)...`);
|
|
145
|
+
await (0, utilites_js_1.delay)(contants_js_1.INTER_BATCH_DELAY_MS);
|
|
146
|
+
}
|
|
147
|
+
let remaining = [...batch.leaves];
|
|
148
|
+
for (let attempt = 0; attempt <= contants_js_1.MAX_RETRIES; attempt++) {
|
|
149
|
+
if (attempt > 0) {
|
|
150
|
+
const backoffMs = contants_js_1.BASE_RETRY_DELAY_MS * Math.pow(2, attempt - 1);
|
|
151
|
+
logger_js_1.logger.warn(`${label} Retry ${attempt}/${contants_js_1.MAX_RETRIES} after ${backoffMs}ms backoff (${remaining.length} entries)...`);
|
|
152
|
+
await (0, utilites_js_1.delay)(backoffMs);
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const prompt = (0, exports.buildBatchPrompt)(from, to, remaining);
|
|
156
|
+
const response = await translator.translate(prompt);
|
|
157
|
+
if (!response || response.trim().length === 0) {
|
|
158
|
+
if (attempt === contants_js_1.MAX_RETRIES) {
|
|
159
|
+
logger_js_1.logger.error(`${label} Failed after ${contants_js_1.MAX_RETRIES + 1} attempts: empty response`);
|
|
160
|
+
for (const leaf of remaining)
|
|
161
|
+
failedIds.push(leaf.id);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
logger_js_1.logger.warn(`${label} Attempt ${attempt + 1} returned empty response`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const decoded = (0, exports.decodeResponse)(response);
|
|
168
|
+
const stillMissing = [];
|
|
169
|
+
for (const leaf of remaining) {
|
|
170
|
+
const value = decoded.get(leaf.id);
|
|
171
|
+
if (!value || value.trim().length === 0) {
|
|
172
|
+
stillMissing.push(leaf);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
translations.set(leaf.id, value);
|
|
176
|
+
}
|
|
177
|
+
if (stillMissing.length === 0) {
|
|
178
|
+
logger_js_1.logger.info(`${label} Translated successfully (${(0, utilites_js_1.formatBytes)(batch.byteSize)}, ${batch.leaves.length} entries)`);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (attempt === contants_js_1.MAX_RETRIES) {
|
|
182
|
+
logger_js_1.logger.error(`${label} Failed after ${contants_js_1.MAX_RETRIES + 1} attempts: ${stillMissing.length} entries missing`);
|
|
183
|
+
for (const leaf of stillMissing)
|
|
184
|
+
failedIds.push(leaf.id);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
logger_js_1.logger.warn(`${label} ${stillMissing.length}/${remaining.length} entries missing, will retry`);
|
|
188
|
+
remaining = stillMissing;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
192
|
+
if (attempt === contants_js_1.MAX_RETRIES) {
|
|
193
|
+
logger_js_1.logger.error(`${label} Failed after ${contants_js_1.MAX_RETRIES + 1} attempts: ${message}`);
|
|
194
|
+
for (const leaf of remaining)
|
|
195
|
+
failedIds.push(leaf.id);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
logger_js_1.logger.warn(`${label} Attempt ${attempt + 1} failed: ${message}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (failedIds.length > 0) {
|
|
203
|
+
const preview = failedIds.slice(0, 20).join(', ');
|
|
204
|
+
const more = failedIds.length > 20 ? `, …(+${failedIds.length - 20})` : '';
|
|
205
|
+
throw new Error(`Translation failed for ${failedIds.length} entry/entries (ids: ${preview}${more})`);
|
|
206
|
+
}
|
|
207
|
+
return translations;
|
|
208
|
+
};
|
|
209
|
+
exports.runBatches = runBatches;
|
package/script/src/types.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export type Provider = 'gemini' | 'openai' | 'anthropic';
|
|
2
|
+
export type TranslateOptions = {
|
|
3
|
+
noLimit: boolean;
|
|
4
|
+
noTimeout: boolean;
|
|
5
|
+
};
|
|
2
6
|
export type TranslateArgs = {
|
|
3
7
|
key?: string;
|
|
4
8
|
provider?: string;
|
|
@@ -8,6 +12,9 @@ export type TranslateArgs = {
|
|
|
8
12
|
from?: string;
|
|
9
13
|
to?: string;
|
|
10
14
|
url?: string;
|
|
15
|
+
'no-limit'?: boolean;
|
|
16
|
+
'no-timeout'?: boolean;
|
|
17
|
+
'max-batch-size'?: string;
|
|
11
18
|
};
|
|
12
19
|
export type ValidatedTranslateArgs = {
|
|
13
20
|
key: string;
|
|
@@ -18,19 +25,29 @@ export type ValidatedTranslateArgs = {
|
|
|
18
25
|
from: string;
|
|
19
26
|
to: string;
|
|
20
27
|
url?: string;
|
|
28
|
+
noLimit: boolean;
|
|
29
|
+
noTimeout: boolean;
|
|
30
|
+
maxBatchBytes: number;
|
|
21
31
|
};
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
to: string;
|
|
26
|
-
translate(): Promise<string>;
|
|
32
|
+
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
33
|
+
export interface JsonObject {
|
|
34
|
+
[key: string]: JsonValue;
|
|
27
35
|
}
|
|
28
|
-
export type
|
|
29
|
-
export type
|
|
30
|
-
export type
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
export type JsonArray = JsonValue[];
|
|
37
|
+
export type PathSegment = string | number;
|
|
38
|
+
export type Path = PathSegment[];
|
|
39
|
+
export type Leaf = {
|
|
40
|
+
id: number;
|
|
41
|
+
path: Path;
|
|
42
|
+
value: JsonValue;
|
|
43
|
+
translatable: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type Batch = {
|
|
34
46
|
index: number;
|
|
47
|
+
leaves: Leaf[];
|
|
48
|
+
byteSize: number;
|
|
35
49
|
};
|
|
50
|
+
export interface TextTranslator {
|
|
51
|
+
translate(prompt: string): Promise<string>;
|
|
52
|
+
}
|
|
36
53
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEzD,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEzD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,CAAC;AAClF,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AACD,MAAM,MAAM,SAAS,GAAG,SAAS,EAAE,CAAC;AAEpC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAC1C,MAAM,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC;AAEjC,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,IAAI,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C"}
|
package/script/src/utilites.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { TranslateArgs, ValidatedTranslateArgs } from './types.js';
|
|
2
|
-
import type { Args } from '../deps/jsr.io/@std/cli/1.0.
|
|
2
|
+
import type { Args } from '../deps/jsr.io/@std/cli/1.0.29/mod.js';
|
|
3
3
|
export declare const validateArgs: (args: Args<TranslateArgs>) => ValidatedTranslateArgs;
|
|
4
|
-
export declare const generatePrompts: (from: string, to: string) => {
|
|
5
|
-
systemPrompt: string;
|
|
6
|
-
userPrompt: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const isValidJson: (value: string) => boolean;
|
|
9
4
|
export declare const formatBytes: (bytes: number) => string;
|
|
10
5
|
export declare const delay: (ms: number) => Promise<void>;
|
|
11
6
|
//# sourceMappingURL=utilites.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilites.d.ts","sourceRoot":"","sources":["../../src/src/utilites.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,aAAa,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"utilites.d.ts","sourceRoot":"","sources":["../../src/src/utilites.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,aAAa,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAGlE,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI,CAAC,aAAa,CAAC,KAAG,sBA+BxD,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAI3C,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,KAAG,OAAO,CAAC,IAAI,CAE9C,CAAC"}
|
package/script/src/utilites.js
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.delay = exports.formatBytes = exports.
|
|
3
|
+
exports.delay = exports.formatBytes = exports.validateArgs = void 0;
|
|
4
|
+
const contants_js_1 = require("./contants.js");
|
|
4
5
|
const validateArgs = (args) => {
|
|
5
|
-
if (!args.key)
|
|
6
|
+
if (!args.key)
|
|
6
7
|
throw new Error('AI Key is required');
|
|
7
|
-
|
|
8
|
-
if (!args.provider) {
|
|
8
|
+
if (!args.provider)
|
|
9
9
|
throw new Error('Provider parameter is required');
|
|
10
|
-
|
|
11
|
-
if (!args.input) {
|
|
10
|
+
if (!args.input)
|
|
12
11
|
throw new Error('Input parameter is required');
|
|
13
|
-
|
|
14
|
-
if (!args.output) {
|
|
12
|
+
if (!args.output)
|
|
15
13
|
throw new Error('Output parameter is required');
|
|
16
|
-
|
|
17
|
-
if (!args.from) {
|
|
14
|
+
if (!args.from)
|
|
18
15
|
throw new Error('Source language (from) parameter is required');
|
|
19
|
-
|
|
20
|
-
if (!args.to) {
|
|
16
|
+
if (!args.to)
|
|
21
17
|
throw new Error('Target language (to) parameter is required');
|
|
18
|
+
let maxBatchBytes = contants_js_1.DEFAULT_MAX_BATCH_BYTES;
|
|
19
|
+
const rawMaxBatchSize = args['max-batch-size'];
|
|
20
|
+
if (rawMaxBatchSize !== undefined) {
|
|
21
|
+
const parsed = parseInt(rawMaxBatchSize, 10);
|
|
22
|
+
if (isNaN(parsed) || parsed <= 0) {
|
|
23
|
+
throw new Error('--max-batch-size must be a positive integer (value in KB, e.g. --max-batch-size 8)');
|
|
24
|
+
}
|
|
25
|
+
maxBatchBytes = parsed * 1024;
|
|
22
26
|
}
|
|
23
27
|
return {
|
|
24
28
|
key: args.key,
|
|
@@ -29,77 +33,12 @@ const validateArgs = (args) => {
|
|
|
29
33
|
from: args.from,
|
|
30
34
|
to: args.to,
|
|
31
35
|
url: args.url,
|
|
36
|
+
noLimit: args['no-limit'] ?? false,
|
|
37
|
+
noTimeout: args['no-timeout'] ?? false,
|
|
38
|
+
maxBatchBytes,
|
|
32
39
|
};
|
|
33
40
|
};
|
|
34
41
|
exports.validateArgs = validateArgs;
|
|
35
|
-
const generatePrompts = (from, to) => {
|
|
36
|
-
const systemPrompt = `You are a specialized i18next JSON translation expert. Your role is to translate content from ${from} to ${to} with these strict requirements:
|
|
37
|
-
|
|
38
|
-
1. COMPLETE TRANSLATION:
|
|
39
|
-
- Translate ALL text values comprehensively
|
|
40
|
-
- Double-check to ensure no text is left untranslated
|
|
41
|
-
- Pay special attention to arrays and nested objects to ensure everything is translated
|
|
42
|
-
- If unsure about any translation, provide the most accurate and natural translation possible
|
|
43
|
-
|
|
44
|
-
2. TRANSLATION QUALITY:
|
|
45
|
-
- Use natural, context-appropriate language
|
|
46
|
-
- Maintain consistent terminology throughout the translation
|
|
47
|
-
- Use formal language unless the source is clearly casual
|
|
48
|
-
- Preserve the exact meaning and tone of the original text
|
|
49
|
-
- For UI elements, use standard localized terms common in ${to} applications
|
|
50
|
-
|
|
51
|
-
3. STRUCTURAL PRESERVATION:
|
|
52
|
-
- Keep all JSON structure and keys exactly as they are
|
|
53
|
-
- Maintain all variables and interpolation patterns ({{name}}, __VARIABLE__, $t(), etc.)
|
|
54
|
-
- Preserve all HTML tags and markdown formatting
|
|
55
|
-
- Keep all whitespace, nesting, and formatting intact
|
|
56
|
-
|
|
57
|
-
4. VALIDATION:
|
|
58
|
-
- Return only valid JSON
|
|
59
|
-
- Verify that all text is translated
|
|
60
|
-
- Ensure no source language text remains
|
|
61
|
-
- Confirm all arrays and nested objects are fully translated`;
|
|
62
|
-
const userPrompt = `Please translate this i18next JSON file with these specific requirements:
|
|
63
|
-
|
|
64
|
-
1. THOROUGH TRANSLATION:
|
|
65
|
-
- Translate every single text value from ${from} to ${to}
|
|
66
|
-
- Pay special attention to arrays and nested objects
|
|
67
|
-
- Verify no text is left in ${from}
|
|
68
|
-
- Double-check all translations for completeness
|
|
69
|
-
|
|
70
|
-
2. PRESERVE STRUCTURE:
|
|
71
|
-
- Keep all keys unchanged (e.g. "button.submit")
|
|
72
|
-
- Maintain all variables: {{name}}, __VAR__, $t()
|
|
73
|
-
- Preserve HTML tags and markdown
|
|
74
|
-
- Keep all special characters
|
|
75
|
-
- Maintain exact JSON structure
|
|
76
|
-
|
|
77
|
-
3. QUALITY REQUIREMENTS:
|
|
78
|
-
- Use natural ${to} language
|
|
79
|
-
- Maintain consistent terminology
|
|
80
|
-
- Use formal language unless source is casual
|
|
81
|
-
- Ensure translations match the context
|
|
82
|
-
- Use standard ${to} UI terminology for interface elements
|
|
83
|
-
|
|
84
|
-
4. OUTPUT:
|
|
85
|
-
- Return only the translated JSON
|
|
86
|
-
- No explanations or comments
|
|
87
|
-
- No additional text
|
|
88
|
-
- No formatting changes
|
|
89
|
-
- Must be valid JSON`;
|
|
90
|
-
return { systemPrompt, userPrompt };
|
|
91
|
-
};
|
|
92
|
-
exports.generatePrompts = generatePrompts;
|
|
93
|
-
const isValidJson = (value) => {
|
|
94
|
-
try {
|
|
95
|
-
JSON.parse(value);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
exports.isValidJson = isValidJson;
|
|
103
42
|
const formatBytes = (bytes) => {
|
|
104
43
|
if (bytes < 1024)
|
|
105
44
|
return `${bytes} B`;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_data.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cli/1.0.27/_data.js"],"names":[],"mappings":""}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
-
export type { Uint8Array_ };
|
|
3
|
-
export declare const alphabet: Uint8Array<ArrayBufferLike>;
|
|
4
|
-
export declare const rAlphabet: Uint8Array<ArrayBuffer>;
|
|
5
|
-
/**
|
|
6
|
-
* Calculate the output size needed to encode a given input size for
|
|
7
|
-
* {@linkcode encodeIntoHex}.
|
|
8
|
-
*
|
|
9
|
-
* @param originalSize The size of the input buffer.
|
|
10
|
-
* @returns The size of the output buffer.
|
|
11
|
-
*
|
|
12
|
-
* @example Basic Usage
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { assertEquals } from "@std/assert";
|
|
15
|
-
* import { calcSizeHex } from "@std/encoding/unstable-hex";
|
|
16
|
-
*
|
|
17
|
-
* assertEquals(calcSizeHex(1), 2);
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function calcSizeHex(originalSize: number): number;
|
|
21
|
-
export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
|
|
22
|
-
export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array): number;
|
|
23
|
-
//# sourceMappingURL=_common16.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_common16.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common16.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,QAAQ,6BAA+C,CAAC;AACrE,eAAO,MAAM,SAAS,yBAA+B,CAAC;AAMtD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAOR;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,GACnB,MAAM,CAeR"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
-
export const alphabet = new TextEncoder().encode("0123456789abcdef");
|
|
3
|
-
export const rAlphabet = new Uint8Array(128).fill(16); // alphabet.Hex.length
|
|
4
|
-
alphabet.forEach((byte, i) => rAlphabet[byte] = i);
|
|
5
|
-
new TextEncoder()
|
|
6
|
-
.encode("ABCDEF")
|
|
7
|
-
.forEach((byte, i) => rAlphabet[byte] = i + 10);
|
|
8
|
-
/**
|
|
9
|
-
* Calculate the output size needed to encode a given input size for
|
|
10
|
-
* {@linkcode encodeIntoHex}.
|
|
11
|
-
*
|
|
12
|
-
* @param originalSize The size of the input buffer.
|
|
13
|
-
* @returns The size of the output buffer.
|
|
14
|
-
*
|
|
15
|
-
* @example Basic Usage
|
|
16
|
-
* ```ts
|
|
17
|
-
* import { assertEquals } from "@std/assert";
|
|
18
|
-
* import { calcSizeHex } from "@std/encoding/unstable-hex";
|
|
19
|
-
*
|
|
20
|
-
* assertEquals(calcSizeHex(1), 2);
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function calcSizeHex(originalSize) {
|
|
24
|
-
return originalSize * 2;
|
|
25
|
-
}
|
|
26
|
-
export function encode(buffer, i, o, alphabet) {
|
|
27
|
-
for (; i < buffer.length; ++i) {
|
|
28
|
-
const x = buffer[i];
|
|
29
|
-
buffer[o++] = alphabet[x >> 4];
|
|
30
|
-
buffer[o++] = alphabet[x & 0xF];
|
|
31
|
-
}
|
|
32
|
-
return o;
|
|
33
|
-
}
|
|
34
|
-
export function decode(buffer, i, o, alphabet) {
|
|
35
|
-
if ((buffer.length - o) % 2 === 1) {
|
|
36
|
-
throw new RangeError(`Cannot decode input as hex: Length (${buffer.length - o}) must be divisible by 2`);
|
|
37
|
-
}
|
|
38
|
-
i += 1;
|
|
39
|
-
for (; i < buffer.length; i += 2) {
|
|
40
|
-
buffer[o++] = (getByte(buffer[i - 1], alphabet) << 4) |
|
|
41
|
-
getByte(buffer[i], alphabet);
|
|
42
|
-
}
|
|
43
|
-
return o;
|
|
44
|
-
}
|
|
45
|
-
function getByte(char, alphabet) {
|
|
46
|
-
const byte = alphabet[char] ?? 16;
|
|
47
|
-
if (byte === 16) { // alphabet.Hex.length
|
|
48
|
-
throw new TypeError(`Cannot decode input as hex: Invalid character (${String.fromCharCode(char)})`);
|
|
49
|
-
}
|
|
50
|
-
return byte;
|
|
51
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Uint8Array_ } from "./_types.js";
|
|
2
|
-
export type { Uint8Array_ };
|
|
3
|
-
export declare const padding: number;
|
|
4
|
-
export declare const alphabet: Record<Base32Alphabet, Uint8Array>;
|
|
5
|
-
export declare const rAlphabet: Record<Base32Alphabet, Uint8Array>;
|
|
6
|
-
/**
|
|
7
|
-
* Options for encoding and decoding base32 strings.
|
|
8
|
-
*/
|
|
9
|
-
export interface Base32Options {
|
|
10
|
-
/** The base32 alphabet. Defaults to "base32" */
|
|
11
|
-
alphabet?: Base32Alphabet;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The base32 alphabets.
|
|
15
|
-
*/
|
|
16
|
-
export type Base32Alphabet = "base32" | "base32hex" | "base32crockford";
|
|
17
|
-
/**
|
|
18
|
-
* Calculate the output size needed to encode a given input size for
|
|
19
|
-
* {@linkcode encodeIntoBase32}.
|
|
20
|
-
*
|
|
21
|
-
* @param rawSize The size of the input buffer.
|
|
22
|
-
* @returns The size of the output buffer.
|
|
23
|
-
*
|
|
24
|
-
* @example Basic Usage
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { assertEquals } from "@std/assert";
|
|
27
|
-
* import { calcSizeBase32 } from "@std/encoding/unstable-base32";
|
|
28
|
-
*
|
|
29
|
-
* assertEquals(calcSizeBase32(1), 8);
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function calcSizeBase32(rawSize: number): number;
|
|
33
|
-
export declare function encode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
34
|
-
export declare function decode(buffer: Uint8Array_, i: number, o: number, alphabet: Uint8Array, padding: number): number;
|
|
35
|
-
//# sourceMappingURL=_common32.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_common32.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/encoding/1.0.10/_common32.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,eAAO,MAAM,OAAO,QAAoB,CAAC;AACzC,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIvD,CAAC;AACF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,UAAU,CAIxD,CAAC;AAQF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAExE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAmER;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,CAyFR"}
|