@drone1/alt 0.4.2 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +63 -62
  2. package/localization/.localization.cache.json +3100 -908
  3. package/localization/aa.json +23 -16
  4. package/localization/af.json +19 -12
  5. package/localization/agq.json +23 -16
  6. package/localization/ak.json +23 -16
  7. package/localization/am.json +23 -16
  8. package/localization/ar.json +19 -12
  9. package/localization/as.json +23 -16
  10. package/localization/asa.json +23 -16
  11. package/localization/ast.json +16 -9
  12. package/localization/az.json +17 -10
  13. package/localization/ba.json +23 -16
  14. package/localization/bas.json +23 -16
  15. package/localization/be.json +23 -16
  16. package/localization/bem.json +23 -16
  17. package/localization/bez.json +22 -15
  18. package/localization/bg.json +18 -11
  19. package/localization/bm.json +17 -10
  20. package/localization/bn.json +20 -13
  21. package/localization/bo.json +23 -16
  22. package/localization/br.json +18 -11
  23. package/localization/brx.json +23 -16
  24. package/localization/bs.json +20 -13
  25. package/localization/byn.json +23 -16
  26. package/localization/ca.json +16 -9
  27. package/localization/ccp.json +23 -16
  28. package/localization/cd-RU.json +16 -9
  29. package/localization/ceb.json +21 -14
  30. package/localization/cgg.json +22 -15
  31. package/localization/chr.json +23 -16
  32. package/localization/co.json +22 -15
  33. package/localization/config.json +1 -1
  34. package/localization/cs.json +18 -11
  35. package/localization/cu-RU.json +23 -16
  36. package/localization/da.json +14 -7
  37. package/localization/de-AT.json +19 -12
  38. package/localization/de-CH.json +19 -12
  39. package/localization/de-DE.json +18 -11
  40. package/localization/dua.json +23 -16
  41. package/localization/dv.json +23 -16
  42. package/localization/dz.json +23 -16
  43. package/localization/ebu.json +23 -16
  44. package/localization/en.json +9 -2
  45. package/localization/es-ES.json +17 -10
  46. package/localization/es-MX.json +18 -11
  47. package/localization/et.json +20 -13
  48. package/localization/eu.json +20 -13
  49. package/localization/fr-CA.json +15 -8
  50. package/localization/fr-CH.json +15 -8
  51. package/localization/fr-FR.json +15 -8
  52. package/localization/gsw.json +20 -13
  53. package/localization/hi.json +19 -12
  54. package/localization/hr.json +18 -11
  55. package/localization/hy.json +21 -14
  56. package/localization/ja.json +18 -11
  57. package/localization/km.json +21 -14
  58. package/localization/ksf.json +23 -16
  59. package/localization/ku.json +22 -15
  60. package/localization/kw.json +23 -16
  61. package/localization/my.json +22 -15
  62. package/localization/nl.json +18 -11
  63. package/localization/prs.json +18 -11
  64. package/localization/reference.js +9 -1
  65. package/localization/ru.json +14 -7
  66. package/localization/sq.json +19 -12
  67. package/localization/swc.json +21 -14
  68. package/localization/th.json +15 -8
  69. package/localization/tzm-Latn-.json +23 -16
  70. package/localization/uk.json +14 -7
  71. package/localization/vi.json +17 -10
  72. package/localization/zh-Hans.json +17 -10
  73. package/localization/zh-Hant.json +18 -11
  74. package/package.json +4 -3
  75. package/src/commands/list-models.js +6 -0
  76. package/src/{translate.js → commands/translate.js} +124 -139
  77. package/src/{consts.js → lib/consts.js} +12 -0
  78. package/src/{io.js → lib/io.js} +1 -1
  79. package/src/{logging.js → lib/logging.js} +3 -3
  80. package/src/{options.js → lib/options.js} +1 -1
  81. package/src/lib/reference-loader.js +91 -0
  82. package/src/{utils.js → lib/utils.js} +15 -0
  83. package/src/localizer/localize.js +3 -4
  84. package/src/main.mjs +98 -49
  85. package/src/providers/anthropic.mjs +38 -2
  86. package/src/providers/openai.mjs +45 -2
  87. package/src/shutdown.js +1 -1
  88. /package/{bin.mjs → alt.mjs} +0 -0
  89. /package/src/{assert.js → lib/assert.js} +0 -0
  90. /package/src/{cache.js → lib/cache.js} +0 -0
  91. /package/src/{config.js → lib/config.js} +0 -0
  92. /package/src/{context-keys.js → lib/context-keys.js} +0 -0
  93. /package/src/{logo.js → lib/logo.js} +0 -0
  94. /package/src/{provider.js → lib/provider.js} +0 -0
package/README.md CHANGED
@@ -14,10 +14,10 @@
14
14
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
15
15
 
16
16
  # AI Localization Tool
17
- Translates all strings in a reference `.js` file to all target languages using AI.
17
+ Translates all source strings in a reference (`.js`,`.mjs`,`.json`,`.jsonc`) file to all target languages using AI.
18
18
 
19
19
  ## Features
20
- * Loads reference key/value pairs from a reference file
20
+ * Loads source/reference key/value pairs from a file
21
21
  * Localizes using AI as needed, writing to a .json file per language
22
22
  * App-level context can be specified [`appContextMessage`]
23
23
  * Additional context can be specified per string [`--contextPrefix`, `--contextSuffix`]
@@ -44,12 +44,12 @@ You can specify an exported variable instead of using `default`. See `--referenc
44
44
  2. Running
45
45
  ```bash
46
46
  ANTHROPIC_API_KEY=<secret>
47
- alt --reference-file ./reference.js --reference-language en --target-languages aa,bo,es-MX,hi,zh-SG --provider anthropic
47
+ alt translate --reference-file ./reference.js --reference-language en --target-languages aa,bo,es-MX,hi,zh-SG --provider anthropic
48
48
  ```
49
49
  or
50
50
  ```bash
51
51
  OPENAI_API_KEY=<secret>
52
- alt --reference-file ./reference.js --reference-language en --target-languages aa,bo,es-MX,hi,zh-SG --provider openai
52
+ alt translate --reference-file ./reference.js --reference-language en --target-languages aa,bo,es-MX,hi,zh-SG --provider openai
53
53
  ```
54
54
  These commands would iterate across all key/value pairs in the variable exported from `./reference.js` and if needed, translate.
55
55
 
@@ -69,15 +69,6 @@ Note that output files can be lower-cased if you pass the ``--normalize-output-f
69
69
  ALT CLI itself has been localized so you can use it many languages. For non-English languages, you can set the display language with the `ALT_LANGUAGE` environment variable. Please feel free to submit
70
70
  an issue or a PR if you'd like to add another language.
71
71
 
72
- ## Rules
73
- Translation will occur for a given target language & key if any of the following are true:
74
- * The reference value was modified and translation has not yet occurred for the given language/key
75
- * If a context value for the given target language/key is found and has been modified.
76
- * The `--force` flag is used
77
-
78
- Translation will _not_ occur if `alt` detects that the given value in the target language file has been manually modified. If you modify an output value manually and want it to be re-translated
79
- later, you can just delete that key/value pair from the given file.
80
-
81
72
  ## Config file
82
73
  [_optional_] You can create a config file. By default, `ALT` will search the output directory for `config.json`, but you can specify a path directly using
83
74
  `--config-file`.
@@ -102,60 +93,60 @@ Any of the above settings can be specified using command-line arguments (`--app-
102
93
 
103
94
  ## Usage
104
95
  ```
105
- alt [options] [command]
96
+ Usage: alt [options] [command]
97
+
98
+ An AI-powered localization tool
106
99
 
107
100
  Options:
108
- -V, --version output the version number
109
- -r, --reference-file <path> Path to reference JSONC file (default language)
110
- -rl, --reference-language <language> The reference file's language; overrides any
111
- 'referenceLanguage' config setting
112
- -p, --provider <name> AI provider to use for translations (anthropic,
113
- openai); overrides any 'provider' config setting
114
- -o, --output-dir <path> Output directory for localized files
115
- -l, --target-languages <list> Comma-separated list of language codes; overrides
116
- any 'targetLanguages' config setting
117
- -k, --keys <list> Comma-separated list of keys to process
118
- -j, --reference-var-name <var name> The exported variable in the reference file, e.g.
119
- export default = {...} you'd use 'default'
120
- (default: "default")
121
- -f, --force Force regeneration of all translations (default:
122
- false)
123
- -rtw, --realtime-writes Write updates to disk immediately, rather than on
124
- shutdown (default: false)
125
- -m, --app-context-message <message> Description of your app to give context. Passed
126
- with each translation request; overrides any
127
- 'appContextMessage' config setting
128
- -y, --tty Use tty/simple renderer; useful for CI (default:
129
- false)
130
- -c, --config-file <path> Path to config file; defaults to <output
131
- dir>/config.json
132
- -x, --max-retries <integer> Maximum retries on failure (default: 3)
133
- -n, --normalize-output-filenames Normalizes output filenames (to all lower-case);
134
- overrides any 'normalizeOutputFilenames' in config
135
- setting (default: false)
136
- -v, --verbose Enables verbose spew (default: false)
137
- -d, --debug Enables debug spew (default: false)
138
- -t, --trace Enables trace spew (default: false)
139
- --context-prefix <value> String to be prefixed to all keys to search for
140
- additional context, which are passed along to the
141
- AI for context
142
- --context-suffix <value> String to be suffixed to all keys to search for
143
- additional context, which are passed along to the
144
- AI for context
145
- --look-for-context-data If specified, ALT will pass any context data
146
- specified in the reference file to the AI provider
147
- for translation. At least one of --contextPrefix
148
- or --contextSuffix must be specified (default:
149
- false)
150
- -h, --help display help for command
101
+ -V, --version output the version number
102
+ -h, --help display help for command
151
103
 
152
104
  Commands:
153
- translate
105
+ translate [options]
106
+ list-models [options]
107
+ help [command] display help for command
154
108
 
155
109
  Environment variables:
156
110
  ANTHROPIC_API_KEY Your Anthropic API key
157
111
  OPENAI_API_KEY Your OpenAI API key
158
- ALT_LANGUAGE CLI display language
112
+ ALT_LANGUAGE POSIX locale used for display
113
+
114
+ ---
115
+ Usage: alt translate [options]
116
+
117
+ Options:
118
+ -r, --reference-file <path> Path to reference file of source strings to be translated. This file can be in .js, .mjs, .json, or .jsonc formats and is presumed to be in the reference language specified by --reference-language
119
+ -c, --config-file <path> Path to config file; defaults to <output dir>/config.json
120
+ -rl, --reference-language <language> The reference file's language; overrides any 'referenceLanguage' config setting
121
+ -o, --output-dir <path> Output directory for localized files
122
+ -l, --target-languages <list> Comma-separated list of language codes; overrides any 'targetLanguages' config setting
123
+ -k, --keys <list> Comma-separated list of keys to process
124
+ -R, --reference-exported-var-name <var name> For .js or .mjs reference files, this will be the exported variable, e.g. for 'export default = {...}' you'd use 'default' here, or 'data' for 'export const data = { ... }'. For .json or .jsonc reference files, this value is ignored. (default: "default")
125
+ -m, --app-context-message <message> Description of your app to give context. Passed with each translation request; overrides any 'appContextMessage' config setting
126
+ -f, --force Force regeneration of all translations (default: false)
127
+ -rtw, --realtime-writes Write updates to disk immediately, rather than on shutdown (default: false)
128
+ -y, --tty Use tty/simple renderer; useful for CI (default: false)
129
+ -M, --model <name> LLM model name to use; defaults are: for "anthropic": "claude-3-7-sonnet-20250219", for "openai": "gpt-4-turbo"; use the 'list-models' command to view all models
130
+ -x, --max-retries <integer> Maximum retries on failure (default: 3)
131
+ -n, --normalize-output-filenames Normalizes output filenames (to all lower-case); overrides any 'normalizeOutputFilenames' in config setting (default: false)
132
+ -N, --no-logo Suppress logo printout
133
+ -cp, --context-prefix <value> String to be prefixed to all keys to search for additional context, which are passed along to the AI for context
134
+ -cs, --context-suffix <value> String to be suffixed to all keys to search for additional context, which are passed along to the AI for context
135
+ -L, --look-for-context-data If specified, ALT will pass any context data specified in the reference file to the AI provider for translation. At least one of --contextPrefix or --contextSuffix must be specified (default: false)
136
+ -v, --verbose Enables verbose spew (default: false)
137
+ -d, --debug Enables debug spew (default: false)
138
+ -t, --trace Enables trace spew (default: false)
139
+ --dev Enable dev mode, which prints stack traces with errors (default: false)
140
+ -p, --provider <name> AI provider to use for translations (anthropic, openai); overrides any 'provider' config setting
141
+ -h, --help display help for command
142
+
143
+ ---
144
+ Usage: alt list-models [options]
145
+
146
+ Options:
147
+ -p, --provider <name> AI provider to use for translations (anthropic,
148
+ openai); overrides any 'provider' config setting
149
+ -h, --help display help for command
159
150
  ```
160
151
 
161
152
  ## Examples
@@ -166,12 +157,13 @@ Environment variables:
166
157
  * Look for context keys starting with `_context:`
167
158
  * Write output files to the current working directory
168
159
  ```bash
169
- alt --reference-file loc.js
160
+ alt translate --reference-file loc.js
170
161
  --reference-var-name data
171
162
  --provider anthropic
172
163
  --look-for-context-data
173
164
  --context-prefix _context:
174
165
  ```
166
+
175
167
  ### Example II
176
168
  * Import config from `./localization-config.json`
177
169
  * Import from ``loc.js``
@@ -181,7 +173,7 @@ alt --reference-file loc.js
181
173
  * Write to disk repeatedly, as changes are processed
182
174
  * Write files to `./localization`
183
175
  ```bash
184
- alt --config-file ./localization-config.json
176
+ alt translate --config-file ./localization-config.json
185
177
  --reference-file loc.js
186
178
  --output-dir localization
187
179
  --provider openai
@@ -192,7 +184,7 @@ alt --config-file ./localization-config.json
192
184
  * Overrides any config's languages
193
185
  * Only process the specified strings
194
186
  ```bash
195
- alt --config-file config.json
187
+ alt translate --config-file config.json
196
188
  --reference-file reference.js
197
189
  --output-dir localization
198
190
  --provider openai
@@ -221,6 +213,15 @@ Internally, there is currently nothing in the prompt about this. I've tested wit
221
213
 
222
214
  Please submit an issue if it causes you any trouble.
223
215
 
216
+ ## Rules
217
+ Translation will occur for a given target language & key if any of the following are true:
218
+ * The reference value was modified and translation has not yet occurred for the given language/key
219
+ * If a context value for the given target language/key is found and has been modified.
220
+ * The `--force` flag is used
221
+
222
+ Translation will _not_ occur if `alt` detects that the given value in the target language file has been manually modified. If you modify an output value manually and want it to be re-translated
223
+ later, you can just delete that key/value pair from the given file.
224
+
224
225
  ## Additional notes
225
226
  ### Delayed vs. realtime writes
226
227
  By default, `alt` will not write to disk until the tool is shutting down (including SIGTERM &ndash; yes, `Ctrl+C` is safe).