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.
Files changed (230) hide show
  1. package/README.md +86 -55
  2. package/esm/cli.js +49 -41
  3. package/esm/deno.d.ts +1 -1
  4. package/esm/deno.js +7 -7
  5. package/esm/deps/jsr.io/@std/cli/1.0.29/_data.d.ts.map +1 -0
  6. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts.map +1 -1
  7. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts.map +1 -1
  8. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts.map +1 -1
  9. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.js +17 -3
  10. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts.map +1 -1
  11. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.js +1 -1
  12. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts.map +1 -1
  13. package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts.map +1 -1
  14. package/esm/deps/jsr.io/@std/internal/1.0.13/_os.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.js +1 -1
  16. package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.d.ts.map +1 -1
  17. package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.js +1 -1
  18. package/esm/deps/jsr.io/@std/path/1.1.4/basename.js +1 -1
  19. package/esm/deps/jsr.io/@std/path/1.1.4/constants.js +1 -1
  20. package/esm/deps/jsr.io/@std/path/1.1.4/dirname.js +1 -1
  21. package/esm/deps/jsr.io/@std/path/1.1.4/extname.js +1 -1
  22. package/esm/deps/jsr.io/@std/path/1.1.4/format.js +1 -1
  23. package/esm/deps/jsr.io/@std/path/1.1.4/from_file_url.js +1 -1
  24. package/esm/deps/jsr.io/@std/path/1.1.4/glob_to_regexp.js +1 -1
  25. package/esm/deps/jsr.io/@std/path/1.1.4/is_absolute.js +1 -1
  26. package/esm/deps/jsr.io/@std/path/1.1.4/join.js +1 -1
  27. package/esm/deps/jsr.io/@std/path/1.1.4/join_globs.js +1 -1
  28. package/esm/deps/jsr.io/@std/path/1.1.4/normalize.js +1 -1
  29. package/esm/deps/jsr.io/@std/path/1.1.4/normalize_glob.js +1 -1
  30. package/esm/deps/jsr.io/@std/path/1.1.4/parse.js +1 -1
  31. package/esm/deps/jsr.io/@std/path/1.1.4/relative.js +1 -1
  32. package/esm/deps/jsr.io/@std/path/1.1.4/resolve.js +1 -1
  33. package/esm/deps/jsr.io/@std/path/1.1.4/to_file_url.js +1 -1
  34. package/esm/deps/jsr.io/@std/path/1.1.4/to_namespaced_path.js +1 -1
  35. package/esm/src/contants.d.ts +2 -3
  36. package/esm/src/contants.d.ts.map +1 -1
  37. package/esm/src/contants.js +22 -13
  38. package/esm/src/file.d.ts +2 -7
  39. package/esm/src/file.d.ts.map +1 -1
  40. package/esm/src/file.js +1 -93
  41. package/esm/src/providers/anthropic.d.ts +6 -11
  42. package/esm/src/providers/anthropic.d.ts.map +1 -1
  43. package/esm/src/providers/anthropic.js +14 -103
  44. package/esm/src/providers/gemini.d.ts +6 -11
  45. package/esm/src/providers/gemini.d.ts.map +1 -1
  46. package/esm/src/providers/gemini.js +13 -109
  47. package/esm/src/providers/openai.d.ts +6 -11
  48. package/esm/src/providers/openai.d.ts.map +1 -1
  49. package/esm/src/providers/openai.js +10 -104
  50. package/esm/src/translator.d.ts +8 -0
  51. package/esm/src/translator.d.ts.map +1 -0
  52. package/esm/src/translator.js +200 -0
  53. package/esm/src/types.d.ts +28 -11
  54. package/esm/src/types.d.ts.map +1 -1
  55. package/esm/src/utilites.d.ts +1 -6
  56. package/esm/src/utilites.d.ts.map +1 -1
  57. package/esm/src/utilites.js +18 -77
  58. package/package.json +4 -4
  59. package/script/cli.js +47 -39
  60. package/script/deno.d.ts +1 -1
  61. package/script/deno.js +7 -7
  62. package/script/deps/jsr.io/@std/cli/1.0.29/_data.d.ts.map +1 -0
  63. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts.map +1 -1
  64. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts.map +1 -1
  65. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts.map +1 -1
  66. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.js +17 -3
  67. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts.map +1 -1
  68. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.js +1 -1
  69. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts.map +1 -1
  70. package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts.map +1 -1
  71. package/script/deps/jsr.io/@std/internal/1.0.13/_os.d.ts.map +1 -0
  72. package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.js +1 -1
  73. package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.d.ts.map +1 -1
  74. package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.js +1 -1
  75. package/script/deps/jsr.io/@std/path/1.1.4/basename.js +1 -1
  76. package/script/deps/jsr.io/@std/path/1.1.4/constants.js +1 -1
  77. package/script/deps/jsr.io/@std/path/1.1.4/dirname.js +1 -1
  78. package/script/deps/jsr.io/@std/path/1.1.4/extname.js +1 -1
  79. package/script/deps/jsr.io/@std/path/1.1.4/format.js +1 -1
  80. package/script/deps/jsr.io/@std/path/1.1.4/from_file_url.js +1 -1
  81. package/script/deps/jsr.io/@std/path/1.1.4/glob_to_regexp.js +1 -1
  82. package/script/deps/jsr.io/@std/path/1.1.4/is_absolute.js +1 -1
  83. package/script/deps/jsr.io/@std/path/1.1.4/join.js +1 -1
  84. package/script/deps/jsr.io/@std/path/1.1.4/join_globs.js +1 -1
  85. package/script/deps/jsr.io/@std/path/1.1.4/normalize.js +1 -1
  86. package/script/deps/jsr.io/@std/path/1.1.4/normalize_glob.js +1 -1
  87. package/script/deps/jsr.io/@std/path/1.1.4/parse.js +1 -1
  88. package/script/deps/jsr.io/@std/path/1.1.4/relative.js +1 -1
  89. package/script/deps/jsr.io/@std/path/1.1.4/resolve.js +1 -1
  90. package/script/deps/jsr.io/@std/path/1.1.4/to_file_url.js +1 -1
  91. package/script/deps/jsr.io/@std/path/1.1.4/to_namespaced_path.js +1 -1
  92. package/script/src/contants.d.ts +2 -3
  93. package/script/src/contants.d.ts.map +1 -1
  94. package/script/src/contants.js +23 -14
  95. package/script/src/file.d.ts +2 -7
  96. package/script/src/file.d.ts.map +1 -1
  97. package/script/src/file.js +2 -99
  98. package/script/src/providers/anthropic.d.ts +6 -11
  99. package/script/src/providers/anthropic.d.ts.map +1 -1
  100. package/script/src/providers/anthropic.js +13 -102
  101. package/script/src/providers/gemini.d.ts +6 -11
  102. package/script/src/providers/gemini.d.ts.map +1 -1
  103. package/script/src/providers/gemini.js +12 -108
  104. package/script/src/providers/openai.d.ts +6 -11
  105. package/script/src/providers/openai.d.ts.map +1 -1
  106. package/script/src/providers/openai.js +9 -103
  107. package/script/src/translator.d.ts +8 -0
  108. package/script/src/translator.d.ts.map +1 -0
  109. package/script/src/translator.js +209 -0
  110. package/script/src/types.d.ts +28 -11
  111. package/script/src/types.d.ts.map +1 -1
  112. package/script/src/utilites.d.ts +1 -6
  113. package/script/src/utilites.d.ts.map +1 -1
  114. package/script/src/utilites.js +19 -80
  115. package/esm/deps/jsr.io/@std/cli/1.0.27/_data.d.ts.map +0 -1
  116. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  117. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  118. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
  119. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
  120. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
  121. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -192
  122. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
  123. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
  124. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -113
  125. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  126. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  127. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
  128. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  129. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  130. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
  131. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
  132. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
  133. package/esm/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -26
  134. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
  135. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
  136. package/esm/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -152
  137. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
  138. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
  139. package/esm/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -87
  140. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
  141. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
  142. package/esm/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -131
  143. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
  144. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
  145. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -82
  146. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
  147. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
  148. package/esm/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -72
  149. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  150. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  151. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
  152. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
  153. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
  154. package/esm/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -99
  155. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
  156. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
  157. package/esm/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -205
  158. package/esm/deps/jsr.io/@std/internal/1.0.12/_os.d.ts.map +0 -1
  159. package/script/deps/jsr.io/@std/cli/1.0.27/_data.d.ts.map +0 -1
  160. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  161. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  162. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -57
  163. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts +0 -35
  164. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.d.ts.map +0 -1
  165. package/script/deps/jsr.io/@std/encoding/1.0.10/_common32.js +0 -198
  166. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
  167. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
  168. package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -119
  169. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  170. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  171. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -16
  172. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  173. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  174. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -3
  175. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts +0 -2
  176. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.d.ts.map +0 -1
  177. package/script/deps/jsr.io/@std/encoding/1.0.10/_validate_binary_like.js +0 -29
  178. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts +0 -61
  179. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.d.ts.map +0 -1
  180. package/script/deps/jsr.io/@std/encoding/1.0.10/ascii85.js +0 -156
  181. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts +0 -40
  182. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.d.ts.map +0 -1
  183. package/script/deps/jsr.io/@std/encoding/1.0.10/base32.js +0 -91
  184. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts +0 -40
  185. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.d.ts.map +0 -1
  186. package/script/deps/jsr.io/@std/encoding/1.0.10/base58.js +0 -135
  187. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
  188. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
  189. package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -86
  190. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts +0 -40
  191. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.d.ts.map +0 -1
  192. package/script/deps/jsr.io/@std/encoding/1.0.10/base64url.js +0 -76
  193. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  194. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  195. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -91
  196. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts +0 -98
  197. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.d.ts.map +0 -1
  198. package/script/deps/jsr.io/@std/encoding/1.0.10/mod.js +0 -115
  199. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts +0 -120
  200. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.d.ts.map +0 -1
  201. package/script/deps/jsr.io/@std/encoding/1.0.10/varint.js +0 -211
  202. package/script/deps/jsr.io/@std/internal/1.0.12/_os.d.ts.map +0 -1
  203. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.d.ts +0 -0
  204. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.js +0 -0
  205. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts +0 -0
  206. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.js +0 -0
  207. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts +0 -0
  208. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.js +0 -0
  209. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts +0 -0
  210. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts +0 -0
  211. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts +0 -0
  212. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.js +0 -0
  213. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts +0 -0
  214. /package/esm/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.js +0 -0
  215. /package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.d.ts +0 -0
  216. /package/esm/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/os.d.ts +0 -0
  217. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.d.ts +0 -0
  218. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_data.js +0 -0
  219. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.d.ts +0 -0
  220. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/_run_length.js +0 -0
  221. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.d.ts +0 -0
  222. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/mod.js +0 -0
  223. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/parse_args.d.ts +0 -0
  224. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/prompt_secret.d.ts +0 -0
  225. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.d.ts +0 -0
  226. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unicode_width.js +0 -0
  227. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.d.ts +0 -0
  228. /package/script/deps/jsr.io/@std/cli/{1.0.27 → 1.0.29}/unstable_spinner.js +0 -0
  229. /package/script/deps/jsr.io/@std/internal/{1.0.12 → 1.0.13}/_os.d.ts +0 -0
  230. /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.12/os.js";
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.12/os.js";
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.12/os.js";
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.12/os.js";
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.12/os.js";
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.12/os.js";
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.12/os.js";
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.12/os.js";
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
  /**
@@ -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 DEFAULT_MAX_CHUNK_BYTES: 30000;
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 INTER_CHUNK_DELAY_MS: 1500;
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,QAsBrB,CAAC;AAEF,eAAO,MAAM,QAAQ,WAAW,CAAC"}
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"}
@@ -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 DEFAULT_MAX_CHUNK_BYTES = 30_000;
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 INTER_CHUNK_DELAY_MS = 1_500;
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 API key for the AI service (required)
18
- -p, --provider AI translation provider to use (default: ${DEFAULT_PROVIDER})
19
- -m, --model Model name for the selected provider (optional)
20
- -i, --input Path to source JSON file (required)
21
- -o, --output Path to target JSON file (required)
22
- -f, --from Source language (required)
23
- -t, --to Target language (required)
24
- --url Custom base URL for OpenAI/Anthropic (optional)
25
- -h, --help Display this help message
26
- -v, --version Display version
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 { ChunkInfo, JsonObject } from './types.js';
1
+ import type { JsonValue } from './types.js';
2
2
  export declare const resolvePath: (...paths: string[]) => string;
3
- export declare const getImportJson: <T = JsonObject>(input: string) => Promise<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
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/src/file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAS,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG/D,eAAO,MAAM,WAAW,GAAI,GAAG,OAAO,MAAM,EAAE,WAE7C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,CAAC,GAAG,UAAU,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,CAS5E,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,YAAY,MAAM,EAAE,SAAS,MAAM,kBAEpE,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,MAAM,MAAM,qBAW5C,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,IAAI,CAK3E,CAAC;AAeF,eAAO,MAAM,SAAS,GAAI,MAAM,UAAU,EAAE,gBAAe,MAAe,KAAG,SAAS,EA4DrF,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,QAAQ,UAAU,EAAE,KAAG,UAElD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAU,kBAAkB,MAAM,EAAE,SAAS,MAAM,kBAIxE,CAAC"}
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
- import { TEMP_DIR } from './contants.js';
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 Anthropic from '@anthropic-ai/sdk';
2
- import type { ChunkInfo, Translatable } from '../types.js';
3
- declare class AnthropicModel implements Translatable {
4
- chunks: ChunkInfo[];
5
- from: string;
6
- to: string;
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":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAc,YAAY,EAAE,MAAM,aAAa,CAAC;AAQvE,cAAM,cAAe,YAAW,YAAY;IAC1C,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;gBAEF,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;YAW9F,cAAc;IA4DtB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;CAqCnC;AAED,eAAe,cAAc,CAAC"}
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 { delay, formatBytes, generatePrompts, isValidJson } from '../utilites.js';
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, chunks, from, to, baseUrl, modelName) {
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 translateChunk(chunk, systemPrompt, userPrompt) {
49
- const chunkLabel = `[Chunk ${chunk.index + 1}/${this.chunks.length}]`;
50
- const sourceJson = decoder.decode(chunk.data);
51
- for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
52
- try {
53
- if (attempt > 0) {
54
- const backoffMs = BASE_RETRY_DELAY_MS * Math.pow(2, attempt - 1);
55
- logger.warn(`${chunkLabel} Retry ${attempt}/${MAX_RETRIES} after ${backoffMs}ms backoff...`);
56
- await delay(backoffMs);
57
- }
58
- const message = await this.client.messages.create({
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 { GoogleGenAI } from '@google/genai';
2
- import type { ChunkInfo, Translatable } from '../types.js';
3
- declare class Gemini implements Translatable {
4
- chunks: ChunkInfo[];
5
- from: string;
6
- to: string;
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":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAc,YAAY,EAAE,MAAM,aAAa,CAAC;AAMvE,cAAM,MAAO,YAAW,YAAY;IAClC,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;gBAEF,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;YAU5E,cAAc;IAkEtB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;CAqCnC;AAED,eAAe,MAAM,CAAC"}
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 { encodeBase64 } from '../../deps/jsr.io/@std/encoding/1.0.10/mod.js';
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, chunks, from, to, modelName) {
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 translateChunk(chunk, systemPrompt, userPrompt) {
48
- const chunkLabel = `[Chunk ${chunk.index + 1}/${this.chunks.length}]`;
49
- for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
50
- try {
51
- if (attempt > 0) {
52
- const backoffMs = BASE_RETRY_DELAY_MS * Math.pow(2, attempt - 1);
53
- logger.warn(`${chunkLabel} Retry ${attempt}/${MAX_RETRIES} after ${backoffMs}ms backoff...`);
54
- await delay(backoffMs);
55
- }
56
- const fileBase64 = encodeBase64(chunk.data);
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 OpenAI from 'openai';
2
- import type { ChunkInfo, Translatable } from '../types.js';
3
- declare class OpenAIModel implements Translatable {
4
- chunks: ChunkInfo[];
5
- from: string;
6
- to: string;
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":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAc,YAAY,EAAE,MAAM,aAAa,CAAC;AAQvE,cAAM,WAAY,YAAW,YAAY;IACvC,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;gBAEF,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;YAW9F,cAAc;IA4DtB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;CAqCnC;AAED,eAAe,WAAW,CAAC"}
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"}