@drone1/alt 0.9.4 → 1.0.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.
- package/.github/workflows/test.yml +30 -0
- package/.mocharc.cjs +13 -0
- package/README.md +20 -11
- package/localization/.localization.cache.json +1248 -144
- package/localization/aa.json +9 -1
- package/localization/af.json +9 -1
- package/localization/agq.json +9 -1
- package/localization/ak.json +9 -1
- package/localization/am.json +9 -1
- package/localization/ar.json +9 -1
- package/localization/as.json +9 -1
- package/localization/asa.json +9 -1
- package/localization/ast.json +9 -1
- package/localization/az.json +9 -1
- package/localization/ba.json +9 -1
- package/localization/bas.json +9 -1
- package/localization/be.json +9 -1
- package/localization/bem.json +9 -1
- package/localization/bez.json +9 -1
- package/localization/bg.json +9 -1
- package/localization/bm.json +11 -1
- package/localization/bn.json +9 -1
- package/localization/bo.json +9 -1
- package/localization/br.json +9 -1
- package/localization/brx.json +9 -1
- package/localization/bs.json +9 -1
- package/localization/byn.json +9 -1
- package/localization/ca.json +9 -1
- package/localization/ccp.json +9 -1
- package/localization/cd-RU.json +9 -1
- package/localization/ceb.json +9 -1
- package/localization/cgg.json +9 -1
- package/localization/chr.json +9 -1
- package/localization/co.json +9 -1
- package/localization/cs.json +9 -1
- package/localization/cu-RU.json +9 -1
- package/localization/da.json +9 -1
- package/localization/de-AT.json +9 -1
- package/localization/de-CH.json +9 -1
- package/localization/de-DE.json +9 -1
- package/localization/dua.json +9 -1
- package/localization/dv.json +9 -1
- package/localization/dz.json +9 -1
- package/localization/ebu.json +12 -3
- package/localization/en.json +9 -1
- package/localization/es-ES.json +9 -1
- package/localization/es-MX.json +9 -1
- package/localization/et.json +9 -1
- package/localization/eu.json +9 -1
- package/localization/fr-CA.json +9 -1
- package/localization/fr-CH.json +9 -1
- package/localization/fr-FR.json +9 -1
- package/localization/gsw.json +9 -1
- package/localization/hi.json +9 -1
- package/localization/hr.json +9 -1
- package/localization/hy.json +9 -1
- package/localization/ja.json +9 -1
- package/localization/km.json +9 -1
- package/localization/ksf.json +9 -1
- package/localization/ku.json +10 -1
- package/localization/kw.json +9 -1
- package/localization/my.json +9 -1
- package/localization/nl.json +9 -1
- package/localization/prs.json +9 -1
- package/localization/reference.js +10 -1
- package/localization/ru.json +9 -1
- package/localization/sq.json +9 -1
- package/localization/swc.json +9 -1
- package/localization/th.json +9 -1
- package/localization/tzm-Latn-.json +9 -1
- package/localization/uk.json +9 -1
- package/localization/vi.json +11 -3
- package/localization/zh-Hans.json +9 -1
- package/localization/zh-Hant.json +11 -2
- package/npm-shrinkwrap.json +6498 -676
- package/package.json +19 -1
- package/src/commands/list-models.js +1 -0
- package/src/commands/translate.js +42 -9
- package/src/lib/config.js +1 -1
- package/src/lib/context-keys.js +12 -3
- package/src/lib/io.js +10 -3
- package/src/lib/reference-loader.js +1 -0
- package/src/main.mjs +2 -2
- package/test/README.md +37 -0
- package/test/common.mjs +29 -0
- package/test/config.test.js +78 -0
- package/test/fixtures/reference.js +5 -0
- package/test/fixtures/reference.json +5 -0
- package/test/fixtures/reference.jsonc +8 -0
- package/test/list-models.test.js +27 -0
- package/test/localization.test.js +124 -0
- package/test/main-cli.test.js +79 -0
- package/test/mocha.setup.js +10 -0
- package/test/translate-command.test.js +122 -0
- package/test/reference.js +0 -28
- package/test/reference.json +0 -28
- package/test/reference.jsonc +0 -29
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Run Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ '**' ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v3
|
|
15
|
+
|
|
16
|
+
- name: Setup Node.js
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: 'lts/*'
|
|
20
|
+
cache: 'npm'
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: npm ci
|
|
24
|
+
|
|
25
|
+
- name: Run tests
|
|
26
|
+
run: npm run test
|
|
27
|
+
env:
|
|
28
|
+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
29
|
+
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
|
|
30
|
+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
package/.mocharc.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Mocha configuration file
|
|
2
|
+
module.exports = {
|
|
3
|
+
require: 'test/mocha.setup.js',
|
|
4
|
+
spec: 'test/**/*.test.js',
|
|
5
|
+
'node-option': [
|
|
6
|
+
'experimental-vm-modules',
|
|
7
|
+
'no-warnings'
|
|
8
|
+
],
|
|
9
|
+
timeout: 10000,
|
|
10
|
+
recursive: true,
|
|
11
|
+
parallel: false,
|
|
12
|
+
color: true
|
|
13
|
+
}
|
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
[](https://github.com/drone1/alt/actions/workflows/test.yml)
|
|
1
2
|

|
|
2
3
|

|
|
3
4
|

|
|
@@ -99,7 +100,7 @@ Sample output:
|
|
|
99
100
|
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`
|
|
100
101
|
|
|
101
102
|
## Config file
|
|
102
|
-
[_optional_] You can create a config file. By default,
|
|
103
|
+
[_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
|
|
103
104
|
`--config-file`.
|
|
104
105
|
Example
|
|
105
106
|
config:
|
|
@@ -172,6 +173,7 @@ Commands:
|
|
|
172
173
|
Environment variables:
|
|
173
174
|
ANTHROPIC_API_KEY Your Anthropic API key
|
|
174
175
|
OPENAI_API_KEY Your OpenAI API key
|
|
176
|
+
GOOGLE_API_KEY Your Google Gemini API key
|
|
175
177
|
ALT_LANGUAGE BCP47 language tag used for display
|
|
176
178
|
|
|
177
179
|
---
|
|
@@ -183,23 +185,23 @@ Options:
|
|
|
183
185
|
-c, --config-file <path> Path to config file; defaults to <output dir>/config.json
|
|
184
186
|
-rl, --reference-language <language> The reference file's language; overrides any 'referenceLanguage' config setting
|
|
185
187
|
-o, --output-dir <path> Output directory for localized files
|
|
186
|
-
-
|
|
188
|
+
-tl, --target-languages <list> Comma-separated list of language codes; overrides any 'targetLanguages' config setting
|
|
187
189
|
-k, --keys <list> Comma-separated list of keys to process
|
|
188
190
|
-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")
|
|
189
191
|
-m, --app-context-message <message> Description of your app to give context. Passed with each translation request; overrides any 'appContextMessage' config setting
|
|
190
192
|
-f, --force Force regeneration of all translations (default: false)
|
|
191
193
|
-rtw, --realtime-writes Write updates to disk immediately, rather than on shutdown (default: false)
|
|
192
194
|
-y, --tty Use tty/simple renderer; useful for CI (default: false)
|
|
193
|
-
-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
|
|
195
|
+
-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
|
|
194
196
|
-x, --max-retries <integer> Maximum retries on failure (default: 3)
|
|
195
197
|
-n, --normalize-output-filenames Normalizes output filenames (to all lower-case); overrides any 'normalizeOutputFilenames' in config setting (default: false)
|
|
196
198
|
-N, --no-logo Suppress logo printout
|
|
197
199
|
-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
|
|
198
200
|
-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
|
|
199
201
|
-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)
|
|
200
|
-
-v, --verbose Enables verbose spew (default: false)
|
|
201
|
-
-d, --debug Enables debug spew (default: false)
|
|
202
|
-
-t, --trace Enables trace spew (default: false)
|
|
202
|
+
-v, --verbose Enables verbose spew; forces --tty mode (default: false)
|
|
203
|
+
-d, --debug Enables debug spew; forces --tty mode (default: false)
|
|
204
|
+
-t, --trace Enables trace spew; forces --tty mode (default: false)
|
|
203
205
|
--dev Enable dev mode, which prints stack traces with errors (default: false)
|
|
204
206
|
-p, --provider <name> AI provider to use for translations (anthropic, openai); overrides any 'provider' config setting
|
|
205
207
|
-h, --help display help for command
|
|
@@ -212,7 +214,7 @@ Options:
|
|
|
212
214
|
-p, --provider <name> AI provider to use for translations (anthropic,
|
|
213
215
|
openai); overrides any 'provider' config setting
|
|
214
216
|
-h, --help display help for command
|
|
215
|
-
```
|
|
217
|
+
```
|
|
216
218
|
|
|
217
219
|
## Examples
|
|
218
220
|
### Example I
|
|
@@ -279,20 +281,27 @@ Internally, there is currently nothing in the prompt about this. I've tested wit
|
|
|
279
281
|
Please submit an issue if it causes you any trouble.
|
|
280
282
|
|
|
281
283
|
## Translation rules
|
|
282
|
-
|
|
284
|
+
Under what conditions will ALT translate a given source string?
|
|
285
|
+
|
|
286
|
+
Translation will occur for a given target language & reference key/value if any of the following are true:
|
|
287
|
+
|
|
283
288
|
* The output file does not exist
|
|
289
|
+
* Example: You're translating to target language _zh-Hans_ and `zh-Hans.json` doesn't exist
|
|
284
290
|
* The output file is missing the reference key
|
|
291
|
+
* Example: You're translating reference key _error-msg_ to target language _zh-Hant.jso_ and `zh-Hans.json` does not have a key/value pair for key _error-msg_
|
|
285
292
|
* The reference value was modified
|
|
286
|
-
*
|
|
293
|
+
* Example: You change the value of _some-key_ in your reference file
|
|
294
|
+
* A context value for the given target language/key is found and has been modified
|
|
295
|
+
* Example: You modify the value of _context:error-msg_ in your reference file. _error-msg_ will be re-translated for all target languages.
|
|
287
296
|
* `-f` or `--force` are specified
|
|
288
297
|
* The cache file (`.localization.cache.json`) is not present
|
|
289
298
|
|
|
290
|
-
Translation will _not_ occur if
|
|
299
|
+
NOTE: 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
|
|
291
300
|
later, you can just delete that key/value pair from the given file.
|
|
292
301
|
|
|
293
302
|
## Additional notes
|
|
294
303
|
### Delayed vs. realtime writes
|
|
295
|
-
By default,
|
|
304
|
+
By default, ALT will not write to disk until the tool is shutting down (including SIGTERM – yes, `Ctrl+C` is safe).
|
|
296
305
|
|
|
297
306
|
This behavior is useful if your application is monitoring the output directory and you don't want your server
|
|
298
307
|
constantly restarting, for example.
|