ai-i18n-tools 1.7.2 → 1.8.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/README.md +189 -118
- package/dist/api/llm-client.d.ts +5 -5
- package/dist/api/llm-client.d.ts.map +1 -1
- package/dist/api/llm-client.js +8 -8
- package/dist/api/llm-client.js.map +1 -1
- package/dist/api/openrouter-models-catalog.d.ts +32 -0
- package/dist/api/openrouter-models-catalog.d.ts.map +1 -0
- package/dist/api/openrouter-models-catalog.js +89 -0
- package/dist/api/openrouter-models-catalog.js.map +1 -0
- package/dist/build-info.generated.d.ts +1 -1
- package/dist/build-info.generated.js +1 -1
- package/dist/cli/bench-models.d.ts +23 -0
- package/dist/cli/bench-models.d.ts.map +1 -0
- package/dist/cli/bench-models.js +236 -0
- package/dist/cli/bench-models.js.map +1 -0
- package/dist/cli/check-markdown.d.ts.map +1 -1
- package/dist/cli/check-markdown.js +13 -4
- package/dist/cli/check-markdown.js.map +1 -1
- package/dist/cli/check-models.d.ts.map +1 -1
- package/dist/cli/check-models.js +4 -3
- package/dist/cli/check-models.js.map +1 -1
- package/dist/cli/doc-shell-ts-translate.d.ts +28 -0
- package/dist/cli/doc-shell-ts-translate.d.ts.map +1 -0
- package/dist/cli/doc-shell-ts-translate.js +181 -0
- package/dist/cli/doc-shell-ts-translate.js.map +1 -0
- package/dist/cli/doc-translate.d.ts.map +1 -1
- package/dist/cli/doc-translate.js +131 -121
- package/dist/cli/doc-translate.js.map +1 -1
- package/dist/cli/format.d.ts +20 -0
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +42 -8
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/fumadocs-meta-translate.d.ts +8 -0
- package/dist/cli/fumadocs-meta-translate.d.ts.map +1 -0
- package/dist/cli/fumadocs-meta-translate.js +203 -0
- package/dist/cli/fumadocs-meta-translate.js.map +1 -0
- package/dist/cli/fumadocs-ui-catalog.d.ts +14 -0
- package/dist/cli/fumadocs-ui-catalog.d.ts.map +1 -0
- package/dist/cli/fumadocs-ui-catalog.js +256 -0
- package/dist/cli/fumadocs-ui-catalog.js.map +1 -0
- package/dist/cli/generate-ui-languages.d.ts.map +1 -1
- package/dist/cli/generate-ui-languages.js +2 -2
- package/dist/cli/generate-ui-languages.js.map +1 -1
- package/dist/cli/helpers.d.ts +8 -0
- package/dist/cli/helpers.d.ts.map +1 -1
- package/dist/cli/helpers.js +25 -0
- package/dist/cli/helpers.js.map +1 -1
- package/dist/cli/index.js +115 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/llm-client-factory.d.ts +12 -0
- package/dist/cli/llm-client-factory.d.ts.map +1 -0
- package/dist/cli/llm-client-factory.js +25 -0
- package/dist/cli/llm-client-factory.js.map +1 -0
- package/dist/cli/nextra-dictionary-translate.d.ts +8 -0
- package/dist/cli/nextra-dictionary-translate.d.ts.map +1 -0
- package/dist/cli/nextra-dictionary-translate.js +76 -0
- package/dist/cli/nextra-dictionary-translate.js.map +1 -0
- package/dist/cli/nextra-meta-translate.d.ts +8 -0
- package/dist/cli/nextra-meta-translate.d.ts.map +1 -0
- package/dist/cli/nextra-meta-translate.js +97 -0
- package/dist/cli/nextra-meta-translate.js.map +1 -0
- package/dist/cli/openrouter-catalog-model-filter.d.ts.map +1 -1
- package/dist/cli/openrouter-catalog-model-filter.js +3 -3
- package/dist/cli/openrouter-catalog-model-filter.js.map +1 -1
- package/dist/cli/{lint-source.d.ts → proofread-ui.d.ts} +17 -17
- package/dist/cli/proofread-ui.d.ts.map +1 -0
- package/dist/cli/{lint-source.js → proofread-ui.js} +39 -48
- package/dist/cli/proofread-ui.js.map +1 -0
- package/dist/cli/purge-locale.d.ts +28 -0
- package/dist/cli/purge-locale.d.ts.map +1 -0
- package/dist/cli/purge-locale.js +260 -0
- package/dist/cli/purge-locale.js.map +1 -0
- package/dist/cli/translate-json-run.d.ts +2 -1
- package/dist/cli/translate-json-run.d.ts.map +1 -1
- package/dist/cli/translate-json-run.js +49 -33
- package/dist/cli/translate-json-run.js.map +1 -1
- package/dist/cli/translate-summary.d.ts +23 -0
- package/dist/cli/translate-summary.d.ts.map +1 -0
- package/dist/cli/translate-summary.js +92 -0
- package/dist/cli/translate-summary.js.map +1 -0
- package/dist/cli/translate-svg.d.ts.map +1 -1
- package/dist/cli/translate-svg.js +23 -66
- package/dist/cli/translate-svg.js.map +1 -1
- package/dist/cli/translate-ui-strings.d.ts.map +1 -1
- package/dist/cli/translate-ui-strings.js +123 -68
- package/dist/cli/translate-ui-strings.js.map +1 -1
- package/dist/cli/vitepress-catalog-usage.d.ts +8 -0
- package/dist/cli/vitepress-catalog-usage.d.ts.map +1 -0
- package/dist/cli/vitepress-catalog-usage.js +155 -0
- package/dist/cli/vitepress-catalog-usage.js.map +1 -0
- package/dist/cli/vitepress-init-scaffold.d.ts +2 -0
- package/dist/cli/vitepress-init-scaffold.d.ts.map +1 -0
- package/dist/cli/vitepress-init-scaffold.js +174 -0
- package/dist/cli/vitepress-init-scaffold.js.map +1 -0
- package/dist/cli/vitepress-theme-catalog.d.ts +14 -0
- package/dist/cli/vitepress-theme-catalog.d.ts.map +1 -0
- package/dist/cli/vitepress-theme-catalog.js +262 -0
- package/dist/cli/vitepress-theme-catalog.js.map +1 -0
- package/dist/core/cache.d.ts +6 -0
- package/dist/core/cache.d.ts.map +1 -1
- package/dist/core/cache.js +9 -0
- package/dist/core/cache.js.map +1 -1
- package/dist/core/config-migrate.d.ts.map +1 -1
- package/dist/core/config-migrate.js +16 -0
- package/dist/core/config-migrate.js.map +1 -1
- package/dist/core/config.d.ts +46 -11
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +229 -68
- package/dist/core/config.js.map +1 -1
- package/dist/core/doc-file-tracking.d.ts +9 -0
- package/dist/core/doc-file-tracking.d.ts.map +1 -1
- package/dist/core/doc-file-tracking.js +35 -2
- package/dist/core/doc-file-tracking.js.map +1 -1
- package/dist/core/docs-output-normalize.d.ts +9 -0
- package/dist/core/docs-output-normalize.d.ts.map +1 -1
- package/dist/core/docs-output-normalize.js +40 -1
- package/dist/core/docs-output-normalize.js.map +1 -1
- package/dist/core/fumadocs-dot-source-filter.d.ts +16 -0
- package/dist/core/fumadocs-dot-source-filter.d.ts.map +1 -0
- package/dist/core/fumadocs-dot-source-filter.js +61 -0
- package/dist/core/fumadocs-dot-source-filter.js.map +1 -0
- package/dist/core/fumadocs-parser.d.ts +8 -0
- package/dist/core/fumadocs-parser.d.ts.map +1 -0
- package/dist/core/fumadocs-parser.js +15 -0
- package/dist/core/fumadocs-parser.js.map +1 -0
- package/dist/core/llm-providers.d.ts +11 -1
- package/dist/core/llm-providers.d.ts.map +1 -1
- package/dist/core/llm-providers.js +51 -1
- package/dist/core/llm-providers.js.map +1 -1
- package/dist/core/output-paths.d.ts +17 -0
- package/dist/core/output-paths.d.ts.map +1 -1
- package/dist/core/output-paths.js +106 -3
- package/dist/core/output-paths.js.map +1 -1
- package/dist/core/prompt-builder.d.ts +10 -10
- package/dist/core/prompt-builder.d.ts.map +1 -1
- package/dist/core/prompt-builder.js +12 -12
- package/dist/core/prompt-builder.js.map +1 -1
- package/dist/core/prompts.d.ts +4 -4
- package/dist/core/prompts.d.ts.map +1 -1
- package/dist/core/prompts.js +2 -2
- package/dist/core/prompts.js.map +1 -1
- package/dist/core/types.d.ts +172 -6
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +105 -11
- package/dist/core/types.js.map +1 -1
- package/dist/core/ui-languages.d.ts +3 -1
- package/dist/core/ui-languages.d.ts.map +1 -1
- package/dist/core/ui-languages.js +5 -3
- package/dist/core/ui-languages.js.map +1 -1
- package/dist/dashboard-app/ai-i18n-tools_logo.svg +99 -0
- package/dist/dashboard-app/favicon.ico +0 -0
- package/dist/dashboard-app/index.html +13 -1
- package/dist/dashboard-app/styles.css +13 -0
- package/dist/extractors/classify-segment.js +1 -1
- package/dist/extractors/frontmatter-fields.d.ts.map +1 -1
- package/dist/extractors/frontmatter-fields.js +17 -0
- package/dist/extractors/frontmatter-fields.js.map +1 -1
- package/dist/extractors/fumadocs-ui-extractor.d.ts +8 -0
- package/dist/extractors/fumadocs-ui-extractor.d.ts.map +1 -0
- package/dist/extractors/fumadocs-ui-extractor.js +157 -0
- package/dist/extractors/fumadocs-ui-extractor.js.map +1 -0
- package/dist/extractors/image-markdown.d.ts +11 -0
- package/dist/extractors/image-markdown.d.ts.map +1 -0
- package/dist/extractors/image-markdown.js +24 -0
- package/dist/extractors/image-markdown.js.map +1 -0
- package/dist/extractors/markdown-extractor.d.ts.map +1 -1
- package/dist/extractors/markdown-extractor.js +38 -19
- package/dist/extractors/markdown-extractor.js.map +1 -1
- package/dist/extractors/ts-object-literal-extractor.d.ts +17 -0
- package/dist/extractors/ts-object-literal-extractor.d.ts.map +1 -0
- package/dist/extractors/ts-object-literal-extractor.js +165 -0
- package/dist/extractors/ts-object-literal-extractor.js.map +1 -0
- package/dist/extractors/vitepress-theme-extractor.d.ts +9 -0
- package/dist/extractors/vitepress-theme-extractor.d.ts.map +1 -0
- package/dist/extractors/vitepress-theme-extractor.js +194 -0
- package/dist/extractors/vitepress-theme-extractor.js.map +1 -0
- package/dist/i18n/locales/de.json +113 -68
- package/dist/i18n/locales/es.json +113 -68
- package/dist/i18n/locales/fr.json +113 -68
- package/dist/i18n/locales/hi-Latn.json +113 -68
- package/dist/i18n/locales/ja.json +113 -68
- package/dist/i18n/locales/ko.json +114 -69
- package/dist/i18n/locales/pt-BR.json +114 -69
- package/dist/i18n/locales/zh-Hans.json +114 -69
- package/dist/i18n/locales/zh-Hant.json +113 -68
- package/dist/index.d.ts +15 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/processors/admonition-placeholders.d.ts +3 -1
- package/dist/processors/admonition-placeholders.d.ts.map +1 -1
- package/dist/processors/admonition-placeholders.js +29 -8
- package/dist/processors/admonition-placeholders.js.map +1 -1
- package/dist/processors/admonition-syntax.d.ts +39 -0
- package/dist/processors/admonition-syntax.d.ts.map +1 -0
- package/dist/processors/admonition-syntax.js +39 -0
- package/dist/processors/admonition-syntax.js.map +1 -0
- package/dist/processors/anchor-placeholders.d.ts +2 -0
- package/dist/processors/anchor-placeholders.d.ts.map +1 -1
- package/dist/processors/anchor-placeholders.js +2 -1
- package/dist/processors/anchor-placeholders.js.map +1 -1
- package/dist/processors/doc-postprocess.js +2 -2
- package/dist/processors/doc-postprocess.js.map +1 -1
- package/dist/processors/fumadocs-link-normalize.d.ts +17 -0
- package/dist/processors/fumadocs-link-normalize.d.ts.map +1 -0
- package/dist/processors/fumadocs-link-normalize.js +124 -0
- package/dist/processors/fumadocs-link-normalize.js.map +1 -0
- package/dist/processors/markdown-source-diagnostics.d.ts +19 -0
- package/dist/processors/markdown-source-diagnostics.d.ts.map +1 -1
- package/dist/processors/markdown-source-diagnostics.js +96 -3
- package/dist/processors/markdown-source-diagnostics.js.map +1 -1
- package/dist/processors/nextra-link-normalize.d.ts +17 -0
- package/dist/processors/nextra-link-normalize.d.ts.map +1 -0
- package/dist/processors/nextra-link-normalize.js +124 -0
- package/dist/processors/nextra-link-normalize.js.map +1 -0
- package/dist/processors/placeholder-handler.d.ts +5 -1
- package/dist/processors/placeholder-handler.d.ts.map +1 -1
- package/dist/processors/placeholder-handler.js +10 -4
- package/dist/processors/placeholder-handler.js.map +1 -1
- package/dist/processors/translation-placeholder-leaks.js +1 -1
- package/dist/processors/translation-placeholder-leaks.js.map +1 -1
- package/dist/processors/validator.d.ts.map +1 -1
- package/dist/processors/validator.js +10 -0
- package/dist/processors/validator.js.map +1 -1
- package/dist/processors/vitepress-link-normalize.d.ts +37 -0
- package/dist/processors/vitepress-link-normalize.d.ts.map +1 -0
- package/dist/processors/vitepress-link-normalize.js +286 -0
- package/dist/processors/vitepress-link-normalize.js.map +1 -0
- package/dist/runtime/i18next-helpers.d.ts.map +1 -1
- package/dist/runtime/i18next-helpers.js.map +1 -1
- package/dist/utils/table.d.ts +2 -0
- package/dist/utils/table.d.ts.map +1 -1
- package/dist/utils/table.js +10 -4
- package/dist/utils/table.js.map +1 -1
- package/docs/ai-i18n-tools-context.md +122 -54
- package/package.json +34 -31
- package/dist/cli/lint-source.d.ts.map +0 -1
- package/dist/cli/lint-source.js.map +0 -1
- package/docs/GETTING_STARTED.md +0 -1853
- package/docs/LOCALE-ASSETS-GUIDE.md +0 -671
- package/docs/PACKAGE_OVERVIEW.md +0 -568
- package/docs/markdown-mdx-stress-test.md +0 -170
- package/docs/translation-dashboard.png +0 -0
package/README.md
CHANGED
|
@@ -1,46 +1,63 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/public/ai-i18n-tools_logo.png" alt="ai-i18n-tools logo" width="128" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
<a id="ai-i18n-tools"></a>
|
|
2
6
|
# ai-i18n-tools
|
|
3
7
|
|
|
4
|
-
[](https://www.npmjs.com/package/ai-i18n-tools)
|
|
5
|
-
[](https://www.npmjs.com/package/ai-i18n-tools)
|
|
6
|
-
[](https://nodejs.org/)
|
|
7
|
-
[](./LICENSE)
|
|
8
|
-
[](https://github.com/wsj-br/ai-i18n-tools/actions/workflows/ci.yml)
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
<small id="lang-list">[English (UK)](./README.md) · [Deutsch](./translated-docs/README.de.md) · [Español](./translated-docs/README.es.md) · [Français](./translated-docs/README.fr.md) · [Hindi (Roman)](./translated-docs/README.hi-Latn.md) · [日本語](./translated-docs/README.ja.md) · [한국어](./translated-docs/README.ko.md) · [Português (Brasil)](./translated-docs/README.pt-BR.md) · [简体中文](./translated-docs/README.zh-Hans.md) · [繁體中文](./translated-docs/README.zh-Hant.md)</small>
|
|
10
|
+
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
- **Workflow 2 — Document Translation:** Translates markdown, MDX, and `.astro` pages (for websites and Starlight) listed in `docs[].contentPaths` using `translate-docs`.
|
|
14
|
-
- **Workflow 3 — JSON File Translation:** Translates arbitrary nested JSON bundles defined in `json[]`. Use `translate-json` when UI copy is stored in per-locale JSON files instead of using `t()` in source.
|
|
12
|
+
[](https://www.npmjs.com/package/ai-i18n-tools) [](https://www.npmjs.com/package/ai-i18n-tools) [](https://nodejs.org/) [](https://github.com/wsj-br/ai-i18n-tools/blob/main/LICENSE) [](https://github.com/wsj-br/ai-i18n-tools/actions/workflows/ci.yml)
|
|
15
13
|
|
|
16
|
-
**SVG** assets are translated using `features.translateSVG`, the top-level `svg` block, and `translate-svg`—not `docs[].contentPaths`.
|
|
17
14
|
|
|
18
|
-
**
|
|
19
|
-
- Source uses `t()` → **Workflow 1** (`extract` / `translate-ui`)
|
|
20
|
-
- Localized pages or Docusaurus catalog JSON → **Workflow 2** (`translate-docs`)
|
|
21
|
-
- Only standalone, nested JSON locale files → **Workflow 3** (`translate-json`)
|
|
15
|
+
**Translate your app and documentation using the AI model of your choice: no lock-in, no rewrites.**
|
|
22
16
|
|
|
23
|
-
All workflows maintain a file/SQLite cache to ensure that only new or changed segments (strings or text chunks) are sent to the LLM.
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
|
|
19
|
+
`ai-i18n-tools` is a CLI and toolkit for internationalizing JavaScript/TypeScript applications and documentation sites - including Docusaurus, Astro, Starlight, VitePress, Nextra, Fumadocs, and plain Markdown/MDX - using large language models.
|
|
20
|
+
|
|
21
|
+
Choose from built-in presets (**OpenAI**, **Anthropic**, **Google Gemini**, **NVIDIA**, **DeepSeek**, **Groq**, **Mistral**, **xAI**, **Cerebras**, **Alibaba**, **APIFUN**, **OpenRouter**, **Ollama**) or point at any OpenAI-compatible API. Switch providers or models per project—or even per language—without modifying your codebase.
|
|
22
|
+
|
|
23
|
+
One config file drives three translation modes, so you can mix and match based on how your content is structured:
|
|
24
|
+
|
|
25
|
+
- **UI strings** — Extracts `t("…")` calls from JS/TS (and optionally `.astro` files) and generates flat, per-locale JSON for i18next or static SSG lookup.
|
|
26
|
+
- **Documents** — Translates Markdown, MDX, and `.astro` pages listed in `docs[].contentPaths` using `translate-docs`. Works with **VitePress**, **Starlight**, **Docusaurus**, **Nextra**, **Fumadocs**, Astro-based sites, or any static site generator that reads from Markdown/MDX/`.astro` source files.
|
|
27
|
+
- **JSON** — Translates arbitrary nested JSON bundles defined in `json[]`. Use `translate-json` when UI copy lives in per-locale JSON files instead of `t()` calls in source.
|
|
28
|
+
|
|
29
|
+
**SVG** assets get their own path: `features.translateSVG`, the top-level `svg` block, and `translate-svg`—not `docs[].contentPaths`.
|
|
30
|
+
|
|
31
|
+
**Which should I use?**
|
|
32
|
+
|
|
33
|
+
| Your content | Command |
|
|
34
|
+
|-------------------------------------------------------------------------------|---------------------------------------------|
|
|
35
|
+
| Source code uses `t()` | **UI strings** — `extract` / `translate-ui` |
|
|
36
|
+
| Localized pages or docs sites (VitePress, Starlight, Docusaurus, Nextra, Fumadocs, Astro, etc.) | **Documents** — `translate-docs` |
|
|
37
|
+
| Standalone, nested JSON locale files | **JSON** — `translate-json` |
|
|
38
|
+
|
|
39
|
+
All three share a file/SQLite cache, so only new or changed segments (strings or text chunks) are ever re-sent to the model — reruns are fast and cheap regardless of which provider you're using.
|
|
27
40
|
|
|
28
41
|
|
|
29
42
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
30
43
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
31
44
|
**Table of Contents**
|
|
32
45
|
|
|
33
|
-
- [
|
|
46
|
+
- [Translation types](#translation-types)
|
|
34
47
|
- [Installation](#installation)
|
|
35
48
|
- [Using the CLI](#using-the-cli)
|
|
36
|
-
- [LLM providers](#
|
|
49
|
+
- [LLM providers](#llm-providers)
|
|
37
50
|
- [Quick start](#quick-start)
|
|
38
|
-
- [
|
|
39
|
-
- [
|
|
51
|
+
- [UI strings](#ui-strings)
|
|
52
|
+
- [Documents](#documents)
|
|
53
|
+
- [VitePress](#vitepress)
|
|
54
|
+
- [Nextra](#nextra)
|
|
55
|
+
- [Fumadocs](#fumadocs)
|
|
40
56
|
- [Astro (plain Astro & Starlight)](#astro-plain-astro--starlight)
|
|
41
|
-
- [Combined
|
|
57
|
+
- [Combined sync](#combined-sync)
|
|
42
58
|
- [Runtime helpers](#runtime-helpers)
|
|
43
59
|
- [CLI commands](#cli-commands)
|
|
60
|
+
- [Tool UI language (logs, help, dashboard)](#tool-ui-language-logs-help-dashboard)
|
|
44
61
|
- [Documentation](#documentation)
|
|
45
62
|
- [License](#license)
|
|
46
63
|
|
|
@@ -48,24 +65,12 @@ All workflows maintain a file/SQLite cache to ensure that only new or changed se
|
|
|
48
65
|
|
|
49
66
|
|
|
50
67
|
|
|
68
|
+
<a id="translation-types"></a>
|
|
69
|
+
## Translation types
|
|
51
70
|
|
|
71
|
+
Each translation type has its own guide with full configuration details: [UI strings](docs/guide/ui-strings/), [Documents](docs/guide/documents/), and [JSON](docs/guide/json.md). See [What is ai-i18n-tools?](docs/guide/what-is-ai-i18n-tools.md) for a side-by-side comparison.
|
|
52
72
|
|
|
53
|
-
|
|
54
|
-
## Core workflows
|
|
55
|
-
|
|
56
|
-
**Workflow 1 - UI Translation** — for any JS/TS project using i18next (React, Next.js, Node.js, CLIs) or static Astro SSG
|
|
57
|
-
|
|
58
|
-
Scans source files for `t("…")` / `i18n.t("…")` literals (add `.astro` to `ui.uiExtractor.extensions` for Astro frontmatter and template expressions), builds a master catalog (`strings.json`), translates missing entries per locale via OpenRouter, and writes flat JSON files (`de.json`, `pt-BR.json`, …). English source text is the runtime lookup key in those bundles — `strings.json` is the extraction cache, not the runtime bundle.
|
|
59
|
-
|
|
60
|
-
**Workflow 2 - Document Translation** — for markdown, MDX, and `.astro` under `docs[].contentPaths`
|
|
61
|
-
|
|
62
|
-
Designed primarily for **markdown, MDX, and `.astro` documentation** (Docusaurus, [Astro Starlight](https://starlight.astro.build/), plain README files, and plain Astro marketing pages). `translate-docs` writes localised copies with a shared SQLite cache. On Docusaurus sites, set `docs[].docusaurusCatalogDir` to the `write-translations` catalog folder so shell JSON (navbar, footer, theme strings) is translated in the same command. `docs[].docsOutput.style` supports `"nested"`, `"flat"`, `"doc-system"`, and aliases `"docusaurus"` / `"astro-starlight"` (see [Output layouts](docs/GETTING_STARTED.md#output-layouts) in Getting Started). Arbitrary nested UI JSON that is not a Docusaurus catalog belongs in Workflow 3 (`json[]` / `translate-json`), not `docs[]`.
|
|
63
|
-
|
|
64
|
-
**Workflow 3 - JSON file translation** — nested locale JSON without `t()` in source
|
|
65
|
-
|
|
66
|
-
Translate files such as `src/i18n/en/translation.json` via top-level `json[]`, `features.translateJson`, and `translate-json`. Scaffold with `init -t ui-json-bundles`.
|
|
67
|
-
|
|
68
|
-
All workflows share `ai-i18n-tools.config.json` and can be combined; `sync` runs extract, UI translation, translate SVG, `translate-docs`, and `translate-json` in order according to your `features` flags.
|
|
73
|
+
A few things worth knowing up front: UI strings translates missing entries per locale via the active LLM provider (see [LLM providers](#llm-providers)) and writes flat JSON files (`de.json`, `pt-BR.json`, …), with the English source text as the runtime lookup key — `strings.json` is the extraction cache, not the runtime bundle. Documents supports `docs[].docsOutput.style` values `"nested"`, `"flat"`, `"doc-system"`, and aliases `"docusaurus"` / `"astro-starlight"` / `"vitepress"` / `"nextra"` / `"fumadocs"` (see [Output layouts](docs/guide/documents/output-layouts.md)). All three share `ai-i18n-tools.config.json` and can be combined; `sync` runs extract, UI translation, translate SVG, `translate-docs`, and `translate-json` in order according to your `features` flags.
|
|
69
74
|
|
|
70
75
|
---
|
|
71
76
|
|
|
@@ -83,13 +88,44 @@ pnpm add ai-i18n-tools
|
|
|
83
88
|
<a id="using-the-cli"></a>
|
|
84
89
|
### Using the CLI
|
|
85
90
|
|
|
86
|
-
|
|
91
|
+
After you install the package in your project, npm/pnpm/yarn link the published bin entry (`bin/ai-i18n-tools.mjs`) into `node_modules/.bin/ai-i18n-tools`. That shim loads the compiled CLI from the installed package.
|
|
92
|
+
|
|
93
|
+
To type the bare `ai-i18n-tools` command in an interactive shell, configure one of the options below. Without setup, the shell cannot find the binary even after a local install.
|
|
94
|
+
|
|
95
|
+
**direnv** — add to a `.envrc` in the project root (bash/zsh; see [direnv.net](https://direnv.net/)):
|
|
87
96
|
|
|
88
97
|
```bash
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
PATH_add node_modules/.bin
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
After `direnv allow`, the bare command is available whenever you `cd` into the project.
|
|
102
|
+
|
|
103
|
+
**Manual PATH** — from the project root in an interactive shell:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# bash/zsh
|
|
107
|
+
export PATH="$PWD/node_modules/.bin:$PATH"
|
|
108
|
+
ai-i18n-tools sync
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```powershell
|
|
112
|
+
# Windows PowerShell
|
|
113
|
+
$env:Path = "$PWD\node_modules\.bin;$env:Path"
|
|
114
|
+
ai-i18n-tools sync
|
|
91
115
|
```
|
|
92
116
|
|
|
117
|
+
**Global install** — install the CLI once and invoke it from any directory:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm install -g ai-i18n-tools
|
|
121
|
+
# or
|
|
122
|
+
pnpm add -g ai-i18n-tools
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
A global install uses the globally pinned version. For per-project version pinning, prefer direnv or manual PATH so `node_modules/.bin` resolves to the project's dependency.
|
|
126
|
+
|
|
127
|
+
**`package.json` scripts** — when npm or pnpm runs a script, it prepends `node_modules/.bin` to `PATH`, so the bare command name works inside scripts without shell PATH changes:
|
|
128
|
+
|
|
93
129
|
```json
|
|
94
130
|
"scripts": {
|
|
95
131
|
"i18n:extract": "ai-i18n-tools extract",
|
|
@@ -103,38 +139,49 @@ npx ai-i18n-tools sync # or: pnpm exec ai-i18n-tools sync
|
|
|
103
139
|
}
|
|
104
140
|
```
|
|
105
141
|
|
|
106
|
-
|
|
142
|
+
Then run e.g. `pnpm run i18n:sync` — scripts resolve the local binary without extra shell setup.
|
|
107
143
|
|
|
144
|
+
**Alternatives** — if you prefer not to adjust `PATH`: `npx ai-i18n-tools …` (npm) or `pnpm exec ai-i18n-tools …` (pnpm). For a zero-install one-off with no `package.json` entry: `npx ai-i18n-tools <cmd>` or `pnpm dlx ai-i18n-tools <cmd>`.
|
|
108
145
|
|
|
109
|
-
Prefer `sync` over hand-chaining `extract`, `translate-ui`, `translate-svg`, `translate-docs`, and `translate-json` — order and feature flags are easy to get wrong when run manually. See [Recommended `package.json` scripts](docs/
|
|
146
|
+
Prefer `sync` over hand-chaining `extract`, `translate-ui`, `translate-svg`, `translate-docs`, and `translate-json` — order and feature flags are easy to get wrong when run manually. See [Recommended `package.json` scripts](docs/guide/quick-start.md#recommended-packagejson-scripts) in the Quick start guide.
|
|
110
147
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
> **Tip:** To run `ai-i18n-tools` bare in an interactive shell without `npx`, add `node_modules/.bin` to your `PATH` (bash/zsh: `export PATH="$PWD/node_modules/.bin:$PATH"`). See [Getting Started](docs/GETTING_STARTED.md#installation) for direnv and Windows instructions.
|
|
114
|
-
|
|
115
|
-
Set your provider API key (OpenRouter shown; use the matching variable for your provider):
|
|
148
|
+
Set the API key for your chosen provider (environment variable names are in [LLM providers](#llm-providers)):
|
|
116
149
|
|
|
117
150
|
```bash
|
|
118
|
-
export
|
|
151
|
+
export PROVIDER_API_KEY=sk-your-key-here
|
|
119
152
|
```
|
|
120
153
|
|
|
121
154
|
---
|
|
122
155
|
|
|
123
|
-
<a id="
|
|
156
|
+
<a id="llm-providers"></a>
|
|
124
157
|
## LLM providers
|
|
125
158
|
|
|
126
159
|
Translation commands (`translate-ui`, `translate-docs`, `translate-json`, `sync`, `check-models`, and related scripts) call an LLM provider; `check-markdown`, `mark-html`, and `extract` do not.
|
|
127
160
|
|
|
128
161
|
Configure providers under a top-level `providers` map and pick the active one with a top-level `provider` selector (optional when exactly one provider is configured). Most providers need only a `translationModels` list — `baseUrl` and the API-key environment variable come from a built-in preset; you can override `baseUrl`, `apiKeyEnv`, `headers`, `maxTokens`, `temperature`, and `requestTimeoutMs` per provider. `requestTimeoutMs` is the maximum time in milliseconds to wait for each request (default `30000`).
|
|
129
162
|
|
|
163
|
+
Optional model tiers on each provider block:
|
|
164
|
+
|
|
165
|
+
- `translationModels` — global ordered fallback chain (required for translation features).
|
|
166
|
+
- `uiModels` — UI-only chain (`translate-ui`, plural generation, `proofread-ui`): tried after any matching `localeModels` entry, before `translationModels`.
|
|
167
|
+
- `localeModels` — per-locale overrides for **all** pipelines: each entry maps a BCP-47 locale to an ordered model list tried first for that locale only (`pt-br` matches `pt-BR`).
|
|
168
|
+
|
|
169
|
+
Resolution order: **UI** → `localeModels(locale)` → `uiModels` → `translationModels`; **docs / JSON / SVG** → `localeModels(locale)` → `translationModels`. Duplicate model ids are skipped while preserving order.
|
|
170
|
+
|
|
130
171
|
To switch providers for a single run without editing the config, pass the global `-P` / `--provider <name>` option (e.g. `ai-i18n-tools -P groq translate-ui`); the name must be one of the configured `providers` keys.
|
|
131
172
|
|
|
132
173
|
```jsonc
|
|
133
174
|
{
|
|
134
|
-
"provider": "
|
|
175
|
+
"provider": "ollama",
|
|
135
176
|
"providers": {
|
|
136
|
-
"openrouter": { "translationModels": ["qwen/qwen3-235b-a22b-2507", "openai/gpt-4o-mini"] },
|
|
137
177
|
"groq": { "translationModels": ["llama-3.3-70b-versatile"] },
|
|
178
|
+
"openrouter": {
|
|
179
|
+
"translationModels": ["qwen/qwen3-235b-a22b-2507", "openai/gpt-4o-mini"],
|
|
180
|
+
"uiModels": ["anthropic/claude-sonnet-latest"],
|
|
181
|
+
"localeModels": [
|
|
182
|
+
{ "locale": "pt-BR", "models": ["google/gemini-3-flash-preview"] }
|
|
183
|
+
]
|
|
184
|
+
},
|
|
138
185
|
"ollama": { "baseUrl": "http://localhost:11434/v1", "translationModels": ["llama3.2"] }
|
|
139
186
|
}
|
|
140
187
|
}
|
|
@@ -142,96 +189,120 @@ To switch providers for a single run without editing the config, pass the global
|
|
|
142
189
|
|
|
143
190
|
Built-in provider presets (key — base URL — API-key env var):
|
|
144
191
|
|
|
145
|
-
| Provider
|
|
146
|
-
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
| `deepseek`
|
|
152
|
-
| `
|
|
153
|
-
| `groq`
|
|
154
|
-
| `mistral`
|
|
155
|
-
| `
|
|
156
|
-
| `
|
|
157
|
-
| `
|
|
158
|
-
| `
|
|
159
|
-
| `
|
|
192
|
+
| Provider | Base URL | API-key env var |
|
|
193
|
+
|--------------|-----------------------------------------------------------|----------------------|
|
|
194
|
+
| `alibaba` | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1` | `ALIBABA_API_KEY` |
|
|
195
|
+
| `anthropic` | `https://api.anthropic.com/v1` | `ANTHROPIC_API_KEY` |
|
|
196
|
+
| `apifun` | `https://api.apikey.fun/v1` | `APIFUN_API_KEY` |
|
|
197
|
+
| `cerebras` | `https://api.cerebras.ai/v1` | `CEREBRAS_API_KEY` |
|
|
198
|
+
| `deepseek` | `https://api.deepseek.com` | `DEEPSEEK_API_KEY` |
|
|
199
|
+
| `gemini` | `https://generativelanguage.googleapis.com/v1beta/openai` | `GOOGLE_API_KEY` |
|
|
200
|
+
| `groq` | `https://api.groq.com/openai/v1` | `GROQ_API_KEY` |
|
|
201
|
+
| `mistral` | `https://api.mistral.ai/v1` | `MISTRAL_API_KEY` |
|
|
202
|
+
| `nvidia` | `https://integrate.api.nvidia.com/v1` | `NVIDIA_API_KEY` |
|
|
203
|
+
| `ollama` | `http://localhost:11434/v1` | (none) |
|
|
204
|
+
| `openai` | `https://api.openai.com/v1` | `OPENAI_API_KEY` |
|
|
205
|
+
| `openrouter` | `https://openrouter.ai/api/v1` | `OPENROUTER_API_KEY` |
|
|
206
|
+
| `xai` | `https://api.x.ai/v1` | `XAI_API_KEY` |
|
|
160
207
|
|
|
161
208
|
Define a custom OpenAI-compatible provider by adding a new key with `baseUrl` (and `apiKeyEnv` unless it needs no key). Model ids are plain upstream ids — the provider is chosen at the config level, so no `provider/` prefix is needed (OpenRouter ids keep their native `vendor/model` form).
|
|
162
209
|
|
|
163
|
-
Token usage is reported for every provider; exact USD cost is shown only when the provider returns it
|
|
164
|
-
|
|
165
|
-
A legacy top-level `openrouter` config block is still accepted and is automatically migrated to `providers.openrouter` (with `provider: "openrouter"`) on load.
|
|
210
|
+
Token usage is reported for every provider; exact USD cost is shown only when the provider returns it. `ai-i18n-tools check-models` validates all configured model ids (`translationModels`, `uiModels`, and every `localeModels` entry) against the active provider's live `GET /models` list, and shows pricing when the provider returns it. `ai-i18n-tools list-models` lists every model the active provider advertises (use `-P` / `--provider` to inspect another configured provider). `ai-i18n-tools bench-models` benchmarks every unique configured model id (`translationModels`, `uiModels`, and `localeModels`) by translating a sample in isolation (models run in parallel, bounded by `concurrency`) and prints per-model input/output tokens, wall-clock time, and USD cost.
|
|
166
211
|
|
|
167
|
-
For a hands-on demo of switching providers with `-P` on a single document, see [`examples/multi-provider`](examples/multi-provider/)
|
|
212
|
+
For a hands-on demo of switching providers with `-P` on a single document, see [`examples/multi-provider`](https://github.com/wsj-br/ai-i18n-tools/tree/main/examples/multi-provider/).
|
|
168
213
|
|
|
169
214
|
---
|
|
170
215
|
|
|
171
216
|
<a id="quick-start"></a>
|
|
172
217
|
## Quick start
|
|
173
218
|
|
|
174
|
-
|
|
175
|
-
|
|
219
|
+
Configure your shell for the bare command first — see [Using the CLI](#using-the-cli).
|
|
220
|
+
|
|
221
|
+
<a id="ui-strings"></a>
|
|
222
|
+
### UI strings
|
|
176
223
|
|
|
177
224
|
```bash
|
|
178
225
|
# 1. Create config (default ui-markdown; plain Astro: init -t ui-astro-website)
|
|
179
|
-
|
|
226
|
+
ai-i18n-tools init [-P <provider>]
|
|
180
227
|
|
|
181
228
|
# 2. Extract UI strings to strings.json
|
|
182
|
-
|
|
229
|
+
ai-i18n-tools extract
|
|
183
230
|
|
|
184
231
|
# 3. Translate to all target locales
|
|
185
|
-
|
|
232
|
+
ai-i18n-tools translate-ui
|
|
186
233
|
```
|
|
187
234
|
|
|
188
|
-
Then wire i18next in your app using the helpers from `'ai-i18n-tools/runtime'`. See [Step 4: Wire i18next at runtime](docs/
|
|
235
|
+
Then wire i18next in your app using the helpers from `'ai-i18n-tools/runtime'`. See [Step 4: Wire i18next at runtime](docs/guide/ui-strings/i18next-runtime.md) in the UI strings guide for the full setup.
|
|
189
236
|
|
|
190
|
-
<a id="
|
|
191
|
-
###
|
|
237
|
+
<a id="documents"></a>
|
|
238
|
+
### Documents
|
|
192
239
|
|
|
193
240
|
The default `init` template (`ui-markdown`) enables UI extraction only. Use a docs-oriented template (or enable `features.translateDocs` and add `docs[]`) before `translate-docs`:
|
|
194
241
|
|
|
195
242
|
```bash
|
|
196
243
|
# Docusaurus docs + optional write-translations catalog
|
|
197
|
-
|
|
244
|
+
ai-i18n-tools init -t ui-docusaurus [-P <provider>]
|
|
198
245
|
|
|
199
246
|
# Astro Starlight documentation
|
|
200
|
-
#
|
|
247
|
+
# ai-i18n-tools init -t ui-starlight [-P <provider>]
|
|
248
|
+
|
|
249
|
+
# VitePress documentation (pages + theme catalog)
|
|
250
|
+
# ai-i18n-tools init -t ui-vitepress [-P <provider>]
|
|
251
|
+
|
|
252
|
+
# Nextra documentation (pages + _meta.ts + theme dictionary)
|
|
253
|
+
# ai-i18n-tools init -t ui-nextra [-P <provider>]
|
|
254
|
+
|
|
255
|
+
# Fumadocs documentation (pages + meta.json + UI catalog)
|
|
256
|
+
# ai-i18n-tools init -t ui-fumadocs [-P <provider>]
|
|
201
257
|
|
|
202
258
|
# Plain Astro website — UI extraction for t() in .astro; add docs[] for page HTML (see Astro below)
|
|
203
|
-
#
|
|
259
|
+
# ai-i18n-tools init -t ui-astro-website [-P <provider>]
|
|
204
260
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
#
|
|
261
|
+
ai-i18n-tools translate-docs
|
|
262
|
+
ai-i18n-tools status
|
|
263
|
+
# ai-i18n-tools translate-docs --locale de # single locale
|
|
208
264
|
```
|
|
209
265
|
|
|
210
|
-
Edit `ai-i18n-tools.config.json`: set `docs[].contentPaths` to markdown, MDX, and/or `.astro` sources; `docs[].outputDir` and `docs[].docsOutput.style` (`"docusaurus"`, `"astro-starlight"`, `"flat"`, etc.). Full field reference: [
|
|
266
|
+
Edit `ai-i18n-tools.config.json`: set `docs[].contentPaths` to markdown, MDX, and/or `.astro` sources; `docs[].outputDir` and `docs[].docsOutput.style` (`"docusaurus"`, `"astro-starlight"`, `"vitepress"`, `"nextra"`, `"fumadocs"`, `"flat"`, etc.). Full field reference: [Documents](docs/guide/documents/).
|
|
267
|
+
|
|
268
|
+
<a id="vitepress"></a>
|
|
269
|
+
### VitePress
|
|
270
|
+
|
|
271
|
+
`init -t ui-vitepress` scaffolds `docsOutput.style: "vitepress"` plus `docsOutput.vitepressThemeCatalog` for nav/sidebar/footer strings. Run `sync` to translate page markdown and the theme catalog together — no separate JSON pipeline. See [VitePress integration](docs/guide/integrations/vitepress.md) and [examples/vitepress-docs](https://github.com/wsj-br/ai-i18n-tools/tree/main/examples/vitepress-docs/).
|
|
272
|
+
|
|
273
|
+
<a id="nextra"></a>
|
|
274
|
+
### Nextra
|
|
275
|
+
|
|
276
|
+
`init -t ui-nextra` scaffolds `docsOutput.style: "nextra"`. `translate-docs` automatically collects and translates `_meta.ts` sidebar labels; set `docs[].nextraDictionaryPath` to also translate the theme dictionary module (e.g. `app/_dictionaries/en.ts`) — all in the same `sync` run, no JSON sidecars. See [Nextra integration](docs/guide/integrations/nextra.md) and [examples/nextra-docs](https://github.com/wsj-br/ai-i18n-tools/tree/main/examples/nextra-docs/).
|
|
277
|
+
|
|
278
|
+
<a id="fumadocs"></a>
|
|
279
|
+
### Fumadocs
|
|
280
|
+
|
|
281
|
+
`init -t ui-fumadocs` scaffolds `docsOutput.style: "fumadocs"` with the dot parser (default) or dir parser for Nextra-style locale folders. `translate-docs` automatically collects and translates `meta.json` sidebar labels; set `docsOutput.fumadocsUiCatalog` to also translate UI overrides in `lib/layout.shared.ts` — all in the same `sync` run, no JSON sidecars. See [Fumadocs integration](docs/guide/integrations/fumadocs.md) and [examples/fumadocs-docs](https://github.com/wsj-br/ai-i18n-tools/tree/main/examples/fumadocs-docs/).
|
|
211
282
|
|
|
212
283
|
<a id="astro-plain-astro--starlight"></a>
|
|
213
284
|
### Astro (plain Astro & Starlight)
|
|
214
285
|
|
|
215
|
-
**Astro Starlight** — `init -t ui-starlight`, then `translate-docs`. Starlight UI overrides can use `src/content/i18n/en.json` with `jsonPathTemplate` in a separate `docs[]` block when needed ([
|
|
286
|
+
**Astro Starlight** — `init -t ui-starlight`, then `translate-docs`. Starlight UI overrides can use `src/content/i18n/en.json` with `jsonPathTemplate` in a separate `docs[]` block when needed ([Documents — initialise for documentation](docs/guide/documents/index.md#step-1-initialise-for-documentation)).
|
|
216
287
|
|
|
217
|
-
**Plain Astro** (marketing or app sites, not Starlight) — combine [Astro built-in i18n routing](https://docs.astro.build/en/guides/internationalization/) with ai-i18n-tools. Reference project: [`examples/astro-website`](examples/astro-website/) (English at `/`, locales at `/{locale}/`).
|
|
288
|
+
**Plain Astro** (marketing or app sites, not Starlight) — combine [Astro built-in i18n routing](https://docs.astro.build/en/guides/internationalization/) with ai-i18n-tools. Reference project: [`examples/astro-website`](https://github.com/wsj-br/ai-i18n-tools/tree/main/examples/astro-website/) (English at `/`, locales at `/{locale}/`).
|
|
218
289
|
|
|
219
290
|
Most teams use a **hybrid** of two pipelines:
|
|
220
291
|
|
|
221
|
-
| Pipeline
|
|
222
|
-
|
|
223
|
-
| **Page HTML**
|
|
224
|
-
| **UI strings (`t()`)** | Frontmatter data, tab labels, shared arrays
|
|
292
|
+
| Pipeline | Use for | Commands | Output |
|
|
293
|
+
|------------------------|----------------------------------------------------------------------|----------------------------|--------------------------------------------------------|
|
|
294
|
+
| **Page HTML** | Headings, paragraphs, nav labels, inline arrays in the template body | `translate-docs` | `src/pages/{locale}/index.astro` per locale |
|
|
295
|
+
| **UI strings (`t()`)** | Frontmatter data, tab labels, shared arrays | `extract` → `translate-ui` | `public/locales/{locale}.json` (English source as key) |
|
|
225
296
|
|
|
226
|
-
Scaffold UI with `init -t ui-astro-website`. For hardcoded HTML in `.astro` pages, enable `features.translateDocs` and add a `docs[]` block with `docsOutput.style: "astro-starlight"` (see [Astro website pages (parse-and-replace)](docs/
|
|
297
|
+
Scaffold UI with `init -t ui-astro-website`. For hardcoded HTML in `.astro` pages, enable `features.translateDocs` and add a `docs[]` block with `docsOutput.style: "astro-starlight"` (see [Astro website pages (parse-and-replace)](docs/guide/ui-strings/astro-website.md#astro-website-pages-parse-and-replace)). Keep `targetLocales`, `i18n.locales` in `astro.config.mjs`, and `ui-languages.json` aligned (Astro routes use lowercase codes such as `pt-br`; flat bundle filenames follow config casing, e.g. `pt-BR.json`).
|
|
227
298
|
|
|
228
|
-
Wire `t()` at build time without i18next unless you add client islands — see [Astro website UI strings (SSG)](docs/
|
|
299
|
+
Wire `t()` at build time without i18next unless you add client islands — see [Astro website UI strings (SSG)](docs/guide/ui-strings/astro-website.md#astro-website-ui-strings-ssg) and the example’s `src/i18n/t.ts`.
|
|
229
300
|
|
|
230
|
-
<a id="combined-
|
|
231
|
-
### Combined
|
|
301
|
+
<a id="combined-sync"></a>
|
|
302
|
+
### Combined sync
|
|
232
303
|
|
|
233
304
|
```bash
|
|
234
|
-
|
|
305
|
+
ai-i18n-tools sync # extract → translate-ui → translate-svg → translate-docs → translate-json (per features)
|
|
235
306
|
```
|
|
236
307
|
|
|
237
308
|
---
|
|
@@ -246,8 +317,8 @@ The following helpers are exported from `'ai-i18n-tools/runtime'` and work in an
|
|
|
246
317
|
| `defaultI18nInitOptions(sourceLocale)` | Standard i18next init options for key-as-default setups. |
|
|
247
318
|
| `setupKeyAsDefaultT(i18n, { stringsJson, sourcePluralFlatBundle? })` | Recommended wiring: key-trim + plural `wrapT` from `strings.json`, optionally merges `translate-ui` `{sourceLocale}.json` plural keys. |
|
|
248
319
|
| `wrapT(i18n, options)` | Lower-level plural-aware `t()` wrapper (usually installed by `setupKeyAsDefaultT`). |
|
|
249
|
-
| `buildPluralIndexFromStringsJson(entries)`
|
|
250
|
-
| `extractInterpolationNamesForWrap(key)`
|
|
320
|
+
| `buildPluralIndexFromStringsJson(entries)` | Builds the plural group index `wrapT` uses from catalog rows with `"plural": true`. |
|
|
321
|
+
| `extractInterpolationNamesForWrap(key)` | Parses `{{var}}` names from a source key for `wrapT` / key-trim fallback. |
|
|
251
322
|
| `wrapI18nWithKeyTrim(i18n)` | Lower-level key-trim wrapper only (deprecated for app wiring; prefer `setupKeyAsDefaultT`). |
|
|
252
323
|
| `makeLocaleLoadersFromManifest(uiLanguages, sourceLocale, makeLoader)` | Builds the `localeLoaders` map for `makeLoadLocale` from `ui-languages.json` (every `code` except `sourceLocale`). |
|
|
253
324
|
| `makeLoadLocale(i18n, loaders, sourceLocale)` | Factory for async locale file loading. |
|
|
@@ -267,8 +338,9 @@ The following helpers are exported from `'ai-i18n-tools/runtime'` and work in an
|
|
|
267
338
|
ai-i18n-tools version
|
|
268
339
|
ai-i18n-tools check-models
|
|
269
340
|
ai-i18n-tools list-models
|
|
341
|
+
ai-i18n-tools bench-models [--model <ids>] [--text <text>|--file <path>] [--source <locale>] [--target <locale>]
|
|
270
342
|
ai-i18n-tools list-languages [search]
|
|
271
|
-
ai-i18n-tools init [-t ui-markdown|ui-docusaurus|ui-starlight|ui-astro-website|ui-json-bundles] [-o path] [--with-translate-ignore]
|
|
343
|
+
ai-i18n-tools init [-t ui-markdown|ui-docusaurus|ui-starlight|ui-vitepress|ui-nextra|ui-fumadocs|ui-astro-website|ui-json-bundles] [-o path] [-P <provider>] [--with-translate-ignore]
|
|
272
344
|
ai-i18n-tools write-heading-ids …
|
|
273
345
|
ai-i18n-tools mark-html [paths...] [--write]
|
|
274
346
|
ai-i18n-tools extract
|
|
@@ -277,7 +349,7 @@ ai-i18n-tools translate-json …
|
|
|
277
349
|
ai-i18n-tools translate-svg …
|
|
278
350
|
ai-i18n-tools translate-ui …
|
|
279
351
|
ai-i18n-tools sync-ui …
|
|
280
|
-
ai-i18n-tools
|
|
352
|
+
ai-i18n-tools proofread-ui …
|
|
281
353
|
ai-i18n-tools check-markdown [-p|--path <path>] [-f|--file <path>] [--json] [--no-cache]
|
|
282
354
|
ai-i18n-tools export-ui-xliff …
|
|
283
355
|
ai-i18n-tools sync …
|
|
@@ -285,6 +357,7 @@ ai-i18n-tools status …
|
|
|
285
357
|
ai-i18n-tools statistics …
|
|
286
358
|
ai-i18n-tools cleanup …
|
|
287
359
|
ai-i18n-tools clean-temp …
|
|
360
|
+
ai-i18n-tools purge-locale -l <code> [-l <code> …] [--dry-run] [-y|--yes] [-f|--force] [--keep-files] [--backup <path>]
|
|
288
361
|
ai-i18n-tools dashboard …
|
|
289
362
|
ai-i18n-tools generate-ui-languages [--master path] [--dry-run]
|
|
290
363
|
ai-i18n-tools glossary-generate
|
|
@@ -292,37 +365,35 @@ ai-i18n-tools help [command]
|
|
|
292
365
|
```
|
|
293
366
|
|
|
294
367
|
|
|
295
|
-
For plain HTML apps, annotate elements with bare `data-i18n` / `data-i18n-title` / `data-i18n-placeholder` markers (the source text is taken from the element's own textContent / title / placeholder, written once); `mark-html` inserts them for you and `extract` then captures them into `strings.json`. See [
|
|
368
|
+
For plain HTML apps, annotate elements with bare `data-i18n` / `data-i18n-title` / `data-i18n-placeholder` markers (the source text is taken from the element's own textContent / title / placeholder, written once); `mark-html` inserts them for you and `extract` then captures them into `strings.json`. See [Marking HTML for translation](docs/guide/ui-strings/plain-html.md#marking-html-for-translation).
|
|
296
369
|
|
|
297
|
-
Complete per-command flag lists are in [
|
|
370
|
+
Complete per-command flag lists are in [CLI reference](docs/reference/cli-commands/). Run `ai-i18n-tools <command> --help` for built-in usage text.
|
|
298
371
|
|
|
299
|
-
Global options
|
|
372
|
+
Global options: `-c <config>` (default: `ai-i18n-tools.config.json`), `-v` (verbose), `-P` / `--provider <name>` (override the active LLM provider; must be configured under `providers`), `-L` / `--ui-lang <code>` (language for the tool's own UI/logs), `-V` / `--version`, and `-h` / `--help` — accepted on every command. `-w` / `--write-logs [path]` tees console output to a log file (default: under the translation cache directory), but only takes effect on the translation and sync commands (`translate-docs`, `translate-json`, `translate-svg`, `translate-ui`, `sync-ui`, `sync`, `cleanup`). Several commands accept `-l` / `--locale <codes>` (comma-separated BCP-47) to limit target locales; `proofread-ui` uses a single source locale. See [CLI reference](docs/reference/cli-commands/) for the command overview.
|
|
300
373
|
|
|
374
|
+
<a id="tool-ui-language-logs-help-dashboard"></a>
|
|
301
375
|
### Tool UI language (logs, help, dashboard)
|
|
302
376
|
|
|
303
|
-
The tool localizes its own CLI help,
|
|
304
|
-
|
|
305
|
-
1. `-L` / `--ui-lang <code>` global flag (e.g. `-L pt-BR`).
|
|
306
|
-
2. `AI_I18N_LANG` environment variable (e.g. `export AI_I18N_LANG=es`).
|
|
307
|
-
3. The `uiLanguage` config key in `ai-i18n-tools.config.json` (BCP-47 string).
|
|
308
|
-
4. The host OS locale (via `Intl.DateTimeFormat().resolvedOptions().locale`).
|
|
309
|
-
|
|
310
|
-
The requested locale is matched against the shipped UI languages exactly or by closest variation (for example `pt-PT` resolves to `pt-BR`, and `en-US` resolves to `en-GB`); when nothing matches it falls back to the source locale (`en-GB`). This is independent of your project's `sourceLocale` / `targetLocales`. Shipped UI languages: `en-GB` (source) plus `de`, `es`, `fr`, `hi-Latn`, `ja`, `ko`, `pt-BR`, `zh-Hans`, and `zh-Hant`.
|
|
377
|
+
The tool localizes its own CLI help, log summaries, and Translation Dashboard independently of the locales you translate. By default it follows your OS locale; override with `-L pt-BR`, `export AI_I18N_LANG=es`, or `"uiLanguage"` in config. See [Tool UI language](docs/guide/tool-ui-language.md) for locale resolution, shipped languages, and dashboard behaviour.
|
|
311
378
|
|
|
312
379
|
---
|
|
313
380
|
|
|
314
381
|
<a id="documentation"></a>
|
|
315
382
|
## Documentation
|
|
316
383
|
|
|
317
|
-
- [
|
|
318
|
-
- [
|
|
319
|
-
- [
|
|
320
|
-
- [
|
|
321
|
-
-
|
|
384
|
+
- [Documentation site](https://wsj-br.github.io/ai-i18n-tools/) — VitePress guide (9 locales on GitHub Pages); slim entry point with links into the full guide.
|
|
385
|
+
- [Quick start](docs/guide/quick-start.md) — setup for UI strings, documents, and JSON (UI, docs/`.astro`, JSON bundles, VitePress, Nextra, Fumadocs, Astro Starlight and plain Astro).
|
|
386
|
+
- [Locale assets guide](docs/guide/images-and-screenshots/) - screenshots and illustrated SVGs in translated docs (flat link rewriter, screenshot scripts).
|
|
387
|
+
- [Architecture](docs/reference/architecture.md) - architecture, internals, programmatic API, and extension points.
|
|
388
|
+
- [AI Agent Context](https://github.com/wsj-br/ai-i18n-tools/blob/main/docs/ai-i18n-tools-context.md) - **for apps using the package:** integration prompts for downstream projects (copy into your repo’s agent rules).
|
|
389
|
+
- Maintainer guide for **this** repository: `AGENT.md` (rules and workflows; clone-only; not on npm). Pipeline reference: `docs/reference/`. Local dev and publishing: `dev/DEVEL.md`.
|
|
322
390
|
|
|
323
391
|
---
|
|
324
392
|
|
|
325
393
|
<a id="license"></a>
|
|
326
394
|
## License
|
|
327
395
|
|
|
328
|
-
|
|
396
|
+
This project is licensed under the MIT License.
|
|
397
|
+
See the [LICENSE](https://github.com/wsj-br/ai-i18n-tools/blob/main/LICENSE) file for details.
|
|
398
|
+
|
|
399
|
+
Copyright © 2026 Waldemar Scudeller Jr.
|
package/dist/api/llm-client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CldrPluralForm, I18nConfig } from "../core/types.js";
|
|
2
2
|
import { type BatchTranslationResult, type ChatResponse, type LlmUsageStats, type Segment, type TranslationResult } from "../core/types.js";
|
|
3
|
-
import { type DocumentBatchResponseFormat, type DocumentPromptContentType, type
|
|
3
|
+
import { type DocumentBatchResponseFormat, type DocumentPromptContentType, type ProofreadUISlotResult } from "../core/prompt-builder.js";
|
|
4
4
|
import type { Logger } from "../utils/logger.js";
|
|
5
5
|
/** Thrown when every model in the chain fails for {@link LlmClient.translateDocumentBatch}. */
|
|
6
6
|
export declare class DocumentBatchAllModelsFailedError extends Error {
|
|
@@ -35,7 +35,7 @@ export interface LlmClientOptions {
|
|
|
35
35
|
apiKey?: string;
|
|
36
36
|
/**
|
|
37
37
|
* When set and non-empty, use this ordered model list instead of resolving from the active provider
|
|
38
|
-
* (e.g. UI translation with `
|
|
38
|
+
* (e.g. locale-aware UI or document translation with `uiModels` / `localeModels` prepended).
|
|
39
39
|
*/
|
|
40
40
|
translationModels?: string[];
|
|
41
41
|
/** Append request/response JSON when set. */
|
|
@@ -153,13 +153,13 @@ export declare class LlmClient {
|
|
|
153
153
|
cost?: number;
|
|
154
154
|
}>;
|
|
155
155
|
/**
|
|
156
|
-
* `
|
|
156
|
+
* `proofread-ui`: review a batch of source-locale UI strings; model returns JSON array of `{ issues: [...] }`.
|
|
157
157
|
*/
|
|
158
|
-
|
|
158
|
+
proofreadUISourceBatch(texts: string[], languageLabel: string, options?: {
|
|
159
159
|
startModelIndex?: number;
|
|
160
160
|
glossaryHints?: string[];
|
|
161
161
|
}): Promise<{
|
|
162
|
-
slots:
|
|
162
|
+
slots: ProofreadUISlotResult[];
|
|
163
163
|
model: string;
|
|
164
164
|
usage: LlmUsageStats;
|
|
165
165
|
cost?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-client.d.ts","sourceRoot":"","sources":["../../src/api/llm-client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAEvB,MAAM,kBAAkB,CAAC;AAc1B,OAAO,EAYL,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,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