@drone1/alt 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -44
- package/{localization/config.json → alt.config.json} +3 -1
- package/localization/.localization.cache.json +554 -140
- package/localization/aa.json +4 -1
- package/localization/af.json +4 -1
- package/localization/agq.json +4 -1
- package/localization/ak.json +4 -1
- package/localization/am.json +4 -1
- package/localization/ar.json +4 -1
- package/localization/as.json +4 -1
- package/localization/asa.json +4 -1
- package/localization/ast.json +4 -1
- package/localization/az.json +4 -1
- package/localization/ba.json +4 -1
- package/localization/bas.json +4 -1
- package/localization/be.json +4 -1
- package/localization/bem.json +4 -1
- package/localization/bez.json +4 -1
- package/localization/bg.json +4 -1
- package/localization/bm.json +4 -1
- package/localization/bn.json +4 -1
- package/localization/bo.json +4 -1
- package/localization/br.json +4 -1
- package/localization/brx.json +4 -1
- package/localization/bs.json +4 -1
- package/localization/byn.json +4 -1
- package/localization/ca.json +4 -1
- package/localization/ccp.json +4 -1
- package/localization/cd-RU.json +4 -1
- package/localization/ceb.json +4 -1
- package/localization/cgg.json +4 -1
- package/localization/chr.json +4 -1
- package/localization/co.json +4 -1
- package/localization/cs.json +4 -1
- package/localization/cu-RU.json +4 -1
- package/localization/da.json +4 -1
- package/localization/de-AT.json +4 -1
- package/localization/de-CH.json +4 -1
- package/localization/de-DE.json +4 -1
- package/localization/dua.json +4 -1
- package/localization/dv.json +4 -1
- package/localization/dz.json +4 -1
- package/localization/ebu.json +4 -1
- package/localization/en.json +4 -1
- package/localization/es-ES.json +4 -1
- package/localization/es-MX.json +4 -1
- package/localization/et.json +4 -1
- package/localization/eu.json +4 -1
- package/localization/fr-CA.json +4 -1
- package/localization/fr-CH.json +4 -1
- package/localization/fr-FR.json +4 -1
- package/localization/gsw.json +4 -1
- package/localization/hi.json +4 -1
- package/localization/hr.json +4 -1
- package/localization/hy.json +4 -1
- package/localization/ja.json +4 -1
- package/localization/km.json +4 -1
- package/localization/ksf.json +4 -1
- package/localization/ku.json +4 -1
- package/localization/kw.json +4 -1
- package/localization/my.json +4 -1
- package/localization/nl.json +4 -1
- package/localization/prs.json +4 -1
- package/localization/reference.js +3 -0
- package/localization/ru.json +4 -1
- package/localization/sq.json +4 -1
- package/localization/swc.json +4 -1
- package/localization/th.json +4 -1
- package/localization/tzm-Latn-.json +4 -1
- package/localization/uk.json +4 -1
- package/localization/vi.json +4 -1
- package/localization/zh-Hans.json +4 -1
- package/localization/zh-Hant.json +4 -1
- package/package.json +2 -2
- package/src/commands/translate.js +78 -17
- package/src/lib/config.js +30 -14
- package/src/lib/consts.js +1 -4
- package/src/lib/io.js +5 -0
- package/src/lib/reference-loader.js +1 -1
- package/src/lib/utils.js +1 -1
- package/src/main.mjs +9 -9
- package/test/main-cli.test.js +0 -18
- package/test/translate-command.test.js +6 -2
package/README.md
CHANGED
|
@@ -23,20 +23,21 @@
|
|
|
23
23
|
* [Display language](#display-language)
|
|
24
24
|
* [Usage](#usage)
|
|
25
25
|
* [Examples](#examples)
|
|
26
|
-
* [Example I](#example-i)
|
|
26
|
+
* [Example I: ALT's localized display strings](#example-i-alts-localized-display-strings)
|
|
27
27
|
* [Example II](#example-ii)
|
|
28
28
|
* [Example III](#example-iii)
|
|
29
|
-
* [Example
|
|
29
|
+
* [Example III](#example-iii-1)
|
|
30
30
|
* [Formatting](#formatting)
|
|
31
31
|
* [Translation rules](#translation-rules)
|
|
32
32
|
* [Additional notes](#additional-notes)
|
|
33
|
+
* [Yes, you should commit your .localization.cache.json](#yes-you-should-commit-your-localizationcachejson)
|
|
33
34
|
* [Delayed vs. realtime writes](#delayed-vs-realtime-writes)
|
|
34
35
|
* [CI](#ci)
|
|
35
36
|
* [Contributing](#contributing)
|
|
36
37
|
* [Feedback](#feedback)
|
|
37
38
|
|
|
38
39
|
<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
|
|
39
|
-
<!-- Added by: jonl, at: Fri Apr 18
|
|
40
|
+
<!-- Added by: jonl, at: Fri Apr 18 09:55:42 PM CEST 2025 -->
|
|
40
41
|
|
|
41
42
|
<!--te-->
|
|
42
43
|
|
|
@@ -101,12 +102,15 @@ Sample output:
|
|
|
101
102
|
Note that output files can be lower-cased if you pass the ``--normalize-output-filenames`` option, so `fr-FR` translations would write to `fr-fr.json`
|
|
102
103
|
|
|
103
104
|
## Config file
|
|
104
|
-
[_optional_] For convenience, a config file is supported. You can use a config file in conjunction with command-line arguments.
|
|
105
|
+
[_optional_] For convenience, a config file is supported. You can use a config file in conjunction with command-line arguments.
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
`--config-file`.
|
|
107
|
+
Command-line arguments override config file values.
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
If no explicit config file is specified via `--config-file`, ALT will search for a file with the name `alt.config.json` in the current working directory.
|
|
110
|
+
|
|
111
|
+
If no config is loaded, you'll need to specify `--reference-file` and `--provider`, otherwise ALT will fail.
|
|
112
|
+
|
|
113
|
+
Here's an example `alt.config.json` file you might keep in your project's root directory:
|
|
110
114
|
|
|
111
115
|
```
|
|
112
116
|
{
|
|
@@ -116,13 +120,17 @@ Here's an example config:
|
|
|
116
120
|
"lookForContextData": true,
|
|
117
121
|
"contextPrefix": "_context:",
|
|
118
122
|
"contextSuffix": "",
|
|
123
|
+
"outputDir": "localization",
|
|
124
|
+
"referenceFile": "localization/reference.js",
|
|
119
125
|
"targetLanguages": [
|
|
120
126
|
"es-MX", "zh-SG"
|
|
121
127
|
]
|
|
122
128
|
}
|
|
123
129
|
```
|
|
124
130
|
|
|
125
|
-
|
|
131
|
+
Since in most cases these arguments will not change often, a config file is recommended.
|
|
132
|
+
|
|
133
|
+
Any of the above settings can be specified using command-line arguments, but note the mapping from _camelCase_ to _kebab-case_ (`appContextMessage` => `--app-context-message`, `referenceLanguage` => `--reference-language`, etc.).
|
|
126
134
|
|
|
127
135
|
## Adding context
|
|
128
136
|
Sometimes a string isn't enough to give context to the AI, and as a result, it may give an undesirable translation. ALT allows you to specify additional context for this reason.
|
|
@@ -186,15 +194,15 @@ Environment variables:
|
|
|
186
194
|
Usage: alt translate [options]
|
|
187
195
|
|
|
188
196
|
Options:
|
|
189
|
-
-
|
|
190
|
-
-
|
|
197
|
+
-c, --config-file <path> Path to config file; defaults to <output dir>/alt.config.json
|
|
198
|
+
-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; overrides any 'referenceFile' config setting
|
|
199
|
+
-o, --output-dir <path> Output directory for localized files; overrides any 'outputDir' config setting
|
|
191
200
|
-rl, --reference-language <language> The reference file's language; overrides any 'referenceLanguage' config setting
|
|
192
|
-
-o, --output-dir <path> Output directory for localized files
|
|
193
201
|
-tl, --target-languages <list> Comma-separated list of language codes; overrides any 'targetLanguages' config setting
|
|
194
|
-
-k, --keys <list> Comma-separated list of keys to process
|
|
195
|
-
-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")
|
|
196
|
-
-m, --app-context-message <message> Description of your app to
|
|
197
|
-
-f, --force Force regeneration of all
|
|
202
|
+
-k, --keys <list> Comma-separated list of keys to process; if none are processed, all keys in the reference file will be processed
|
|
203
|
+
-R, --reference-exported-var-name <var name> For .js or .mjs reference files only, 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")
|
|
204
|
+
-m, --app-context-message <message> Description of your app, to be passed along to the AI, per translation request; overrides any 'appContextMessage' config setting
|
|
205
|
+
-f, --force Force regeneration of all keys; if no '--keys' argument is specified, all keys will be processed (default: false)
|
|
198
206
|
-rtw, --realtime-writes Write updates to disk immediately, rather than on shutdown (default: false)
|
|
199
207
|
-y, --tty Use tty/simple renderer; useful for CI (default: false)
|
|
200
208
|
-M, --model <name> LLM model name to use; defaults are: for "anthropic": "claude-3-7-sonnet-20250219", for "google": "gemini-2.0-flash", for "openai": "gpt-4-turbo"; use the 'list-models' command to view all models
|
|
@@ -222,28 +230,29 @@ Options:
|
|
|
222
230
|
```
|
|
223
231
|
|
|
224
232
|
## Examples
|
|
225
|
-
### Example I
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
### Example I: ALT's localized display strings
|
|
234
|
+
The best example is probably the localization for ALT's own display strings.
|
|
235
|
+
|
|
236
|
+
See [alt.config.js](alt.config.js), which contains a `config.js` file and localization files used for the tool's own display strings.
|
|
237
|
+
|
|
238
|
+
Generated with `npm run localize-display-strings`
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
### Example II
|
|
231
242
|
```bash
|
|
232
243
|
alt translate --reference-file loc.js
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
--reference-var-name data
|
|
245
|
+
--provider anthropic
|
|
246
|
+
--look-for-context-data
|
|
247
|
+
--context-prefix _context:
|
|
237
248
|
```
|
|
249
|
+
* Imports reference strings from ``loc.js``
|
|
250
|
+
* Looks for exported variable ``data`` (if `loc.js` has `export data = { ... } `)
|
|
251
|
+
* Translates with Claude
|
|
252
|
+
* Looks for context keys starting with `_context:`
|
|
253
|
+
* Writes output files to the current working directory
|
|
238
254
|
|
|
239
|
-
### Example
|
|
240
|
-
* Import config from `./localization-config.json`
|
|
241
|
-
* Import from ``loc.js``
|
|
242
|
-
* Look for exported ``default`` value
|
|
243
|
-
* Translate with ChatGPT
|
|
244
|
-
* Look for context keys ending with `[context]`
|
|
245
|
-
* Write to disk repeatedly, as changes are processed
|
|
246
|
-
* Write files to `./localization`
|
|
255
|
+
### Example III
|
|
247
256
|
```bash
|
|
248
257
|
alt translate --config-file ./localization-config.json
|
|
249
258
|
--reference-file loc.js
|
|
@@ -252,26 +261,29 @@ alt translate --config-file ./localization-config.json
|
|
|
252
261
|
--look-for-context-data
|
|
253
262
|
--context-suffix "[context]"
|
|
254
263
|
```
|
|
264
|
+
* Imports config from `./localization-config.json`
|
|
265
|
+
* Imports reference strings from ``loc.js``
|
|
266
|
+
* Looks for exported ``default`` value
|
|
267
|
+
* Translates with ChatGPT
|
|
268
|
+
* Looks for context keys ending with `[context]`
|
|
269
|
+
* Writes to disk repeatedly, as changes are processed
|
|
270
|
+
* Writes files to `./localization`
|
|
271
|
+
|
|
255
272
|
### Example III
|
|
256
|
-
* Overrides any config's languages
|
|
257
|
-
* Only process the specified strings
|
|
258
273
|
```bash
|
|
259
274
|
alt translate --config-file config.json
|
|
260
|
-
--reference-file reference.js
|
|
261
|
-
--output-dir localization
|
|
275
|
+
--reference-file localization/reference/source.js
|
|
276
|
+
--output-dir localization/output
|
|
262
277
|
--provider openai
|
|
263
|
-
--look-for-context-data
|
|
264
|
-
--context-suffix "[context]"
|
|
265
278
|
--target-languages vi,aa
|
|
266
279
|
--keys error-msg,title-hero,button-text-send
|
|
267
280
|
```
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
Generated with `npm run localize-display-strings`
|
|
281
|
+
* Overrides any target languages specified in the config
|
|
282
|
+
* Only processes the specified keys (`error-msg`, etc.)
|
|
272
283
|
|
|
273
284
|
## Formatting
|
|
274
285
|
If your reference values include formatting information like this:
|
|
286
|
+
|
|
275
287
|
```javascript
|
|
276
288
|
"error-msg": "The server returned an error: %%details%%"
|
|
277
289
|
```
|
|
@@ -279,7 +291,7 @@ or
|
|
|
279
291
|
```javascript
|
|
280
292
|
"error-msg": "The server returned an error: {{details}}"
|
|
281
293
|
```
|
|
282
|
-
...or whatever syntax your app may use
|
|
294
|
+
...or whatever syntax your app may use for formatting, the AI's consistently smart enough not to translate `%%details%%` or `{{details}}` into the target language, and will leave it untouched.
|
|
283
295
|
|
|
284
296
|
Internally, there is currently nothing in the prompt about this. I've tested with `%%var%%` syntax, and it hasn't failed yet.
|
|
285
297
|
|
|
@@ -305,6 +317,9 @@ NOTE: Translation will _not_ occur if ALT detects that the given value in the ta
|
|
|
305
317
|
later, you can just delete that key/value pair from the given file.
|
|
306
318
|
|
|
307
319
|
## Additional notes
|
|
320
|
+
### Yes, you should commit your .localization.cache.json
|
|
321
|
+
If you do not do this, you'll lose important state and need to re-translate everything.
|
|
322
|
+
|
|
308
323
|
### Delayed vs. realtime writes
|
|
309
324
|
By default, ALT will not write to disk until the tool is shutting down (including SIGTERM – yes, `Ctrl+C` is safe).
|
|
310
325
|
|