@publishpress/potomatic 0.0.0-stage → 1.4.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,127 @@
1
+ # Changelog
2
+
3
+ PublishPress forked [GravityKit Potomatic](https://github.com/GravityKit/Potomatic) at version 1.3.0. PublishPress released **1.4.0** as the first version of this fork. Versions 1.3.0 and earlier are GravityKit releases. The npm package name is `@publishpress/potomatic`.
4
+
5
+ ## 1.4.5 — 2026-11-27
6
+
7
+ ### Fixed
8
+
9
+ * Prettier on `src/config/index.js` so the npm publish workflow passes `prepublishOnly`.
10
+
11
+ ## 1.4.4 — 2026-11-27
12
+
13
+ ### Changed
14
+
15
+ * npm publish workflow and `docs/npm.md` for the `publishpress` org and `developers` team.
16
+
17
+ ## 1.4.3 — 2026-11-27
18
+
19
+ ### Changed
20
+
21
+ * Published on [npmjs.com](https://www.npmjs.com/package/@publishpress/potomatic) under the `publishpress` org. Grant the `developers` team with `npm access grant` (see `docs/npm.md`).
22
+
23
+ * The README and the changelog state the fork point. PublishPress forked GravityKit Potomatic at 1.3.0. The first PublishPress release is 1.4.0.
24
+
25
+ ## 1.4.2 — 2026-11-27
26
+
27
+ ### Changed
28
+
29
+ * npm package name is `@publishpress/potomatic`. That name is this fork. It is not the `potomatic` package on npmjs.com.
30
+
31
+ ## 1.4.1 — 2026-11-19
32
+
33
+ ### Fixed
34
+
35
+ * GPT-5.6 rates now match the current standard short-context prices. `gpt-5.6-sol` is $4 / $20, `gpt-5.6-terra` is $2 / $12, and `gpt-5.6-luna` is $0.20 / $1.20 per 1M tokens. The other catalogue rates already matched that list.
36
+
37
+ ## 1.4.0 — 2026-11-19
38
+
39
+ First PublishPress release. The fork starts from [GravityKit Potomatic 1.3.0](https://github.com/GravityKit/Potomatic/releases/tag/v1.3.0).
40
+
41
+ ### Added
42
+
43
+ * GPT-6 chat models in the price catalogue: `gpt-6-luna`, `gpt-6-sol`, `gpt-6-astra`, `gpt-6.1-terra`, `gpt-6.1-sol`, `gpt-6.2-sol`, and `gpt-6.2-astra`. Rates are the standard short-context prices.
44
+ * `--reasoning-effort` (or `REASONING_EFFORT`) sends `reasoning_effort` on the Chat Completions request. Leave it unset to keep the previous request. `none` also sends `temperature` and skips the reasoning token headroom. Any other value omits `temperature`.
45
+
46
+ ## 1.3.0 — 2026-07-28
47
+
48
+ Upstream [GravityKit Potomatic](https://github.com/GravityKit/Potomatic/releases/tag/v1.3.0) release. PublishPress forked this version. Entries from 1.3.0 through 1.0.0 are GravityKit releases.
49
+
50
+ ### Upgrade notes
51
+
52
+ No flags, environment variables or model names were removed, but three behaviours change:
53
+
54
+ * **A partly translated run now exits `1` instead of `0`.** Previously only a run with no successful translations at all failed, so a `.po` with untranslated strings still reported success. Check any pipeline that treats a non-zero exit as fatal.
55
+ * **The default model is now `gpt-5.4-mini`.** Output and per-token rates both change: against this pricing table, input is 87.5% higher and output 181.25% higher. Pin the previous behaviour with `--model gpt-4.1-mini` or `MODEL=gpt-4.1-mini`.
56
+ * **GPT-5 models now work.** A configuration naming one previously failed every request; it will now do real, billable work.
57
+
58
+ ### Added
59
+
60
+ * `--allow-unknown-model` (or `ALLOW_UNKNOWN_MODEL=true`) accepts a model that is not in the pricing catalogue, costed at the fallback rate. Without it, a model missing from `config/openai-pricing.json` is rejected, which would otherwise mean waiting for a release to use a newly published model.
61
+
62
+ ### Fixed
63
+
64
+ * GPT-5 models could not be used at all. Every request sent `max_tokens`, which the GPT-5 and o-series families reject. Requests now send `max_completion_tokens` for those models and keep `max_tokens` for the supported GPT-4.1 models.
65
+ * `temperature` is now omitted for models that accept only the default value (the GPT-5.6 and GPT-5.5 families, the GPT-5 base family, and the o-series), which previously failed the request outright.
66
+ * Reasoning models were starved of completion budget. The token limit was sized from estimated visible output, but on the `max_completion_tokens` path that same limit also pays for hidden reasoning, which is largely fixed rather than proportional to the batch. Small batches therefore truncated: in our tested configurations `gpt-5-nano` and `gpt-5-mini` failed every run at batch sizes 1 to 5 while batches of 10 or more succeeded. Those models now get a flat headroom allowance. Raising the limit is not prepaid, though any extra tokens a model does generate are billable.
67
+ * A truncated response was parsed as zero translations and written out as blank strings while the run reported success. Truncation is now detected via `finish_reason` and fails the batch without retrying, since an unchanged retry is unlikely to help and incurs another charge.
68
+ * Potomatic's parser required an exact `<f0>` tag, so a malformed opening tag such as `<f0">` sent the entry down the singular path and blanked every plural form, shipping it untranslated. Form tags are now matched tolerantly while still requiring the tag name to end, so `<f10>` is not read as form 1 and `<f0evil>` is not read as form 0.
69
+ * Token counting fell back to a rough `length / 4` estimate for GPT-5 names that tiktoken does not recognise. It now falls back to the `o200k_base` encoding those models use, which matches the API's own token accounting exactly in our tests.
70
+ * Token encoders were rebuilt after every successfully returned response, costing roughly 60 ms each. They are now created once per model and shared.
71
+ * `--temperature 0` and `TEMPERATURE=0` were silently replaced by the default, because zero was treated as unset.
72
+ * The A/B prompt tool crashed with `translations.map is not a function` on every run, because it treated the `{ translations, validationStats }` object returned by `parseXmlResponse()` as an array.
73
+
74
+ ### Changed
75
+
76
+ * Documentation no longer describes providers other than OpenAI. The README and `.env.example` advertised Gemini and Anthropic keys with automatic provider detection, but `--provider gemini` fails outright and a `GEMINI_API_KEY` was only ever used as an OpenAI key. The `--provider` flag still works for `openai` and is now hidden from `--help` until there is a second provider to choose.
77
+ * OpenAI models and pricing updated to July 2026, adding the GPT-5.6 (Sol, Terra, Luna) and GPT-5.5 tiers.
78
+ * The model catalogue lists only models the chat completions endpoint serves, which excludes the `-pro` tiers. None of them were listed in 1.2.0, so no existing configuration is affected.
79
+ * `tiktoken` updated to 1.0.22, which recognises more model names directly. Counts are unchanged, since every name it knows resolves to the same `o200k_base` encoding used for the rest.
80
+ * The `ab-prompt-test` npm script has been removed. `tools/` is not published, so the script pointed at a file that was never in the package; run `node tools/ab-prompt-test` from a checkout instead.
81
+ * A batch that failed after being billed now reports what it cost instead of zero, so `--max-cost` accounts for it, and the failure message states the number of attempts actually made.
82
+ * The A/B prompt tool no longer hardcodes its two models, which were outside the supported catalogue. Models, temperatures and target language are set with `AB_MODEL_A`, `AB_MODEL_B`, `AB_TEMP_A`, `AB_TEMP_B` and `AB_LANG`.
83
+
84
+ ## 1.2.0 — 2026-04-06
85
+
86
+ ### Fixed
87
+
88
+ * Output directory was not being created when saving .po files if it didn't exist.
89
+
90
+ ### Added
91
+
92
+ * Post-translation validation that catches placeholder mismatches, non-breaking space issues, and plural form errors - blanking bad translations for automatic retry.
93
+ * New `--extra-prompt-path` CLI flag to append domain-specific prompt content without replacing the base prompt.
94
+ * Language-specific plural form guidance in the default prompt (Arabic 6-form, Russian 3-form, French 2-form, Japanese 1-form).
95
+ * XML source elements now include a `placeholders` attribute listing expected placeholders for LLM verification.
96
+
97
+ ### Changed
98
+
99
+ * Update OpenAI models and pricing to April 2026.
100
+ * Default model changed from `gpt-4o-mini` to `gpt-4.1-mini`.
101
+ * Hardened default prompt with explicit negative examples for placeholder preservation.
102
+ * Blanked translation details now logged at warn level instead of debug.
103
+
104
+ ## 1.1.0 — 2025-11-12
105
+
106
+ ### Fixed
107
+
108
+ * Fix plural-form translations in languages with complex rules (e.g., Arabic, Russian,).
109
+ * Treat environment variables such as `FORCE_TRANSLATE=false` correctly instead of interpreting them as `true`.
110
+ * Ensure configuration files are detected when running Potomatic from paths containing spaces (such as `~/Local Sites/`) and on Windows systems.
111
+
112
+ ### Added
113
+
114
+ * Support multiple API key formats (`OPENAI_API_KEY`, `POTOMATIC_OPENAI_API_KEY`, etc.) with automatic provider detection based on the key name.
115
+ * Add CLI options `--prompt-file-path` and `--po-header-template-path` to customize the locations of translation prompt and header template files.
116
+
117
+ ### Changed
118
+
119
+ * Update OpenAI pricing data to reflect current model costs (November 2025).
120
+
121
+ ## 1.0.1 — 2025-06-27
122
+
123
+ * Version bump for [npm release](https://www.npmjs.com/package/potomatic).
124
+
125
+ ## 1.0.0 — 2025-06-27
126
+
127
+ * Initial release.
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2025 Katz Web Services, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,471 @@
1
- # Temporary Holding Version
1
+ # Potomatic
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <div align="center">
4
+ <img src="assets/terminal.gif" alt="Animated image showing Potomatic in action" width="800">
5
+ </div>
6
+
7
+ <br />
8
+
9
+ ## Fork
10
+
11
+ This repository is the PublishPress fork of [Potomatic](https://github.com/GravityKit/Potomatic).
12
+
13
+ GravityKit released [Potomatic 1.3.0](https://github.com/GravityKit/Potomatic/releases/tag/v1.3.0). PublishPress forked that version.
14
+
15
+ PublishPress released **1.4.0** as the first version of this fork. The npm package name is `@publishpress/potomatic`.
16
+
17
+ Install from npmjs.com (PublishPress org):
18
+
19
+ ```bash
20
+ npm install @publishpress/potomatic
21
+ ```
22
+
23
+
24
+ The GravityKit npm package name is `potomatic`.
25
+
26
+ **Potomatic** is a command-line tool for translating `.pot` (Portable Object Template) files into multiple languages using AI (currently OpenAI). GravityKit built it to streamline large-scale localization of WordPress products. GravityKit describes that work in [this article](https://www.gravitykit.com/translating-wordpress-plugins-using-chatgpt/).
27
+
28
+ [`gpt-po`](https://github.com/ryanhex53/gpt-po) was the start for GravityKit. GravityKit then added retry logic, cost controls, job visibility, and an [A/B testing utility](#ab-testing-for-prompt-optimization) for prompt tuning.
29
+
30
+ ## Disclaimer
31
+
32
+ Translation quality varies depending on factors such as model selection, prompt design, and the complexity of the source text. **Potomatic** can generate a baseline translation, but the output should always be reviewed and verified before use.
33
+
34
+ For improved results, consider refining your prompt, using a higher-tier model, or consulting a professional translator to ensure accuracy and quality.
35
+
36
+ ---
37
+
38
+ ## Table of Contents
39
+
40
+ * [Fork](#fork)
41
+ * [Key Features](#key-features)
42
+ * [Prerequisites](#prerequisites)
43
+ * [Setup](#setup)
44
+ * [Quick Usage](#quick-usage)
45
+ * [User Dictionaries](#user-dictionaries)
46
+ * [Example Commands](#example-commands)
47
+ * [Dry‑run (no API calls)](#dryrun-no-api-calls)
48
+ * [Cost and string limits](#cost-and-string-limits)
49
+ * [Advanced options](#advanced-options)
50
+ * [WordPress plugin](#wordpress-plugin)
51
+ * [JSON output](#json-output)
52
+ * [CLI Options Reference](#cli-options-reference)
53
+ * [Supported Languages](#supported-languages)
54
+ * [Configuration Files](#configuration-files)
55
+ * [Available Scripts](#available-scripts)
56
+ * [A/B Testing for Prompt Optimization](#ab-testing-for-prompt-optimization)
57
+ * [Acknowledgments](#acknowledgments)
58
+
59
+ ---
60
+
61
+ ## Key Features
62
+
63
+ * **AI‑powered translations** – Translate into any language supported by OpenAI models.
64
+ * **Smart batch handling** – Tune batch size, concurrency and retries for the right balance of cost and speed.
65
+ * **Cost‑conscious execution** – Accurately estimate costs and tokens, and control the maximum cost of a job.
66
+ * **Incremental & resumable workflows** – Resume interrupted jobs, merge with existing `.po` files, or force a re‑translation.
67
+ * **Custom dictionaries** – Supply term mappings for consistent brand and technical vocabulary.
68
+ * **Plural‑forms support** – Automatic plural rules for languages that require different word forms based on quantity.
69
+ * **Dry‑run mode** – Preview translations and cost without making API calls.
70
+ * **Detailed progress tracking** – Real‑time stats with four verbosity levels.
71
+ * **Flexible output** – Console or JSON, with optional raw API logs for debugging.
72
+ * **Everything is a flag** – Every knob exposed via CLI flags *and* env vars.
73
+
74
+ ---
75
+
76
+ ## Prerequisites
77
+
78
+ Before using **Potomatic**, you need a `.pot` file containing the source strings to translate.
79
+
80
+ ### Creating a POT file
81
+
82
+ **For WordPress plugin/theme authors**: Use [WP-CLI's i18n command](https://developer.wordpress.org/cli/commands/i18n/make-pot/):
83
+
84
+ ```bash
85
+ wp i18n make-pot /path/to/your-plugin /path/to/your-plugin/languages/your-plugin.pot
86
+ ```
87
+
88
+ **For non-WordPress projects**: Use [gettext](https://www.gnu.org/software/gettext/) tools to extract strings from your source code:
89
+
90
+ ```bash
91
+ # For Python projects (using _() or gettext() functions)
92
+ xgettext --language=Python --keyword=_ --keyword=gettext --output=translations.pot *.py
93
+
94
+ # For JavaScript/Node.js projects
95
+ xgettext --language=JavaScript --keyword=_ --keyword=gettext --output=translations.pot *.js
96
+
97
+ # For PHP projects (specify which functions to extract)
98
+ xgettext --language=PHP --keyword=__ --keyword=_e --keyword=_n:1,2 --output=translations.pot *.php
99
+
100
+ # For multiple file types in a directory
101
+ find . -iname "*.php" -o -iname "*.js" -o -iname "*.py" | xgettext --files-from=- --output=translations.pot
102
+ ```
103
+
104
+ **Note**: The `--keyword` option tells xgettext which function names to look for when extracting translatable strings. Common options include `_()`, `gettext()`, `__()`, `_e()`, and `_n()` depending on your framework.
105
+
106
+ These tools will scan your project and extract all translatable strings into a POT file that **Potomatic** can then use to generate translations.
107
+
108
+ ---
109
+
110
+ ## Setup
111
+
112
+ 1. **Install dependencies**
113
+
114
+ ```bash
115
+ npm install
116
+ ```
117
+
118
+ 2. **(Optional) Create a `.env` file** for convenience:
119
+
120
+ ```bash
121
+ # Copy the template and customize it
122
+ cp .env.example
123
+
124
+ # Or create manually with your settings
125
+ echo "OPENAI_API_KEY=your-api-key-here" > .env
126
+ echo "TARGET_LANGUAGES=fr_FR,es_ES" >> .env
127
+ echo "POT_FILE_PATH=path/to/your/file.pot" >> .env
128
+ ```
129
+
130
+ **Note**: All settings can be provided via CLI arguments.
131
+
132
+ 3. **Run**
133
+
134
+ ```bash
135
+ ./potomatic
136
+ # or
137
+ npm run translate
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Quick Usage
143
+
144
+ ```bash
145
+ # Translate French and Spanish using defaults
146
+ ./potomatic -l fr_FR,es_ES -p translations.pot -k $OPENAI_API_KEY
147
+
148
+ # Preview only (no API calls, cost estimate shown)
149
+ ./potomatic --dry-run -l fr_FR -p translations.pot
150
+ ```
151
+
152
+ ---
153
+
154
+ ## User Dictionaries
155
+
156
+ Custom dictionaries are supported to maintain consistency in the translation of brand names, technical terms, domain-specific language, etc.
157
+
158
+ ### File layout
159
+
160
+ ```
161
+ config/
162
+ └─ dictionaries/
163
+ ├─ dictionary.json # fallback for every language
164
+ ├─ dictionary-fr.json # language fallback
165
+ └─ dictionary-fr-fr.json # exact locale match
166
+ ```
167
+
168
+ Each dictionary file is a plain JSON object:
169
+
170
+ ```json
171
+ {
172
+ "WordPress": "WordPress",
173
+ "Gravity Forms": "Gravity Forms",
174
+ "REST API": "REST API",
175
+ "Block Editor": "Block Editor",
176
+ "Multisite": "Multisite"
177
+ }
178
+ ```
179
+
180
+ Using this example, "Block Editor" and other terms will not be translated to target language(s).
181
+
182
+ ### CLI switches
183
+
184
+ | Flag | Env | Description | Default |
185
+ | ------------------------- | ----------------- | ------------------------------- | ----------------------- |
186
+ | `--dictionary-path <dir>` | `DICTIONARY_PATH` | Directory with dictionary files | `./config/dictionaries` |
187
+ | `--use-dictionary` | `USE_DICTIONARY` | Enable dictionary system | disabled |
188
+
189
+ ```bash
190
+ ./potomatic -l fr_FR -p translations.pot --use-dictionary --dictionary-path ./my-dicts
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Example Commands
196
+
197
+ ### Dry‑run (no API calls)
198
+
199
+ ```bash
200
+ ./potomatic --dry-run -l fr_FR -p translations.pot
201
+ ./potomatic --dry-run -l fr_FR,es_ES -p translations.pot --max-strings-per-job 10
202
+ ```
203
+
204
+ ### Cost and string limits
205
+
206
+ ```bash
207
+ ./potomatic -l fr_FR,es_ES -p translations.pot --max-cost 1.00
208
+ ./potomatic -l fr_FR -p translations.pot --max-strings-per-job 50
209
+ ./potomatic -l fr_FR,es_ES,de_DE -p translations.pot --max-total-strings 150
210
+ ./potomatic -l fr_FR,es_ES,de_DE -p translations.pot --max-total-strings 150 --max-strings-per-job 20 --max-cost 1.00
211
+ ```
212
+
213
+ ### Advanced options
214
+
215
+ ```bash
216
+ # Larger batches, more parallelism
217
+ ./potomatic -l fr_FR -p translations.pot --batch-size 30 --jobs 3
218
+
219
+ # Force overwrite existing translations
220
+ ./potomatic -l fr_FR -p translations.pot --force-translate
221
+
222
+ # Merge with an existing .po file
223
+ ./potomatic -l fr_FR -p translations.pot --input-po-path existing.po
224
+
225
+ # Custom output directory, prefix, and locale format (this will save "output/app-fr_FR.po")
226
+ ./potomatic -l fr_FR -p translations.pot -o output/ \
227
+ --po-file-prefix app- --locale-format wp_locale
228
+
229
+ # Verbose logging + save raw API responses
230
+ ./potomatic -l fr_FR -p translations.pot --verbose-level 3 --save-debug-info
231
+ ```
232
+
233
+ ### WordPress plugin
234
+
235
+ ```bash
236
+ # Translate a WordPress plugin using a .pot file and save translations to `languages/`
237
+ ./potomatic \
238
+ --target-languages fr_FR,es_ES \
239
+ --pot-file-path translations.pot \
240
+ --output-dir languages/ \
241
+ --po-file-prefix your-plugin-text-domain-
242
+ ```
243
+
244
+ ### JSON output
245
+
246
+ ```bash
247
+ ./potomatic -l fr_FR -p translations.pot --output-format json
248
+ ./potomatic -l fr_FR -p translations.pot --output-format json --output-file results.json
249
+ ```
250
+
251
+ ---
252
+
253
+ ## CLI Options Reference
254
+
255
+ ### Required Options
256
+
257
+ | Option | Short | Description | Default |
258
+ | -------------------------------- | ----- | --------------------------------------------------------------- | ------- |
259
+ | `--target-languages <languages>` | `-l` | Target language codes, comma-separated. **Accepts multiple formats**: WordPress locale (`fr_FR`, `es_ES`), ISO 639-1 (`fr`, `es`), ISO 639-2 (`fra`, `spa`), or language names (`French`, `Spanish`). See [supported languages](#supported-languages) below. | - |
260
+ | `--pot-file-path <path>` | `-p` | Path to the input `.pot` file containing source strings | - |
261
+ | `--api-key <key>` | `-k` | OpenAI API key (precedence: CLI > `POTOMATIC_OPENAI_API_KEY` > `OPENAI_API_KEY` > `POTOMATIC_API_KEY` > `API_KEY`) | - |
262
+
263
+ ### API Key
264
+
265
+ Potomatic translates through OpenAI. Set your key with `--api-key`, or in the environment:
266
+
267
+ | Variable | Notes |
268
+ | ------------------------ | ------------------------------------------------ |
269
+ | `OPENAI_API_KEY` | Standard key, shared with other tools |
270
+ | `POTOMATIC_OPENAI_API_KEY` | Use a different key for Potomatic than for everything else |
271
+
272
+ `--api-key` takes precedence over both. A key is required unless you pass `--dry-run`.
273
+
274
+ ### Model Settings
275
+
276
+ | Option | Short | Description | Default |
277
+ | -------------------------- | ----- | ------------------------------------------------------------------------------------- | --------------- |
278
+ | `--model <model>` | `-m` | AI model name (e.g., "gpt-5.4-mini") | `gpt-5.4-mini` |
279
+ | `--temperature <number>` | - | Creativity level (0.0-2.0); ignored by models that accept only their default | `0.7` |
280
+ | `--reasoning-effort <level>` | - | `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`. Omit to keep the model default. `none` sends temperature and skips reasoning headroom | unset |
281
+ | `--max-tokens <number>` | - | Completion-token limit (1-32768); reasoning models get extra headroom automatically | Auto-calculated |
282
+ | `--allow-unknown-model` | - | Accept a model that is not in the pricing catalogue, costed at the fallback rate | `false` |
283
+ | `--source-language <lang>` | `-s` | Source language code (default: "en") | `en` |
284
+
285
+ ### File Output Settings
286
+
287
+ | Option | Short | Description | Default |
288
+ | --------------------------- | ----- | ---------------------------------------------------------------------------------------------------------------------- | ------------- |
289
+ | `--output-dir <path>` | `-o` | Directory to save generated `.po` files for each language | `.` |
290
+ | `--output-format <format>` | - | Output format: `console` or `json` (default: console) | `console` |
291
+ | `--output-file <path>` | - | Path to save JSON output (use stdout if not provided) | - |
292
+ | `--po-file-prefix <prefix>` | - | Prefix for each output `.po` file (e.g., "app-" → "app-fr_FR.po") | - |
293
+ | `--locale-format <format>` | - | **Controls output filename format only** (not input). Options: `wp_locale` (ru_RU), `iso_639_1` (ru), `iso_639_2` (rus), or `target_lang` (uses input format as-is) | `target_lang` |
294
+
295
+ ### Translation Behavior
296
+
297
+ | Option | Short | Description | Default |
298
+ | ------------------------ | ----- | ------------------------------------------------------------- | ------- |
299
+ | `--force-translate` | `-F` | Re-translate all strings, ignoring any existing translations | `false` |
300
+ | `--input-po-path <path>` | - | Path to an existing `.po` file to use as a base for merging | - |
301
+ | `--dictionary-path <path>` | - | Directory containing dictionary files for consistent translations | `./config/dictionaries` |
302
+ | `--use-dictionary` | - | Use the dictionary system for consistent translations | `false` |
303
+
304
+ ### Configuration Files
305
+
306
+ | Option | Short | Description | Default |
307
+ | ----------------------------------- | ----- | ------------------------------------------------------------------------------- | ------------------------ |
308
+ | `--prompt-file-path <path>` | - | Path to the prompt.md file containing translation instructions | `./config/prompt.md` |
309
+ | `--po-header-template-path <path>` | - | Path to the po-header.json file containing custom PO file headers | `./config/po-header.json`|
310
+
311
+ ### Performance & Concurrency
312
+
313
+ | Option | Short | Description | Default |
314
+ | ----------------------- | ----- | -------------------------------------------------------------------------------------------------------------- | ------- |
315
+ | `--batch-size <number>` | `-b` | Number of strings per translation batch (1-100). Larger batches reduce cost but increase risk of API failures. | `20` |
316
+ | `--jobs <number>` | `-j` | Maximum number of languages to translate in parallel (1-10) | `2` |
317
+ | `--timeout <number>` | - | Timeout for API requests in seconds (10-300) | `60` |
318
+
319
+ ### Processing Limits
320
+
321
+ | Option | Short | Description | Default |
322
+ | -------------------------------- | ----- | --------------------------------------------------------------------------------------- | ------- |
323
+ | `--max-strings-per-job <number>` | - | Limit the number of strings translated per language (for testing) | - |
324
+ | `--max-total-strings <number>` | - | Limit total number of strings translated across all languages (processed sequentially) | - |
325
+ | `--max-cost <number>` | - | Limit total estimated translation cost in USD | - |
326
+
327
+ ### Error Handling & Retries
328
+
329
+ | Option | Short | Description | Default |
330
+ | ----------------------------- | ----- | ---------------------------------------------------------------------------------- | ------- |
331
+ | `--max-retries <number>` | - | Number of retry attempts per batch (0-10) | `3` |
332
+ | `--retry-delay <number>` | - | Delay between retry attempts in milliseconds (500-30000) | `2000` |
333
+ | `--abort-on-failure` | - | Abort the entire translation run if any batch fails all retry attempts | `false` |
334
+ | `--skip-language-on-failure` | - | Skip current language on failure and continue with remaining languages | `false` |
335
+
336
+ ### Development & Debugging
337
+
338
+ | Option | Short | Description | Default |
339
+ | ------------------------- | ----- | ---------------------------------------------------------------------------------------------- | ------- |
340
+ | `--verbose-level <level>` | `-v` | Verbosity level: 0=errors, 1=normal, 2=verbose, 3=debug | `1` |
341
+ | `--dry-run` | - | Simulate translation without making actual API calls | `false` |
342
+ | `--save-debug-info` | - | Save detailed request/response logs to timestamped files in the `debug/` directory | `false` |
343
+
344
+ ### Testing & Simulation
345
+
346
+ | Option | Short | Description | Default |
347
+ | ---------------------------------- | ----- | -------------------------------------------------------------------------- | ------- |
348
+ | `--test-retry-failure-rate <rate>` | - | [Testing] Simulate API failure rate (0.0-1.0) to test retry logic | - |
349
+ | `--test-allow-complete-failure` | - | [Testing] Allow complete failure of a batch (disables final fallback) | `false` |
350
+
351
+ ### General
352
+
353
+ | Option | Short | Description | Default |
354
+ | ----------- | ----- | ------------------------- | ------- |
355
+ | `--version` | `-V` | Output the version number | - |
356
+ | `--help` | `-h` | Display help for command | - |
357
+
358
+ **Note**: All options can also be set via environment variables. Environment variable names typically match the CLI option names in UPPER_CASE format (e.g., `--max-cost` becomes `MAX_COST`, `--retry-delay` becomes `RETRY_DELAY`).
359
+
360
+ ---
361
+
362
+ ## Supported Languages
363
+
364
+ **Potomatic** supports a wide range of languages (including regional variants) and accepts multiple input formats. You can specify target languages using any of the following formats:
365
+
366
+ ### Input Formats (for `--target-languages`)
367
+
368
+ - **WordPress locale format**: `fr_FR`, `es_ES`, `de_DE`, `pt_BR`, `zh_CN`
369
+ - **ISO 639-1 codes** (2-letter): `fr`, `es`, `de`, `pt`, `zh`
370
+ - **ISO 639-2 codes** (3-letter): `fra`, `spa`, `deu`, `por`, `zho`
371
+ - **BCP-47 format** (with dash): `fr-FR`, `es-ES`, `de-DE`
372
+ - **Language names**: `French`, `Spanish`, `German`, `Portuguese`, `Chinese`
373
+
374
+ **Example**: All of the following specify French:
375
+ ```bash
376
+ ./potomatic -l fr_FR -p translations.pot
377
+ ./potomatic -l fr -p translations.pot
378
+ ./potomatic -l fra -p translations.pot
379
+ ./potomatic -l "French" -p translations.pot
380
+ ```
381
+
382
+ ### Output Formats (for `--locale-format`)
383
+
384
+ Control how language codes appear in output filenames:
385
+
386
+ - `target_lang` (default): Uses the format you provided (e.g., `fr` → `fr.po`, `fr_FR` → `fr_FR.po`)
387
+ - `wp_locale`: WordPress format with region (e.g., `fr_FR.po`, `es_ES.po`)
388
+ - `iso_639_1`: 2-letter ISO codes (e.g., `fr.po`, `es.po`)
389
+ - `iso_639_2`: 3-letter ISO codes (e.g., `fra.po`, `spa.po`)
390
+
391
+ ### Complete Language List
392
+
393
+ For a full list of supported languages and their corresponding codes, see the [language mapping reference](src/utils/languageMapping.js). The mappings are based on [GlotPress locale data](https://github.com/GlotPress/GlotPress/blob/develop/locales/locales.php) from WordPress.org's translation platform.
394
+
395
+ **Major supported languages include**: Afrikaans, Arabic (multiple variants), Bengali, Chinese (Simplified/Traditional), Czech, Danish, Dutch, English (multiple variants), French, German, Greek, Hebrew, Hindi, Hungarian, Indonesian, Italian, Japanese, Korean, Persian, Polish, Portuguese (Brazil/Portugal), Romanian, Russian, Spanish (multiple variants), Swedish, Thai, Turkish, Ukrainian, Vietnamese, and more.
396
+
397
+ ---
398
+
399
+ ## Configuration Files
400
+
401
+ **Potomatic** uses several configuration files in the `config/` directory to customize its behavior:
402
+
403
+ ### `config/dictionaries/`
404
+
405
+ Used by default to locate [user dictionary](#-user-dictionaries) files. You can change the path to the dictionary files using the `--dictionary-path` option.
406
+
407
+ ### `config/prompt.md`
408
+
409
+ Contains the system prompt sent to the model for translation. You may consider modifying it to adjust translation style or add domain-specific instructions.
410
+
411
+ You can override the default path using the `--prompt-file-path` CLI option or the `PROMPT_FILE_PATH` environment variable.
412
+
413
+ ### `config/po-header.json`
414
+
415
+ Defines custom headers for generated `.po` files. These headers contain metadata about the translation project.
416
+
417
+ You can override the default path using the `--po-header-template-path` CLI option or the `PO_HEADER_TEMPLATE_PATH` environment variable.
418
+
419
+ **How it works:**
420
+
421
+ 1. Starts with headers from the source `.pot` file
422
+ 2. Applies your custom headers from this file
423
+ 3. When merging with existing `.po` files, preserves custom headers from the existing file
424
+ 4. **Always overwrites these headers** (regardless of what's in POT/config/existing files):
425
+ - `Language`: Set to target language (e.g., `fr_FR`)
426
+ - `PO-Revision-Date`: Set to current timestamp
427
+ - `Plural-Forms`: Set to language-specific plural rules (e.g., Arabic gets 6 forms, Polish gets 3 forms)
428
+ 5. **Sets `Plural-Forms` only for new files** (preserves existing PO file values when merging)
429
+
430
+ **Note**: `{{LANGUAGE}}` can be used in the custom headers to insert the target language code.
431
+
432
+ **Example custom header file:**
433
+
434
+ ```json
435
+ {
436
+ "Project-Id-Version": "MyApp 1.0",
437
+ "Report-Msgid-Bugs-To": "support@myapp.com",
438
+ "Last-Translator": "MyApp Team <team@myapp.com>",
439
+ "Language-Team": "{{LANGUAGE}} Team <{{LANGUAGE}}@myapp.com>",
440
+ "X-Generator": "MyApp Automated Translations"
441
+ }
442
+ ```
443
+
444
+ **Note**: When merging with existing `.po` files, custom headers like `Project-Id-Version` from the existing file are preserved, while `Language`, `PO-Revision-Date`, and `Plural-Forms` are updated to current values. The tool automatically handles complex plural forms for languages like Arabic (6 forms), Polish/Russian/Croatian (3 forms), and others.
445
+
446
+ ### `config/openai-pricing.json`
447
+
448
+ Contains pricing information for OpenAI models (as of July 2026) used for cost estimation. This file is automatically loaded and used to calculate translation costs.
449
+
450
+ ---
451
+
452
+ ## Available Scripts
453
+
454
+ ```bash
455
+ npm run translate # Main translation task
456
+ npm run ab-prompt-test # Prompt A/B tester
457
+ ```
458
+
459
+ ---
460
+
461
+ ## A/B Testing for Prompt Optimization
462
+
463
+ `npm run ab-prompt-test` (or `node tools/ab-prompt-test`) runs two prompt strategies side by side, reports cost, and highlights divergent translations so you can pick the winner.
464
+
465
+ ---
466
+
467
+ ## Acknowledgments
468
+
469
+ [GravityKit](https://github.com/GravityKit/Potomatic) built Potomatic through version 1.3.0. PublishPress forked that version and released 1.4.0.
470
+
471
+ Hat tip to [ryanhex53](https://github.com/ryanhex53) for the original [gpt-po](https://github.com/ryanhex53/gpt-po) that inspired Potomatic.