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,29 +1,7 @@
1
1
  import OpenAI from 'openai';
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 OpenAIModel {
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,92 +14,20 @@ class OpenAIModel {
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.openai;
43
18
  this.client = new OpenAI({
44
19
  apiKey: key,
45
20
  baseURL: baseUrl,
21
+ timeout: options.noTimeout ? 2_147_483_647 : 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 response = await this.client.responses.create({
59
- model: this.model,
60
- input: [
61
- {
62
- role: 'user',
63
- content: [
64
- {
65
- type: 'input_text',
66
- text: `${systemPrompt}\n\n${userPrompt}\n\nSOURCE_JSON:\n${sourceJson}`,
67
- },
68
- ],
69
- },
70
- ],
71
- });
72
- const text = response.output_text;
73
- if (!text) {
74
- logger.error(`${chunkLabel} Empty response from OpenAI`);
75
- continue;
76
- }
77
- const tempJsonFileName = `${this.to}_chunk_${chunk.index + 1}.json`;
78
- await writeTemp(tempJsonFileName, text);
79
- if (!isValidJson(text)) {
80
- logger.error(`${chunkLabel} Invalid JSON response, saved to ${tempJsonFileName}`);
81
- continue;
82
- }
83
- logger.info(`${chunkLabel} Translated successfully (${formatBytes(chunk.byteSize)}, ${chunk.keyCount} keys)`);
84
- return text;
85
- }
86
- catch (error) {
87
- const isLastAttempt = attempt === MAX_RETRIES;
88
- const errorMessage = error instanceof Error ? error.message : String(error);
89
- if (isLastAttempt) {
90
- logger.error(`${chunkLabel} Failed after ${MAX_RETRIES + 1} attempts: ${errorMessage}`);
91
- return null;
92
- }
93
- logger.warn(`${chunkLabel} Attempt ${attempt + 1} failed: ${errorMessage}`);
94
- }
95
- }
96
- return null;
97
- }
98
- async translate() {
99
- const { systemPrompt, userPrompt } = generatePrompts(this.from, this.to);
100
- const totalChunks = this.chunks.length;
101
- logger.info(`Starting translation: ${totalChunks} chunk(s) to process`);
102
- const results = [];
103
- const failedChunks = [];
104
- for (let i = 0; i < totalChunks; i++) {
105
- const chunk = this.chunks[i];
106
- if (i > 0) {
107
- logger.info(`Waiting ${INTER_CHUNK_DELAY_MS}ms before next chunk (rate limit protection)...`);
108
- await delay(INTER_CHUNK_DELAY_MS);
109
- }
110
- const result = await this.translateChunk(chunk, systemPrompt, userPrompt);
111
- if (result) {
112
- results.push(result);
113
- }
114
- else {
115
- failedChunks.push(chunk.index + 1);
116
- }
117
- }
118
- if (failedChunks.length > 0) {
119
- throw new Error(`Translation failed for chunk(s): ${failedChunks.join(', ')}. Check temp files for partial results.`);
120
- }
121
- logger.info(`All ${totalChunks} chunk(s) translated successfully, merging results...`);
122
- const jsonInputs = results.map((r) => JSON.parse(r));
123
- const mergedContent = mergeInputs(jsonInputs);
124
- return JSON.stringify(mergedContent, null, 2);
24
+ async translate(prompt) {
25
+ const completion = await this.client.chat.completions.create({
26
+ model: this.model,
27
+ messages: [{ role: 'user', content: prompt }],
28
+ temperature: 0.2,
29
+ });
30
+ return completion.choices[0]?.message?.content ?? '';
125
31
  }
126
32
  }
127
33
  export default OpenAIModel;
@@ -0,0 +1,8 @@
1
+ import type { Batch, JsonValue, Leaf, TextTranslator, TranslateOptions } from './types.js';
2
+ export declare const extractLeaves: (data: JsonValue) => Leaf[];
3
+ export declare const groupIntoBatches: (leaves: Leaf[], maxBytes: number) => Batch[];
4
+ export declare const buildBatchPrompt: (from: string, to: string, leaves: Leaf[]) => string;
5
+ export declare const decodeResponse: (text: string) => Map<number, string>;
6
+ export declare const reconstruct: (allLeaves: Leaf[], translations: Map<number, string>) => JsonValue;
7
+ export declare const runBatches: (batches: Batch[], translator: TextTranslator, from: string, to: string, options: TranslateOptions) => Promise<Map<number, string>>;
8
+ //# sourceMappingURL=translator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translator.d.ts","sourceRoot":"","sources":["../../src/src/translator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAQ,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAQjG,eAAO,MAAM,aAAa,GAAI,MAAM,SAAS,KAAG,IAAI,EAiCnD,CAAC;AAQF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,IAAI,EAAE,EAAE,UAAU,MAAM,KAAG,KAAK,EA0BxE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,IAAI,MAAM,EAAE,QAAQ,IAAI,EAAE,KAAG,MAkB3E,CAAC;AAQF,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAS/D,CAAC;AAgBF,eAAO,MAAM,WAAW,GAAI,WAAW,IAAI,EAAE,EAAE,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,SAalF,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,SAAS,KAAK,EAAE,EAChB,YAAY,cAAc,EAC1B,MAAM,MAAM,EACZ,IAAI,MAAM,EACV,SAAS,gBAAgB,KACxB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgF7B,CAAC"}
@@ -0,0 +1,200 @@
1
+ import { logger } from './logger.js';
2
+ import { delay, formatBytes } from './utilites.js';
3
+ import { BASE_RETRY_DELAY_MS, INTER_BATCH_DELAY_MS, MAX_RETRIES } from './contants.js';
4
+ const encoder = new TextEncoder();
5
+ const byteSize = (s) => encoder.encode(s).byteLength;
6
+ export const extractLeaves = (data) => {
7
+ const out = [];
8
+ let nextId = 0;
9
+ const walk = (node, path) => {
10
+ if (node === null || typeof node !== 'object') {
11
+ const isString = typeof node === 'string';
12
+ out.push({
13
+ id: ++nextId,
14
+ path,
15
+ value: node,
16
+ translatable: isString && node.trim().length > 0,
17
+ });
18
+ return;
19
+ }
20
+ if (Array.isArray(node)) {
21
+ if (node.length === 0) {
22
+ out.push({ id: ++nextId, path, value: node, translatable: false });
23
+ return;
24
+ }
25
+ node.forEach((item, i) => walk(item, [...path, i]));
26
+ return;
27
+ }
28
+ const entries = Object.entries(node);
29
+ if (entries.length === 0) {
30
+ out.push({ id: ++nextId, path, value: node, translatable: false });
31
+ return;
32
+ }
33
+ for (const [k, v] of entries)
34
+ walk(v, [...path, k]);
35
+ };
36
+ walk(data, []);
37
+ return out;
38
+ };
39
+ const TAG_OPEN = (id) => `≪${id}≫`;
40
+ const TAG_CLOSE = (id) => `≪/${id}≫`;
41
+ const TAG_OVERHEAD_CHARS = 8;
42
+ const wrapEntry = (leaf) => `${TAG_OPEN(leaf.id)}${String(leaf.value)}${TAG_CLOSE(leaf.id)}`;
43
+ export const groupIntoBatches = (leaves, maxBytes) => {
44
+ const translatable = leaves.filter((l) => l.translatable);
45
+ const batches = [];
46
+ let current = [];
47
+ let currentSize = 0;
48
+ for (const leaf of translatable) {
49
+ const valueBytes = byteSize(String(leaf.value));
50
+ const idChars = String(leaf.id).length;
51
+ const overhead = TAG_OVERHEAD_CHARS + idChars * 2 + 1;
52
+ const itemSize = valueBytes + overhead;
53
+ if (current.length > 0 && currentSize + itemSize > maxBytes) {
54
+ batches.push({ index: batches.length, leaves: current, byteSize: currentSize });
55
+ current = [];
56
+ currentSize = 0;
57
+ }
58
+ current.push(leaf);
59
+ currentSize += itemSize;
60
+ }
61
+ if (current.length > 0) {
62
+ batches.push({ index: batches.length, leaves: current, byteSize: currentSize });
63
+ }
64
+ return batches;
65
+ };
66
+ export const buildBatchPrompt = (from, to, leaves) => {
67
+ const entries = leaves.map(wrapEntry).join('\n');
68
+ return `Translate each tagged entry below from ${from} to ${to}.
69
+
70
+ Tag format:
71
+ - Every entry is wrapped exactly as ≪N≫value≪/N≫, where N is the entry id (a positive integer).
72
+ - The opening marker is the character ≪ (U+226A), then the id, then ≫ (U+226B). The closing marker is ≪, /, the same id, then ≫.
73
+ - Copy these markers verbatim. Do not put spaces inside them. Do not change them to <<>>, «», <tag>, [n], or any other notation.
74
+ - The id must match the input id of the same entry — never renumber, merge, split, or reorder entries.
75
+
76
+ What to write back:
77
+ - One ≪N≫translated_value≪/N≫ block per input entry, in the same order, separated by single newlines.
78
+ - Translate only the text that sits between ≪N≫ and ≪/N≫.
79
+ - Preserve every variable ({{name}}, {name}, __VAR__, $t(...), %s, %d), HTML tag, markdown token, escape sequence, and special character inside the value.
80
+ - Output nothing else: no headings, no prose, no commentary, no code fences, no language labels.
81
+
82
+ Now translate the following entries:
83
+ ${entries}`;
84
+ };
85
+ const TAG_PATTERNS = [
86
+ /≪\s*(\d+)\s*≫([\s\S]*?)≪\s*\/\s*\1\s*≫/g,
87
+ /<<\s*(\d+)\s*>>([\s\S]*?)<<\s*\/\s*\1\s*>>/g,
88
+ /«\s*(\d+)\s*»([\s\S]*?)«\s*\/\s*\1\s*»/g,
89
+ ];
90
+ export const decodeResponse = (text) => {
91
+ const map = new Map();
92
+ for (const pattern of TAG_PATTERNS) {
93
+ for (const match of text.matchAll(pattern)) {
94
+ const id = parseInt(match[1], 10);
95
+ if (!map.has(id))
96
+ map.set(id, match[2].trim());
97
+ }
98
+ }
99
+ return map;
100
+ };
101
+ const setPath = (root, path, value) => {
102
+ let node = root;
103
+ for (let i = 0; i < path.length - 1; i++) {
104
+ const key = path[i];
105
+ const nextKey = path[i + 1];
106
+ const container = node;
107
+ if (container[key] === undefined) {
108
+ container[key] = typeof nextKey === 'number' ? [] : {};
109
+ }
110
+ node = container[key];
111
+ }
112
+ node[path[path.length - 1]] = value;
113
+ };
114
+ export const reconstruct = (allLeaves, translations) => {
115
+ if (allLeaves.length === 0)
116
+ return {};
117
+ const firstStep = allLeaves[0].path[0];
118
+ if (firstStep === undefined) {
119
+ const only = allLeaves[0];
120
+ return only.translatable ? translations.get(only.id) ?? only.value : only.value;
121
+ }
122
+ const root = typeof firstStep === 'number' ? [] : {};
123
+ for (const leaf of allLeaves) {
124
+ const value = leaf.translatable && translations.has(leaf.id) ? translations.get(leaf.id) : leaf.value;
125
+ setPath(root, leaf.path, value);
126
+ }
127
+ return root;
128
+ };
129
+ export const runBatches = async (batches, translator, from, to, options) => {
130
+ const translations = new Map();
131
+ const failedIds = [];
132
+ for (let i = 0; i < batches.length; i++) {
133
+ const batch = batches[i];
134
+ const label = `[Batch ${batch.index + 1}/${batches.length}]`;
135
+ if (i > 0 && !options.noLimit) {
136
+ logger.info(`Waiting ${INTER_BATCH_DELAY_MS}ms before next batch (rate limit protection)...`);
137
+ await delay(INTER_BATCH_DELAY_MS);
138
+ }
139
+ let remaining = [...batch.leaves];
140
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
141
+ if (attempt > 0) {
142
+ const backoffMs = BASE_RETRY_DELAY_MS * Math.pow(2, attempt - 1);
143
+ logger.warn(`${label} Retry ${attempt}/${MAX_RETRIES} after ${backoffMs}ms backoff (${remaining.length} entries)...`);
144
+ await delay(backoffMs);
145
+ }
146
+ try {
147
+ const prompt = buildBatchPrompt(from, to, remaining);
148
+ const response = await translator.translate(prompt);
149
+ if (!response || response.trim().length === 0) {
150
+ if (attempt === MAX_RETRIES) {
151
+ logger.error(`${label} Failed after ${MAX_RETRIES + 1} attempts: empty response`);
152
+ for (const leaf of remaining)
153
+ failedIds.push(leaf.id);
154
+ break;
155
+ }
156
+ logger.warn(`${label} Attempt ${attempt + 1} returned empty response`);
157
+ continue;
158
+ }
159
+ const decoded = decodeResponse(response);
160
+ const stillMissing = [];
161
+ for (const leaf of remaining) {
162
+ const value = decoded.get(leaf.id);
163
+ if (!value || value.trim().length === 0) {
164
+ stillMissing.push(leaf);
165
+ continue;
166
+ }
167
+ translations.set(leaf.id, value);
168
+ }
169
+ if (stillMissing.length === 0) {
170
+ logger.info(`${label} Translated successfully (${formatBytes(batch.byteSize)}, ${batch.leaves.length} entries)`);
171
+ break;
172
+ }
173
+ if (attempt === MAX_RETRIES) {
174
+ logger.error(`${label} Failed after ${MAX_RETRIES + 1} attempts: ${stillMissing.length} entries missing`);
175
+ for (const leaf of stillMissing)
176
+ failedIds.push(leaf.id);
177
+ break;
178
+ }
179
+ logger.warn(`${label} ${stillMissing.length}/${remaining.length} entries missing, will retry`);
180
+ remaining = stillMissing;
181
+ }
182
+ catch (error) {
183
+ const message = error instanceof Error ? error.message : String(error);
184
+ if (attempt === MAX_RETRIES) {
185
+ logger.error(`${label} Failed after ${MAX_RETRIES + 1} attempts: ${message}`);
186
+ for (const leaf of remaining)
187
+ failedIds.push(leaf.id);
188
+ break;
189
+ }
190
+ logger.warn(`${label} Attempt ${attempt + 1} failed: ${message}`);
191
+ }
192
+ }
193
+ }
194
+ if (failedIds.length > 0) {
195
+ const preview = failedIds.slice(0, 20).join(', ');
196
+ const more = failedIds.length > 20 ? `, …(+${failedIds.length - 20})` : '';
197
+ throw new Error(`Translation failed for ${failedIds.length} entry/entries (ids: ${preview}${more})`);
198
+ }
199
+ return translations;
200
+ };
@@ -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 interface Translatable {
23
- chunks: ChunkInfo[];
24
- from: string;
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 JsonObject = Record<string, any>;
29
- export type Chunk = Uint8Array;
30
- export type ChunkInfo = {
31
- data: Uint8Array;
32
- keyCount: number;
33
- byteSize: number;
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;CACd,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;CACd,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE7C,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC;AAE/B,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,UAAU,CAAC;IAEjB,QAAQ,EAAE,MAAM,CAAC;IAEjB,QAAQ,EAAE,MAAM,CAAC;IAEjB,KAAK,EAAE,MAAM,CAAC;CACf,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"}
@@ -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.27/mod.js';
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;AAElE,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI,CAAC,aAAa,CAAC,KAAG,sBAmCxD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,IAAI,MAAM;;;CA2DvD,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAI3C,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,KAAG,OAAO,CAAC,IAAI,CAE9C,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"}
@@ -1,21 +1,25 @@
1
+ import { DEFAULT_MAX_BATCH_BYTES } from './contants.js';
1
2
  export const validateArgs = (args) => {
2
- if (!args.key) {
3
+ if (!args.key)
3
4
  throw new Error('AI Key is required');
4
- }
5
- if (!args.provider) {
5
+ if (!args.provider)
6
6
  throw new Error('Provider parameter is required');
7
- }
8
- if (!args.input) {
7
+ if (!args.input)
9
8
  throw new Error('Input parameter is required');
10
- }
11
- if (!args.output) {
9
+ if (!args.output)
12
10
  throw new Error('Output parameter is required');
13
- }
14
- if (!args.from) {
11
+ if (!args.from)
15
12
  throw new Error('Source language (from) parameter is required');
16
- }
17
- if (!args.to) {
13
+ if (!args.to)
18
14
  throw new Error('Target language (to) parameter is required');
15
+ let maxBatchBytes = DEFAULT_MAX_BATCH_BYTES;
16
+ const rawMaxBatchSize = args['max-batch-size'];
17
+ if (rawMaxBatchSize !== undefined) {
18
+ const parsed = parseInt(rawMaxBatchSize, 10);
19
+ if (isNaN(parsed) || parsed <= 0) {
20
+ throw new Error('--max-batch-size must be a positive integer (value in KB, e.g. --max-batch-size 8)');
21
+ }
22
+ maxBatchBytes = parsed * 1024;
19
23
  }
20
24
  return {
21
25
  key: args.key,
@@ -26,74 +30,11 @@ export const validateArgs = (args) => {
26
30
  from: args.from,
27
31
  to: args.to,
28
32
  url: args.url,
33
+ noLimit: args['no-limit'] ?? false,
34
+ noTimeout: args['no-timeout'] ?? false,
35
+ maxBatchBytes,
29
36
  };
30
37
  };
31
- export const generatePrompts = (from, to) => {
32
- const systemPrompt = `You are a specialized i18next JSON translation expert. Your role is to translate content from ${from} to ${to} with these strict requirements:
33
-
34
- 1. COMPLETE TRANSLATION:
35
- - Translate ALL text values comprehensively
36
- - Double-check to ensure no text is left untranslated
37
- - Pay special attention to arrays and nested objects to ensure everything is translated
38
- - If unsure about any translation, provide the most accurate and natural translation possible
39
-
40
- 2. TRANSLATION QUALITY:
41
- - Use natural, context-appropriate language
42
- - Maintain consistent terminology throughout the translation
43
- - Use formal language unless the source is clearly casual
44
- - Preserve the exact meaning and tone of the original text
45
- - For UI elements, use standard localized terms common in ${to} applications
46
-
47
- 3. STRUCTURAL PRESERVATION:
48
- - Keep all JSON structure and keys exactly as they are
49
- - Maintain all variables and interpolation patterns ({{name}}, __VARIABLE__, $t(), etc.)
50
- - Preserve all HTML tags and markdown formatting
51
- - Keep all whitespace, nesting, and formatting intact
52
-
53
- 4. VALIDATION:
54
- - Return only valid JSON
55
- - Verify that all text is translated
56
- - Ensure no source language text remains
57
- - Confirm all arrays and nested objects are fully translated`;
58
- const userPrompt = `Please translate this i18next JSON file with these specific requirements:
59
-
60
- 1. THOROUGH TRANSLATION:
61
- - Translate every single text value from ${from} to ${to}
62
- - Pay special attention to arrays and nested objects
63
- - Verify no text is left in ${from}
64
- - Double-check all translations for completeness
65
-
66
- 2. PRESERVE STRUCTURE:
67
- - Keep all keys unchanged (e.g. "button.submit")
68
- - Maintain all variables: {{name}}, __VAR__, $t()
69
- - Preserve HTML tags and markdown
70
- - Keep all special characters
71
- - Maintain exact JSON structure
72
-
73
- 3. QUALITY REQUIREMENTS:
74
- - Use natural ${to} language
75
- - Maintain consistent terminology
76
- - Use formal language unless source is casual
77
- - Ensure translations match the context
78
- - Use standard ${to} UI terminology for interface elements
79
-
80
- 4. OUTPUT:
81
- - Return only the translated JSON
82
- - No explanations or comments
83
- - No additional text
84
- - No formatting changes
85
- - Must be valid JSON`;
86
- return { systemPrompt, userPrompt };
87
- };
88
- export const isValidJson = (value) => {
89
- try {
90
- JSON.parse(value);
91
- return true;
92
- }
93
- catch {
94
- return false;
95
- }
96
- };
97
38
  export const formatBytes = (bytes) => {
98
39
  if (bytes < 1024)
99
40
  return `${bytes} B`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glotto",
3
- "version": "2.8.0",
3
+ "version": "3.0.0",
4
4
  "description": "A tool for translating i18n JSON files using AI services.",
5
5
  "author": "Ibrahim Odev <me@ibrahimo.dev>",
6
6
  "repository": {
@@ -22,10 +22,10 @@
22
22
  "node": ">=20.0.0"
23
23
  },
24
24
  "dependencies": {
25
- "@anthropic-ai/sdk": "^0.74.0",
26
- "@google/genai": "^1.41.0",
25
+ "@anthropic-ai/sdk": "^0.95.0",
26
+ "@google/genai": "^1.52.0",
27
27
  "consola": "^3.4.2",
28
- "openai": "^6.21.0",
28
+ "openai": "^6.36.0",
29
29
  "@deno/shim-deno": "~0.18.0"
30
30
  },
31
31
  "devDependencies": {