@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.
Files changed (97) hide show
  1. package/.github/workflows/test.yml +30 -0
  2. package/.mocharc.cjs +13 -0
  3. package/README.md +20 -11
  4. package/localization/.localization.cache.json +1248 -144
  5. package/localization/aa.json +9 -1
  6. package/localization/af.json +9 -1
  7. package/localization/agq.json +9 -1
  8. package/localization/ak.json +9 -1
  9. package/localization/am.json +9 -1
  10. package/localization/ar.json +9 -1
  11. package/localization/as.json +9 -1
  12. package/localization/asa.json +9 -1
  13. package/localization/ast.json +9 -1
  14. package/localization/az.json +9 -1
  15. package/localization/ba.json +9 -1
  16. package/localization/bas.json +9 -1
  17. package/localization/be.json +9 -1
  18. package/localization/bem.json +9 -1
  19. package/localization/bez.json +9 -1
  20. package/localization/bg.json +9 -1
  21. package/localization/bm.json +11 -1
  22. package/localization/bn.json +9 -1
  23. package/localization/bo.json +9 -1
  24. package/localization/br.json +9 -1
  25. package/localization/brx.json +9 -1
  26. package/localization/bs.json +9 -1
  27. package/localization/byn.json +9 -1
  28. package/localization/ca.json +9 -1
  29. package/localization/ccp.json +9 -1
  30. package/localization/cd-RU.json +9 -1
  31. package/localization/ceb.json +9 -1
  32. package/localization/cgg.json +9 -1
  33. package/localization/chr.json +9 -1
  34. package/localization/co.json +9 -1
  35. package/localization/cs.json +9 -1
  36. package/localization/cu-RU.json +9 -1
  37. package/localization/da.json +9 -1
  38. package/localization/de-AT.json +9 -1
  39. package/localization/de-CH.json +9 -1
  40. package/localization/de-DE.json +9 -1
  41. package/localization/dua.json +9 -1
  42. package/localization/dv.json +9 -1
  43. package/localization/dz.json +9 -1
  44. package/localization/ebu.json +12 -3
  45. package/localization/en.json +9 -1
  46. package/localization/es-ES.json +9 -1
  47. package/localization/es-MX.json +9 -1
  48. package/localization/et.json +9 -1
  49. package/localization/eu.json +9 -1
  50. package/localization/fr-CA.json +9 -1
  51. package/localization/fr-CH.json +9 -1
  52. package/localization/fr-FR.json +9 -1
  53. package/localization/gsw.json +9 -1
  54. package/localization/hi.json +9 -1
  55. package/localization/hr.json +9 -1
  56. package/localization/hy.json +9 -1
  57. package/localization/ja.json +9 -1
  58. package/localization/km.json +9 -1
  59. package/localization/ksf.json +9 -1
  60. package/localization/ku.json +10 -1
  61. package/localization/kw.json +9 -1
  62. package/localization/my.json +9 -1
  63. package/localization/nl.json +9 -1
  64. package/localization/prs.json +9 -1
  65. package/localization/reference.js +10 -1
  66. package/localization/ru.json +9 -1
  67. package/localization/sq.json +9 -1
  68. package/localization/swc.json +9 -1
  69. package/localization/th.json +9 -1
  70. package/localization/tzm-Latn-.json +9 -1
  71. package/localization/uk.json +9 -1
  72. package/localization/vi.json +11 -3
  73. package/localization/zh-Hans.json +9 -1
  74. package/localization/zh-Hant.json +11 -2
  75. package/npm-shrinkwrap.json +6498 -676
  76. package/package.json +19 -1
  77. package/src/commands/list-models.js +1 -0
  78. package/src/commands/translate.js +42 -9
  79. package/src/lib/config.js +1 -1
  80. package/src/lib/context-keys.js +12 -3
  81. package/src/lib/io.js +10 -3
  82. package/src/lib/reference-loader.js +1 -0
  83. package/src/main.mjs +2 -2
  84. package/test/README.md +37 -0
  85. package/test/common.mjs +29 -0
  86. package/test/config.test.js +78 -0
  87. package/test/fixtures/reference.js +5 -0
  88. package/test/fixtures/reference.json +5 -0
  89. package/test/fixtures/reference.jsonc +8 -0
  90. package/test/list-models.test.js +27 -0
  91. package/test/localization.test.js +124 -0
  92. package/test/main-cli.test.js +79 -0
  93. package/test/mocha.setup.js +10 -0
  94. package/test/translate-command.test.js +122 -0
  95. package/test/reference.js +0 -28
  96. package/test/reference.json +0 -28
  97. 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
+ [![Run Tests](https://github.com/drone1/alt/actions/workflows/test.yml/badge.svg)](https://github.com/drone1/alt/actions/workflows/test.yml)
1
2
  ![Claude](https://img.shields.io/badge/Anthropic-black?logo=anthropic&logoColor=white)
2
3
  ![ChatGPT](https://img.shields.io/badge/ChatGPT-74aa9c?logo=openai&logoColor=white)
3
4
  ![Gemini](https://img.shields.io/badge/Gemini-4285F4?logo=google&logoColor=white)
@@ -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, `ALT` will search the output directory for `config.json`, but you can specify a path directly using
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
- -l, --target-languages <list> Comma-separated list of language codes; overrides any 'targetLanguages' config setting
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
- When does ALT translate a given source string? Translation will occur for a given target language & reference key/value if any of the following are true:
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
- * A context value for the given target language/key is found and has been modified.
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 `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
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, `alt` will not write to disk until the tool is shutting down (including SIGTERM &ndash; yes, `Ctrl+C` is safe).
304
+ By default, ALT will not write to disk until the tool is shutting down (including SIGTERM &ndash; 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.