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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { joinGlobs as posixJoinGlobs } from "./posix/join_globs.js";
|
|
5
5
|
import { joinGlobs as windowsJoinGlobs } from "./windows/join_globs.js";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { normalize as posixNormalize } from "./posix/normalize.js";
|
|
5
5
|
import { normalize as windowsNormalize } from "./windows/normalize.js";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { normalizeGlob as posixNormalizeGlob } from "./posix/normalize_glob.js";
|
|
5
5
|
import { normalizeGlob as windowsNormalizeGlob, } from "./windows/normalize_glob.js";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { parse as posixParse } from "./posix/parse.js";
|
|
5
5
|
import { parse as windowsParse } from "./windows/parse.js";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { relative as posixRelative } from "./posix/relative.js";
|
|
5
5
|
import { relative as windowsRelative } from "./windows/relative.js";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { resolve as posixResolve } from "./posix/resolve.js";
|
|
5
5
|
import { resolve as windowsResolve } from "./windows/resolve.js";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { toFileUrl as posixToFileUrl } from "./posix/to_file_url.js";
|
|
5
5
|
import { toFileUrl as windowsToFileUrl } from "./windows/to_file_url.js";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
import { isWindows } from "../../internal/1.0.
|
|
3
|
+
import { isWindows } from "../../internal/1.0.13/os.js";
|
|
4
4
|
import { toNamespacedPath as posixToNamespacedPath } from "./posix/to_namespaced_path.js";
|
|
5
5
|
import { toNamespacedPath as windowsToNamespacedPath } from "./windows/to_namespaced_path.js";
|
|
6
6
|
/**
|
package/esm/src/contants.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Provider } from './types.js';
|
|
2
2
|
export declare const DEFAULT_PROVIDER: Provider;
|
|
3
3
|
export declare const DEFAULT_MODELS: Record<Provider, string>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const DEFAULT_MAX_BATCH_BYTES: 12000;
|
|
5
5
|
export declare const MAX_RETRIES: 3;
|
|
6
6
|
export declare const BASE_RETRY_DELAY_MS: 2000;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const INTER_BATCH_DELAY_MS: 1500;
|
|
8
8
|
export declare const HELP_TEXT: string;
|
|
9
|
-
export declare const TEMP_DIR = "./tmp/";
|
|
10
9
|
//# sourceMappingURL=contants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contants.d.ts","sourceRoot":"","sources":["../../src/src/contants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,gBAAgB,EAAE,QAAmB,CAAC;AAEnD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAInD,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAG,KAAe,CAAC;AAEvD,eAAO,MAAM,WAAW,EAAG,CAAU,CAAC;AAEtC,eAAO,MAAM,mBAAmB,EAAG,IAAc,CAAC;AAElD,eAAO,MAAM,oBAAoB,EAAG,IAAc,CAAC;AAEnD,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"contants.d.ts","sourceRoot":"","sources":["../../src/src/contants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,gBAAgB,EAAE,QAAmB,CAAC;AAEnD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAInD,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAG,KAAe,CAAC;AAEvD,eAAO,MAAM,WAAW,EAAG,CAAU,CAAC;AAEtC,eAAO,MAAM,mBAAmB,EAAG,IAAc,CAAC;AAElD,eAAO,MAAM,oBAAoB,EAAG,IAAc,CAAC;AAEnD,eAAO,MAAM,SAAS,QAgCrB,CAAC"}
|
package/esm/src/contants.js
CHANGED
|
@@ -4,31 +4,40 @@ export const DEFAULT_MODELS = {
|
|
|
4
4
|
openai: 'gpt-4.1-mini',
|
|
5
5
|
anthropic: 'claude-3-5-haiku-latest',
|
|
6
6
|
};
|
|
7
|
-
export const
|
|
7
|
+
export const DEFAULT_MAX_BATCH_BYTES = 12_000;
|
|
8
8
|
export const MAX_RETRIES = 3;
|
|
9
9
|
export const BASE_RETRY_DELAY_MS = 2_000;
|
|
10
|
-
export const
|
|
10
|
+
export const INTER_BATCH_DELAY_MS = 1_500;
|
|
11
11
|
export const HELP_TEXT = `
|
|
12
12
|
Glotto AI Translator
|
|
13
13
|
-------------------
|
|
14
14
|
A tool for translating i18n JSON files using AI services.
|
|
15
15
|
|
|
16
|
+
Glotto walks the input JSON, extracts every string leaf with its path, sends them to the
|
|
17
|
+
chosen provider as plain-text batches (using ≪id≫value≪/id≫ tagged entries), and
|
|
18
|
+
reconstructs the JSON from the responses. JSON structure, keys, variables and HTML tags
|
|
19
|
+
are preserved by the tool itself — the model only sees and produces text.
|
|
20
|
+
|
|
16
21
|
Options:
|
|
17
|
-
--key
|
|
18
|
-
-p, --provider
|
|
19
|
-
-m, --model
|
|
20
|
-
-i, --input
|
|
21
|
-
-o, --output
|
|
22
|
-
-f, --from
|
|
23
|
-
-t, --to
|
|
24
|
-
--url
|
|
25
|
-
-
|
|
26
|
-
-
|
|
22
|
+
--key API key for the AI service (required)
|
|
23
|
+
-p, --provider AI translation provider to use (default: ${DEFAULT_PROVIDER})
|
|
24
|
+
-m, --model Model name for the selected provider (optional)
|
|
25
|
+
-i, --input Path to source JSON file (required)
|
|
26
|
+
-o, --output Path to target JSON file (required)
|
|
27
|
+
-f, --from Source language (required)
|
|
28
|
+
-t, --to Target language (required)
|
|
29
|
+
--url Custom base URL for OpenAI/Anthropic (optional)
|
|
30
|
+
--no-limit Disable rate limit delay between batches
|
|
31
|
+
--no-timeout Disable request timeout (wait indefinitely for AI response)
|
|
32
|
+
--max-batch-size Maximum source size per batch, in KB (default: ${DEFAULT_MAX_BATCH_BYTES / 1024} KB)
|
|
33
|
+
-h, --help Display this help message
|
|
34
|
+
-v, --version Display version
|
|
27
35
|
|
|
28
36
|
Examples:
|
|
29
37
|
glotto --key {{key}} --input=en.json --output=tr.json --from=english --to=turkish
|
|
30
38
|
glotto --key {{key}} -i en.json -o tr.json -f english -t turkish -p gemini
|
|
31
39
|
glotto --key {{key}} -i en.json -o tr.json -f english -t turkish -p openai
|
|
32
40
|
glotto --key {{key}} -i en.json -o tr.json -f english -t turkish -p anthropic
|
|
41
|
+
glotto --key {{key}} -i en.json -o tr.json -f english -t turkish --no-limit --no-timeout
|
|
42
|
+
glotto --key {{key}} -i en.json -o tr.json -f english -t turkish --max-batch-size 8
|
|
33
43
|
`;
|
|
34
|
-
export const TEMP_DIR = './tmp/';
|
package/esm/src/file.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JsonValue } from './types.js';
|
|
2
2
|
export declare const resolvePath: (...paths: string[]) => string;
|
|
3
|
-
export declare const getImportJson: <T =
|
|
3
|
+
export declare const getImportJson: <T = JsonValue>(input: string) => Promise<T>;
|
|
4
4
|
export declare const writeOutput: (outputPath: string, content: string) => Promise<void>;
|
|
5
|
-
export declare const existsFile: (path: string) => Promise<boolean>;
|
|
6
|
-
export declare const ensureDirectoryExists: (directory: string) => Promise<void>;
|
|
7
|
-
export declare const splitJson: (data: JsonObject, maxChunkBytes?: number) => ChunkInfo[];
|
|
8
|
-
export declare const mergeInputs: (inputs: JsonObject[]) => JsonObject;
|
|
9
|
-
export declare const writeTemp: (tempJsonFileName: string, content: string) => Promise<void>;
|
|
10
5
|
//# sourceMappingURL=file.d.ts.map
|
package/esm/src/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/src/file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/src/file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,eAAO,MAAM,WAAW,GAAI,GAAG,OAAO,MAAM,EAAE,KAAG,MAA4C,CAAC;AAE9F,eAAO,MAAM,aAAa,GAAU,CAAC,GAAG,SAAS,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,CAO3E,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,YAAY,MAAM,EAAE,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAEnF,CAAC"}
|
package/esm/src/file.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as dntShim from "../_dnt.shims.js";
|
|
2
2
|
import { join } from '../deps/jsr.io/@std/path/1.1.4/mod.js';
|
|
3
|
-
|
|
4
|
-
export const resolvePath = (...paths) => {
|
|
5
|
-
return join(dntShim.Deno.cwd(), ...paths);
|
|
6
|
-
};
|
|
3
|
+
export const resolvePath = (...paths) => join(dntShim.Deno.cwd(), ...paths);
|
|
7
4
|
export const getImportJson = async (input) => {
|
|
8
5
|
const filePath = resolvePath(input);
|
|
9
6
|
const fileContent = await dntShim.Deno.readTextFile(filePath);
|
|
@@ -15,92 +12,3 @@ export const getImportJson = async (input) => {
|
|
|
15
12
|
export const writeOutput = async (outputPath, content) => {
|
|
16
13
|
await dntShim.Deno.writeTextFile(outputPath, content, { create: true });
|
|
17
14
|
};
|
|
18
|
-
export const existsFile = async (path) => {
|
|
19
|
-
try {
|
|
20
|
-
await dntShim.Deno.stat(path);
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
if (error instanceof dntShim.Deno.errors.NotFound) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export const ensureDirectoryExists = async (directory) => {
|
|
31
|
-
const directoryExists = await existsFile(directory);
|
|
32
|
-
if (!directoryExists) {
|
|
33
|
-
await dntShim.Deno.mkdir(directory, { recursive: true });
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const getByteSize = (str) => {
|
|
37
|
-
return new TextEncoder().encode(str).byteLength;
|
|
38
|
-
};
|
|
39
|
-
const buildChunkWithSize = (data, keys) => {
|
|
40
|
-
const chunk = Object.create(null);
|
|
41
|
-
for (const key of keys) {
|
|
42
|
-
chunk[key] = data[key];
|
|
43
|
-
}
|
|
44
|
-
const json = JSON.stringify(chunk);
|
|
45
|
-
return { json, size: getByteSize(json) };
|
|
46
|
-
};
|
|
47
|
-
export const splitJson = (data, maxChunkBytes = 30_000) => {
|
|
48
|
-
const encoder = new TextEncoder();
|
|
49
|
-
const dataKeys = Object.keys(data);
|
|
50
|
-
const totalKeys = dataKeys.length;
|
|
51
|
-
const fullJson = JSON.stringify(data);
|
|
52
|
-
const totalBytes = getByteSize(fullJson);
|
|
53
|
-
if (totalBytes <= maxChunkBytes) {
|
|
54
|
-
return [
|
|
55
|
-
{
|
|
56
|
-
data: encoder.encode(fullJson),
|
|
57
|
-
keyCount: totalKeys,
|
|
58
|
-
byteSize: totalBytes,
|
|
59
|
-
index: 0,
|
|
60
|
-
},
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
const chunks = [];
|
|
64
|
-
let currentKeys = [];
|
|
65
|
-
let currentSize = 2;
|
|
66
|
-
for (let i = 0; i < totalKeys; i++) {
|
|
67
|
-
const key = dataKeys[i];
|
|
68
|
-
const keyValueJson = JSON.stringify({ [key]: data[key] });
|
|
69
|
-
const entrySize = getByteSize(keyValueJson) - 2;
|
|
70
|
-
const separatorSize = currentKeys.length > 0 ? 1 : 0;
|
|
71
|
-
const projectedSize = currentSize + entrySize + separatorSize;
|
|
72
|
-
if (projectedSize > maxChunkBytes && currentKeys.length > 0) {
|
|
73
|
-
const { json, size } = buildChunkWithSize(data, currentKeys);
|
|
74
|
-
chunks.push({
|
|
75
|
-
data: encoder.encode(json),
|
|
76
|
-
keyCount: currentKeys.length,
|
|
77
|
-
byteSize: size,
|
|
78
|
-
index: chunks.length,
|
|
79
|
-
});
|
|
80
|
-
currentKeys = [key];
|
|
81
|
-
currentSize = 2 + entrySize;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
currentKeys.push(key);
|
|
85
|
-
currentSize = projectedSize;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (currentKeys.length > 0) {
|
|
89
|
-
const { json, size } = buildChunkWithSize(data, currentKeys);
|
|
90
|
-
chunks.push({
|
|
91
|
-
data: encoder.encode(json),
|
|
92
|
-
keyCount: currentKeys.length,
|
|
93
|
-
byteSize: size,
|
|
94
|
-
index: chunks.length,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return chunks;
|
|
98
|
-
};
|
|
99
|
-
export const mergeInputs = (inputs) => {
|
|
100
|
-
return Object.assign({}, ...inputs);
|
|
101
|
-
};
|
|
102
|
-
export const writeTemp = async (tempJsonFileName, content) => {
|
|
103
|
-
await ensureDirectoryExists(TEMP_DIR);
|
|
104
|
-
const tempJsonFilePath = resolvePath(TEMP_DIR, tempJsonFileName);
|
|
105
|
-
await dntShim.Deno.writeTextFile(tempJsonFilePath, content, { create: true });
|
|
106
|
-
};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
client: Anthropic;
|
|
8
|
-
model: string;
|
|
9
|
-
constructor(key: string, chunks: ChunkInfo[], from: string, to: string, baseUrl?: string, modelName?: string);
|
|
10
|
-
private translateChunk;
|
|
11
|
-
translate(): Promise<string>;
|
|
1
|
+
import type { TextTranslator, TranslateOptions } from '../types.js';
|
|
2
|
+
declare class AnthropicModel implements TextTranslator {
|
|
3
|
+
private client;
|
|
4
|
+
private model;
|
|
5
|
+
constructor(key: string, baseUrl?: string, modelName?: string, options?: TranslateOptions);
|
|
6
|
+
translate(prompt: string): Promise<string>;
|
|
12
7
|
}
|
|
13
8
|
export default AnthropicModel;
|
|
14
9
|
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/src/providers/anthropic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/src/providers/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpE,cAAM,cAAe,YAAW,cAAc;IAC5C,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAAS;gBAGpB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE,gBAAuD;IAU5D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYjD;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
import {
|
|
3
|
-
import { logger } from '../logger.js';
|
|
4
|
-
import { mergeInputs, writeTemp } from '../file.js';
|
|
5
|
-
import { BASE_RETRY_DELAY_MS, DEFAULT_MODELS, INTER_CHUNK_DELAY_MS, MAX_RETRIES } from '../contants.js';
|
|
6
|
-
const decoder = new TextDecoder();
|
|
2
|
+
import { DEFAULT_MODELS } from '../contants.js';
|
|
7
3
|
class AnthropicModel {
|
|
8
|
-
constructor(key,
|
|
9
|
-
Object.defineProperty(this, "chunks", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: void 0
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "from", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: void 0
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "to", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
4
|
+
constructor(key, baseUrl, modelName, options = { noLimit: false, noTimeout: false }) {
|
|
27
5
|
Object.defineProperty(this, "client", {
|
|
28
6
|
enumerable: true,
|
|
29
7
|
configurable: true,
|
|
@@ -36,91 +14,24 @@ class AnthropicModel {
|
|
|
36
14
|
writable: true,
|
|
37
15
|
value: void 0
|
|
38
16
|
});
|
|
39
|
-
this.chunks = chunks;
|
|
40
|
-
this.from = from;
|
|
41
|
-
this.to = to;
|
|
42
17
|
this.model = modelName ?? DEFAULT_MODELS.anthropic;
|
|
43
18
|
this.client = new Anthropic({
|
|
44
19
|
apiKey: key,
|
|
45
20
|
baseURL: baseUrl,
|
|
21
|
+
timeout: options.noTimeout ? 0 : undefined,
|
|
46
22
|
});
|
|
47
23
|
}
|
|
48
|
-
async
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
model: this.model,
|
|
60
|
-
max_tokens: 4096,
|
|
61
|
-
messages: [
|
|
62
|
-
{
|
|
63
|
-
role: 'user',
|
|
64
|
-
content: `${systemPrompt}\n\n${userPrompt}\n\nSOURCE_JSON:\n${sourceJson}`,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
});
|
|
68
|
-
const textParts = message.content
|
|
69
|
-
.filter((part) => part.type === 'text')
|
|
70
|
-
.map((part) => part.text);
|
|
71
|
-
const text = textParts.join('').trim();
|
|
72
|
-
if (!text) {
|
|
73
|
-
logger.error(`${chunkLabel} Empty response from Anthropic`);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const tempJsonFileName = `${this.to}_chunk_${chunk.index + 1}.json`;
|
|
77
|
-
await writeTemp(tempJsonFileName, text);
|
|
78
|
-
if (!isValidJson(text)) {
|
|
79
|
-
logger.error(`${chunkLabel} Invalid JSON response, saved to ${tempJsonFileName}`);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
logger.info(`${chunkLabel} Translated successfully (${formatBytes(chunk.byteSize)}, ${chunk.keyCount} keys)`);
|
|
83
|
-
return text;
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
const isLastAttempt = attempt === MAX_RETRIES;
|
|
87
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
88
|
-
if (isLastAttempt) {
|
|
89
|
-
logger.error(`${chunkLabel} Failed after ${MAX_RETRIES + 1} attempts: ${errorMessage}`);
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
logger.warn(`${chunkLabel} Attempt ${attempt + 1} failed: ${errorMessage}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
async translate() {
|
|
98
|
-
const { systemPrompt, userPrompt } = generatePrompts(this.from, this.to);
|
|
99
|
-
const totalChunks = this.chunks.length;
|
|
100
|
-
logger.info(`Starting translation: ${totalChunks} chunk(s) to process`);
|
|
101
|
-
const results = [];
|
|
102
|
-
const failedChunks = [];
|
|
103
|
-
for (let i = 0; i < totalChunks; i++) {
|
|
104
|
-
const chunk = this.chunks[i];
|
|
105
|
-
if (i > 0) {
|
|
106
|
-
logger.info(`Waiting ${INTER_CHUNK_DELAY_MS}ms before next chunk (rate limit protection)...`);
|
|
107
|
-
await delay(INTER_CHUNK_DELAY_MS);
|
|
108
|
-
}
|
|
109
|
-
const result = await this.translateChunk(chunk, systemPrompt, userPrompt);
|
|
110
|
-
if (result) {
|
|
111
|
-
results.push(result);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
failedChunks.push(chunk.index + 1);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (failedChunks.length > 0) {
|
|
118
|
-
throw new Error(`Translation failed for chunk(s): ${failedChunks.join(', ')}. Check temp files for partial results.`);
|
|
119
|
-
}
|
|
120
|
-
logger.info(`All ${totalChunks} chunk(s) translated successfully, merging results...`);
|
|
121
|
-
const jsonInputs = results.map((r) => JSON.parse(r));
|
|
122
|
-
const mergedContent = mergeInputs(jsonInputs);
|
|
123
|
-
return JSON.stringify(mergedContent, null, 2);
|
|
24
|
+
async translate(prompt) {
|
|
25
|
+
const message = await this.client.messages.create({
|
|
26
|
+
model: this.model,
|
|
27
|
+
max_tokens: 8192,
|
|
28
|
+
temperature: 0.2,
|
|
29
|
+
messages: [{ role: 'user', content: prompt }],
|
|
30
|
+
});
|
|
31
|
+
return message.content
|
|
32
|
+
.filter((part) => part.type === 'text')
|
|
33
|
+
.map((part) => part.text)
|
|
34
|
+
.join('');
|
|
124
35
|
}
|
|
125
36
|
}
|
|
126
37
|
export default AnthropicModel;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
genAI: GoogleGenAI;
|
|
8
|
-
model: string;
|
|
9
|
-
constructor(key: string, chunks: ChunkInfo[], from: string, to: string, modelName?: string);
|
|
10
|
-
private translateChunk;
|
|
11
|
-
translate(): Promise<string>;
|
|
1
|
+
import type { TextTranslator, TranslateOptions } from '../types.js';
|
|
2
|
+
declare class Gemini implements TextTranslator {
|
|
3
|
+
private genAI;
|
|
4
|
+
private model;
|
|
5
|
+
constructor(key: string, modelName?: string, options?: TranslateOptions);
|
|
6
|
+
translate(prompt: string): Promise<string>;
|
|
12
7
|
}
|
|
13
8
|
export default Gemini;
|
|
14
9
|
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/src/providers/gemini.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/src/providers/gemini.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpE,cAAM,MAAO,YAAW,cAAc;IACpC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,KAAK,CAAS;gBAGpB,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE,gBAAuD;IAS5D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAWjD;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
import { GoogleGenAI } from '@google/genai';
|
|
2
|
-
import {
|
|
3
|
-
import { delay, formatBytes, generatePrompts, isValidJson } from '../utilites.js';
|
|
4
|
-
import { logger } from '../logger.js';
|
|
5
|
-
import { mergeInputs, writeTemp } from '../file.js';
|
|
6
|
-
import { BASE_RETRY_DELAY_MS, DEFAULT_MODELS, INTER_CHUNK_DELAY_MS, MAX_RETRIES } from '../contants.js';
|
|
2
|
+
import { DEFAULT_MODELS } from '../contants.js';
|
|
7
3
|
class Gemini {
|
|
8
|
-
constructor(key,
|
|
9
|
-
Object.defineProperty(this, "chunks", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: void 0
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "from", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: void 0
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "to", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
4
|
+
constructor(key, modelName, options = { noLimit: false, noTimeout: false }) {
|
|
27
5
|
Object.defineProperty(this, "genAI", {
|
|
28
6
|
enumerable: true,
|
|
29
7
|
configurable: true,
|
|
@@ -36,96 +14,22 @@ class Gemini {
|
|
|
36
14
|
writable: true,
|
|
37
15
|
value: void 0
|
|
38
16
|
});
|
|
39
|
-
this.chunks = chunks;
|
|
40
|
-
this.from = from;
|
|
41
|
-
this.to = to;
|
|
42
17
|
this.model = modelName ?? DEFAULT_MODELS.gemini;
|
|
43
18
|
this.genAI = new GoogleGenAI({
|
|
44
19
|
apiKey: key,
|
|
20
|
+
httpOptions: options.noTimeout ? { timeout: 2_147_483_647 } : undefined,
|
|
45
21
|
});
|
|
46
22
|
}
|
|
47
|
-
async
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const part = {
|
|
58
|
-
inlineData: {
|
|
59
|
-
data: fileBase64,
|
|
60
|
-
mimeType: 'text/plain',
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
const { text } = await this.genAI.models.generateContent({
|
|
64
|
-
model: this.model,
|
|
65
|
-
contents: [systemPrompt, userPrompt, part],
|
|
66
|
-
config: {
|
|
67
|
-
systemInstruction: systemPrompt,
|
|
68
|
-
candidateCount: 1,
|
|
69
|
-
responseMimeType: 'application/json',
|
|
70
|
-
responseLogprobs: false,
|
|
71
|
-
temperature: 0.3,
|
|
72
|
-
topP: 0.7,
|
|
73
|
-
topK: 20,
|
|
74
|
-
maxOutputTokens: Number.POSITIVE_INFINITY,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
if (!text) {
|
|
78
|
-
logger.error(`${chunkLabel} Empty response from Gemini AI`);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const tempJsonFileName = `${this.to}_chunk_${chunk.index + 1}.json`;
|
|
82
|
-
await writeTemp(tempJsonFileName, text);
|
|
83
|
-
if (!isValidJson(text)) {
|
|
84
|
-
logger.error(`${chunkLabel} Invalid JSON response, saved to ${tempJsonFileName}`);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
logger.info(`${chunkLabel} Translated successfully (${formatBytes(chunk.byteSize)}, ${chunk.keyCount} keys)`);
|
|
88
|
-
return text;
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
const isLastAttempt = attempt === MAX_RETRIES;
|
|
92
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
93
|
-
if (isLastAttempt) {
|
|
94
|
-
logger.error(`${chunkLabel} Failed after ${MAX_RETRIES + 1} attempts: ${errorMessage}`);
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
logger.warn(`${chunkLabel} Attempt ${attempt + 1} failed: ${errorMessage}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
async translate() {
|
|
103
|
-
const { systemPrompt, userPrompt } = generatePrompts(this.from, this.to);
|
|
104
|
-
const totalChunks = this.chunks.length;
|
|
105
|
-
logger.info(`Starting translation: ${totalChunks} chunk(s) to process`);
|
|
106
|
-
const results = [];
|
|
107
|
-
const failedChunks = [];
|
|
108
|
-
for (let i = 0; i < totalChunks; i++) {
|
|
109
|
-
const chunk = this.chunks[i];
|
|
110
|
-
if (i > 0) {
|
|
111
|
-
logger.info(`Waiting ${INTER_CHUNK_DELAY_MS}ms before next chunk (rate limit protection)...`);
|
|
112
|
-
await delay(INTER_CHUNK_DELAY_MS);
|
|
113
|
-
}
|
|
114
|
-
const result = await this.translateChunk(chunk, systemPrompt, userPrompt);
|
|
115
|
-
if (result) {
|
|
116
|
-
results.push(result);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
failedChunks.push(chunk.index + 1);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (failedChunks.length > 0) {
|
|
123
|
-
throw new Error(`Translation failed for chunk(s): ${failedChunks.join(', ')}. Check temp files for partial results.`);
|
|
124
|
-
}
|
|
125
|
-
logger.info(`All ${totalChunks} chunk(s) translated successfully, merging results...`);
|
|
126
|
-
const jsonInputs = results.map((r) => JSON.parse(r));
|
|
127
|
-
const mergedContent = mergeInputs(jsonInputs);
|
|
128
|
-
return JSON.stringify(mergedContent, null, 2);
|
|
23
|
+
async translate(prompt) {
|
|
24
|
+
const { text } = await this.genAI.models.generateContent({
|
|
25
|
+
model: this.model,
|
|
26
|
+
contents: prompt,
|
|
27
|
+
config: {
|
|
28
|
+
candidateCount: 1,
|
|
29
|
+
temperature: 0.2,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return text ?? '';
|
|
129
33
|
}
|
|
130
34
|
}
|
|
131
35
|
export default Gemini;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
client: OpenAI;
|
|
8
|
-
model: string;
|
|
9
|
-
constructor(key: string, chunks: ChunkInfo[], from: string, to: string, baseUrl?: string, modelName?: string);
|
|
10
|
-
private translateChunk;
|
|
11
|
-
translate(): Promise<string>;
|
|
1
|
+
import type { TextTranslator, TranslateOptions } from '../types.js';
|
|
2
|
+
declare class OpenAIModel implements TextTranslator {
|
|
3
|
+
private client;
|
|
4
|
+
private model;
|
|
5
|
+
constructor(key: string, baseUrl?: string, modelName?: string, options?: TranslateOptions);
|
|
6
|
+
translate(prompt: string): Promise<string>;
|
|
12
7
|
}
|
|
13
8
|
export default OpenAIModel;
|
|
14
9
|
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/src/providers/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/src/providers/openai.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpE,cAAM,WAAY,YAAW,cAAc;IACzC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;gBAGpB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,GAAE,gBAAuD;IAU5D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQjD;AAED,eAAe,WAAW,CAAC"}
|