@drone1/alt 0.4.1 → 0.7.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 +56 -61
- package/localization/.localization.cache.json +3100 -908
- package/localization/aa.json +23 -16
- package/localization/af.json +19 -12
- package/localization/agq.json +23 -16
- package/localization/ak.json +23 -16
- package/localization/am.json +23 -16
- package/localization/ar.json +19 -12
- package/localization/as.json +23 -16
- package/localization/asa.json +23 -16
- package/localization/ast.json +16 -9
- package/localization/az.json +17 -10
- package/localization/ba.json +23 -16
- package/localization/bas.json +23 -16
- package/localization/be.json +23 -16
- package/localization/bem.json +23 -16
- package/localization/bez.json +22 -15
- package/localization/bg.json +18 -11
- package/localization/bm.json +17 -10
- package/localization/bn.json +20 -13
- package/localization/bo.json +23 -16
- package/localization/br.json +18 -11
- package/localization/brx.json +23 -16
- package/localization/bs.json +20 -13
- package/localization/byn.json +23 -16
- package/localization/ca.json +16 -9
- package/localization/ccp.json +23 -16
- package/localization/cd-RU.json +16 -9
- package/localization/ceb.json +21 -14
- package/localization/cgg.json +22 -15
- package/localization/chr.json +23 -16
- package/localization/co.json +22 -15
- package/localization/config.json +1 -1
- package/localization/cs.json +18 -11
- package/localization/cu-RU.json +23 -16
- package/localization/da.json +14 -7
- package/localization/de-AT.json +19 -12
- package/localization/de-CH.json +19 -12
- package/localization/de-DE.json +18 -11
- package/localization/dua.json +23 -16
- package/localization/dv.json +23 -16
- package/localization/dz.json +23 -16
- package/localization/ebu.json +23 -16
- package/localization/en.json +9 -2
- package/localization/es-ES.json +17 -10
- package/localization/es-MX.json +18 -11
- package/localization/et.json +20 -13
- package/localization/eu.json +20 -13
- package/localization/fr-CA.json +15 -8
- package/localization/fr-CH.json +15 -8
- package/localization/fr-FR.json +15 -8
- package/localization/gsw.json +20 -13
- package/localization/hi.json +19 -12
- package/localization/hr.json +18 -11
- package/localization/hy.json +21 -14
- package/localization/ja.json +18 -11
- package/localization/km.json +21 -14
- package/localization/ksf.json +23 -16
- package/localization/ku.json +22 -15
- package/localization/kw.json +23 -16
- package/localization/my.json +22 -15
- package/localization/nl.json +18 -11
- package/localization/prs.json +18 -11
- package/localization/reference.js +9 -1
- package/localization/ru.json +14 -7
- package/localization/sq.json +19 -12
- package/localization/swc.json +21 -14
- package/localization/th.json +15 -8
- package/localization/tzm-Latn-.json +23 -16
- package/localization/uk.json +14 -7
- package/localization/vi.json +17 -10
- package/localization/zh-Hans.json +17 -10
- package/localization/zh-Hant.json +18 -11
- package/package.json +4 -3
- package/src/commands/list-models.js +6 -0
- package/src/{translate.js → commands/translate.js} +124 -139
- package/src/{consts.js → lib/consts.js} +12 -0
- package/src/{io.js → lib/io.js} +1 -1
- package/src/{logging.js → lib/logging.js} +3 -3
- package/src/{options.js → lib/options.js} +1 -1
- package/src/lib/reference-loader.js +91 -0
- package/src/{utils.js → lib/utils.js} +15 -0
- package/src/localizer/localize.js +3 -4
- package/src/main.mjs +98 -49
- package/src/providers/anthropic.mjs +38 -2
- package/src/providers/openai.mjs +45 -2
- package/src/shutdown.js +1 -1
- /package/{bin.mjs → alt.mjs} +0 -0
- /package/src/{assert.js → lib/assert.js} +0 -0
- /package/src/{cache.js → lib/cache.js} +0 -0
- /package/src/{config.js → lib/config.js} +0 -0
- /package/src/{context-keys.js → lib/context-keys.js} +0 -0
- /package/src/{logo.js → lib/logo.js} +0 -0
- /package/src/{provider.js → lib/provider.js} +0 -0
package/README.md
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
[](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
|
|
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
|
|
|
@@ -102,60 +102,60 @@ Any of the above settings can be specified using command-line arguments (`--app-
|
|
|
102
102
|
|
|
103
103
|
## Usage
|
|
104
104
|
```
|
|
105
|
-
alt [options] [command]
|
|
105
|
+
Usage: alt [options] [command]
|
|
106
|
+
|
|
107
|
+
An AI-powered localization tool
|
|
106
108
|
|
|
107
109
|
Options:
|
|
108
|
-
-V, --version
|
|
109
|
-
-
|
|
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
|
|
110
|
+
-V, --version output the version number
|
|
111
|
+
-h, --help display help for command
|
|
151
112
|
|
|
152
113
|
Commands:
|
|
153
|
-
translate
|
|
114
|
+
translate [options]
|
|
115
|
+
list-models [options]
|
|
116
|
+
help [command] display help for command
|
|
154
117
|
|
|
155
118
|
Environment variables:
|
|
156
119
|
ANTHROPIC_API_KEY Your Anthropic API key
|
|
157
120
|
OPENAI_API_KEY Your OpenAI API key
|
|
158
|
-
ALT_LANGUAGE
|
|
121
|
+
ALT_LANGUAGE POSIX locale used for display
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
Usage: alt translate [options]
|
|
125
|
+
|
|
126
|
+
Options:
|
|
127
|
+
-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
|
|
128
|
+
-c, --config-file <path> Path to config file; defaults to <output dir>/config.json
|
|
129
|
+
-rl, --reference-language <language> The reference file's language; overrides any 'referenceLanguage' config setting
|
|
130
|
+
-o, --output-dir <path> Output directory for localized files
|
|
131
|
+
-l, --target-languages <list> Comma-separated list of language codes; overrides any 'targetLanguages' config setting
|
|
132
|
+
-k, --keys <list> Comma-separated list of keys to process
|
|
133
|
+
-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")
|
|
134
|
+
-m, --app-context-message <message> Description of your app to give context. Passed with each translation request; overrides any 'appContextMessage' config setting
|
|
135
|
+
-f, --force Force regeneration of all translations (default: false)
|
|
136
|
+
-rtw, --realtime-writes Write updates to disk immediately, rather than on shutdown (default: false)
|
|
137
|
+
-y, --tty Use tty/simple renderer; useful for CI (default: false)
|
|
138
|
+
-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
|
|
139
|
+
-x, --max-retries <integer> Maximum retries on failure (default: 3)
|
|
140
|
+
-n, --normalize-output-filenames Normalizes output filenames (to all lower-case); overrides any 'normalizeOutputFilenames' in config setting (default: false)
|
|
141
|
+
-N, --no-logo Suppress logo printout
|
|
142
|
+
-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
|
|
143
|
+
-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
|
|
144
|
+
-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)
|
|
145
|
+
-v, --verbose Enables verbose spew (default: false)
|
|
146
|
+
-d, --debug Enables debug spew (default: false)
|
|
147
|
+
-t, --trace Enables trace spew (default: false)
|
|
148
|
+
--dev Enable dev mode, which prints stack traces with errors (default: false)
|
|
149
|
+
-p, --provider <name> AI provider to use for translations (anthropic, openai); overrides any 'provider' config setting
|
|
150
|
+
-h, --help display help for command
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
Usage: alt list-models [options]
|
|
154
|
+
|
|
155
|
+
Options:
|
|
156
|
+
-p, --provider <name> AI provider to use for translations (anthropic,
|
|
157
|
+
openai); overrides any 'provider' config setting
|
|
158
|
+
-h, --help display help for command
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
## Examples
|
|
@@ -166,12 +166,13 @@ Environment variables:
|
|
|
166
166
|
* Look for context keys starting with `_context:`
|
|
167
167
|
* Write output files to the current working directory
|
|
168
168
|
```bash
|
|
169
|
-
alt --reference-file loc.js
|
|
169
|
+
alt translate --reference-file loc.js
|
|
170
170
|
--reference-var-name data
|
|
171
171
|
--provider anthropic
|
|
172
172
|
--look-for-context-data
|
|
173
173
|
--context-prefix _context:
|
|
174
174
|
```
|
|
175
|
+
|
|
175
176
|
### Example II
|
|
176
177
|
* Import config from `./localization-config.json`
|
|
177
178
|
* Import from ``loc.js``
|
|
@@ -181,7 +182,7 @@ alt --reference-file loc.js
|
|
|
181
182
|
* Write to disk repeatedly, as changes are processed
|
|
182
183
|
* Write files to `./localization`
|
|
183
184
|
```bash
|
|
184
|
-
alt --config-file ./localization-config.json
|
|
185
|
+
alt translate --config-file ./localization-config.json
|
|
185
186
|
--reference-file loc.js
|
|
186
187
|
--output-dir localization
|
|
187
188
|
--provider openai
|
|
@@ -192,7 +193,7 @@ alt --config-file ./localization-config.json
|
|
|
192
193
|
* Overrides any config's languages
|
|
193
194
|
* Only process the specified strings
|
|
194
195
|
```bash
|
|
195
|
-
alt --config-file config.json
|
|
196
|
+
alt translate --config-file config.json
|
|
196
197
|
--reference-file reference.js
|
|
197
198
|
--output-dir localization
|
|
198
199
|
--provider openai
|
|
@@ -233,11 +234,5 @@ If you prefer to write updates to disk in real-time (anytime any output data cha
|
|
|
233
234
|
### CI
|
|
234
235
|
You may want to use `--tty` for more useful output.
|
|
235
236
|
|
|
236
|
-
##
|
|
237
|
-
|
|
238
|
-
- Add support for reference files in JSON format
|
|
239
|
-
- It'd be nice to rely on $LANG in POSIX, but I didn't find a clean and reliable conversion from POSIX to BCP47 when I did a cursory search, which includes edge cases
|
|
240
|
-
- Bug: If a user modifies a reference value, then runs and cancels, then runs again, any language/key values which would have been affected by the change will no longer be modified. The tool needs to detect these types of changes at a higher level than it is currently so that key/values can be deleted for all languages and written to disk, so that they're effectively missing and will have to be re-translated. The state that a reference value changed would be lost across runs of the tool, however, but at least the result would be a fix, with this approach.
|
|
241
|
-
- Tests :]
|
|
242
|
-
|
|
243
|
-
Feel free to submit a PR.
|
|
237
|
+
## Issues
|
|
238
|
+
Feel free to fix existing issues and submit a PR, or submit a new issue.
|