ai-i18n-tools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -0
  3. package/dist/api/openrouter.d.ts +115 -0
  4. package/dist/api/openrouter.d.ts.map +1 -0
  5. package/dist/api/openrouter.js +399 -0
  6. package/dist/api/openrouter.js.map +1 -0
  7. package/dist/cli/doc-translate.d.ts +90 -0
  8. package/dist/cli/doc-translate.d.ts.map +1 -0
  9. package/dist/cli/doc-translate.js +1153 -0
  10. package/dist/cli/doc-translate.js.map +1 -0
  11. package/dist/cli/export-ui-xliff.d.ts +32 -0
  12. package/dist/cli/export-ui-xliff.d.ts.map +1 -0
  13. package/dist/cli/export-ui-xliff.js +153 -0
  14. package/dist/cli/export-ui-xliff.js.map +1 -0
  15. package/dist/cli/extract-strings.d.ts +12 -0
  16. package/dist/cli/extract-strings.d.ts.map +1 -0
  17. package/dist/cli/extract-strings.js +80 -0
  18. package/dist/cli/extract-strings.js.map +1 -0
  19. package/dist/cli/file-utils.d.ts +10 -0
  20. package/dist/cli/file-utils.d.ts.map +1 -0
  21. package/dist/cli/file-utils.js +77 -0
  22. package/dist/cli/file-utils.js.map +1 -0
  23. package/dist/cli/format.d.ts +21 -0
  24. package/dist/cli/format.d.ts.map +1 -0
  25. package/dist/cli/format.js +75 -0
  26. package/dist/cli/format.js.map +1 -0
  27. package/dist/cli/helpers.d.ts +27 -0
  28. package/dist/cli/helpers.d.ts.map +1 -0
  29. package/dist/cli/helpers.js +84 -0
  30. package/dist/cli/helpers.js.map +1 -0
  31. package/dist/cli/index.d.ts +3 -0
  32. package/dist/cli/index.d.ts.map +1 -0
  33. package/dist/cli/index.js +772 -0
  34. package/dist/cli/index.js.map +1 -0
  35. package/dist/cli/log-output.d.ts +13 -0
  36. package/dist/cli/log-output.d.ts.map +1 -0
  37. package/dist/cli/log-output.js +75 -0
  38. package/dist/cli/log-output.js.map +1 -0
  39. package/dist/cli/translate-svg.d.ts +7 -0
  40. package/dist/cli/translate-svg.d.ts.map +1 -0
  41. package/dist/cli/translate-svg.js +167 -0
  42. package/dist/cli/translate-svg.js.map +1 -0
  43. package/dist/cli/translate-ui-strings.d.ts +27 -0
  44. package/dist/cli/translate-ui-strings.d.ts.map +1 -0
  45. package/dist/cli/translate-ui-strings.js +357 -0
  46. package/dist/cli/translate-ui-strings.js.map +1 -0
  47. package/dist/core/cache-tracking-keys.d.ts +12 -0
  48. package/dist/core/cache-tracking-keys.d.ts.map +1 -0
  49. package/dist/core/cache-tracking-keys.js +20 -0
  50. package/dist/core/cache-tracking-keys.js.map +1 -0
  51. package/dist/core/cache.d.ts +153 -0
  52. package/dist/core/cache.d.ts.map +1 -0
  53. package/dist/core/cache.js +546 -0
  54. package/dist/core/cache.js.map +1 -0
  55. package/dist/core/config.d.ts +58 -0
  56. package/dist/core/config.d.ts.map +1 -0
  57. package/dist/core/config.js +392 -0
  58. package/dist/core/config.js.map +1 -0
  59. package/dist/core/doc-file-tracking.d.ts +8 -0
  60. package/dist/core/doc-file-tracking.d.ts.map +1 -0
  61. package/dist/core/doc-file-tracking.js +27 -0
  62. package/dist/core/doc-file-tracking.js.map +1 -0
  63. package/dist/core/errors.d.ts +19 -0
  64. package/dist/core/errors.d.ts.map +1 -0
  65. package/dist/core/errors.js +23 -0
  66. package/dist/core/errors.js.map +1 -0
  67. package/dist/core/locale-utils.d.ts +20 -0
  68. package/dist/core/locale-utils.d.ts.map +1 -0
  69. package/dist/core/locale-utils.js +75 -0
  70. package/dist/core/locale-utils.js.map +1 -0
  71. package/dist/core/output-paths.d.ts +22 -0
  72. package/dist/core/output-paths.d.ts.map +1 -0
  73. package/dist/core/output-paths.js +130 -0
  74. package/dist/core/output-paths.js.map +1 -0
  75. package/dist/core/prompt-builder.d.ts +62 -0
  76. package/dist/core/prompt-builder.d.ts.map +1 -0
  77. package/dist/core/prompt-builder.js +232 -0
  78. package/dist/core/prompt-builder.js.map +1 -0
  79. package/dist/core/prompts.d.ts +27 -0
  80. package/dist/core/prompts.d.ts.map +1 -0
  81. package/dist/core/prompts.js +57 -0
  82. package/dist/core/prompts.js.map +1 -0
  83. package/dist/core/svg-asset-paths.d.ts +40 -0
  84. package/dist/core/svg-asset-paths.d.ts.map +1 -0
  85. package/dist/core/svg-asset-paths.js +107 -0
  86. package/dist/core/svg-asset-paths.js.map +1 -0
  87. package/dist/core/types.d.ts +388 -0
  88. package/dist/core/types.d.ts.map +1 -0
  89. package/dist/core/types.js +265 -0
  90. package/dist/core/types.js.map +1 -0
  91. package/dist/core/ui-languages.d.ts +66 -0
  92. package/dist/core/ui-languages.d.ts.map +1 -0
  93. package/dist/core/ui-languages.js +277 -0
  94. package/dist/core/ui-languages.js.map +1 -0
  95. package/dist/core/user-edited-model.d.ts +3 -0
  96. package/dist/core/user-edited-model.d.ts.map +1 -0
  97. package/dist/core/user-edited-model.js +3 -0
  98. package/dist/core/user-edited-model.js.map +1 -0
  99. package/dist/edit-cache-app/app.js +1326 -0
  100. package/dist/edit-cache-app/index.html +287 -0
  101. package/dist/edit-cache-app/styles.css +664 -0
  102. package/dist/extractors/base-extractor.d.ts +15 -0
  103. package/dist/extractors/base-extractor.d.ts.map +1 -0
  104. package/dist/extractors/base-extractor.js +23 -0
  105. package/dist/extractors/base-extractor.js.map +1 -0
  106. package/dist/extractors/classify-segment.d.ts +6 -0
  107. package/dist/extractors/classify-segment.d.ts.map +1 -0
  108. package/dist/extractors/classify-segment.js +20 -0
  109. package/dist/extractors/classify-segment.js.map +1 -0
  110. package/dist/extractors/json-extractor.d.ts +16 -0
  111. package/dist/extractors/json-extractor.d.ts.map +1 -0
  112. package/dist/extractors/json-extractor.js +128 -0
  113. package/dist/extractors/json-extractor.js.map +1 -0
  114. package/dist/extractors/markdown-extractor.d.ts +15 -0
  115. package/dist/extractors/markdown-extractor.d.ts.map +1 -0
  116. package/dist/extractors/markdown-extractor.js +205 -0
  117. package/dist/extractors/markdown-extractor.js.map +1 -0
  118. package/dist/extractors/svg-extractor.d.ts +19 -0
  119. package/dist/extractors/svg-extractor.d.ts.map +1 -0
  120. package/dist/extractors/svg-extractor.js +132 -0
  121. package/dist/extractors/svg-extractor.js.map +1 -0
  122. package/dist/extractors/ui-string-extractor.d.ts +40 -0
  123. package/dist/extractors/ui-string-extractor.d.ts.map +1 -0
  124. package/dist/extractors/ui-string-extractor.js +146 -0
  125. package/dist/extractors/ui-string-extractor.js.map +1 -0
  126. package/dist/extractors/ui-string-locations.d.ts +23 -0
  127. package/dist/extractors/ui-string-locations.d.ts.map +1 -0
  128. package/dist/extractors/ui-string-locations.js +138 -0
  129. package/dist/extractors/ui-string-locations.js.map +1 -0
  130. package/dist/glossary/glossary.d.ts +34 -0
  131. package/dist/glossary/glossary.d.ts.map +1 -0
  132. package/dist/glossary/glossary.js +260 -0
  133. package/dist/glossary/glossary.js.map +1 -0
  134. package/dist/glossary/matcher.d.ts +10 -0
  135. package/dist/glossary/matcher.d.ts.map +1 -0
  136. package/dist/glossary/matcher.js +12 -0
  137. package/dist/glossary/matcher.js.map +1 -0
  138. package/dist/index.d.ts +44 -0
  139. package/dist/index.d.ts.map +1 -0
  140. package/dist/index.js +44 -0
  141. package/dist/index.js.map +1 -0
  142. package/dist/processors/admonition-placeholders.d.ts +8 -0
  143. package/dist/processors/admonition-placeholders.d.ts.map +1 -0
  144. package/dist/processors/admonition-placeholders.js +59 -0
  145. package/dist/processors/admonition-placeholders.js.map +1 -0
  146. package/dist/processors/anchor-placeholders.d.ts +8 -0
  147. package/dist/processors/anchor-placeholders.d.ts.map +1 -0
  148. package/dist/processors/anchor-placeholders.js +37 -0
  149. package/dist/processors/anchor-placeholders.js.map +1 -0
  150. package/dist/processors/batch-processor.d.ts +10 -0
  151. package/dist/processors/batch-processor.d.ts.map +1 -0
  152. package/dist/processors/batch-processor.js +33 -0
  153. package/dist/processors/batch-processor.js.map +1 -0
  154. package/dist/processors/bold-code-placeholders.d.ts +14 -0
  155. package/dist/processors/bold-code-placeholders.d.ts.map +1 -0
  156. package/dist/processors/bold-code-placeholders.js +116 -0
  157. package/dist/processors/bold-code-placeholders.js.map +1 -0
  158. package/dist/processors/doc-postprocess.d.ts +51 -0
  159. package/dist/processors/doc-postprocess.d.ts.map +1 -0
  160. package/dist/processors/doc-postprocess.js +215 -0
  161. package/dist/processors/doc-postprocess.js.map +1 -0
  162. package/dist/processors/emphasis-placeholders.d.ts +6 -0
  163. package/dist/processors/emphasis-placeholders.d.ts.map +1 -0
  164. package/dist/processors/emphasis-placeholders.js +262 -0
  165. package/dist/processors/emphasis-placeholders.js.map +1 -0
  166. package/dist/processors/flat-link-rewrite.d.ts +32 -0
  167. package/dist/processors/flat-link-rewrite.d.ts.map +1 -0
  168. package/dist/processors/flat-link-rewrite.js +90 -0
  169. package/dist/processors/flat-link-rewrite.js.map +1 -0
  170. package/dist/processors/glossary-force-placeholders.d.ts +12 -0
  171. package/dist/processors/glossary-force-placeholders.d.ts.map +1 -0
  172. package/dist/processors/glossary-force-placeholders.js +58 -0
  173. package/dist/processors/glossary-force-placeholders.js.map +1 -0
  174. package/dist/processors/inline-code-placeholders.d.ts +11 -0
  175. package/dist/processors/inline-code-placeholders.d.ts.map +1 -0
  176. package/dist/processors/inline-code-placeholders.js +87 -0
  177. package/dist/processors/inline-code-placeholders.js.map +1 -0
  178. package/dist/processors/placeholder-handler.d.ts +38 -0
  179. package/dist/processors/placeholder-handler.d.ts.map +1 -0
  180. package/dist/processors/placeholder-handler.js +55 -0
  181. package/dist/processors/placeholder-handler.js.map +1 -0
  182. package/dist/processors/translation-placeholder-leaks.d.ts +2 -0
  183. package/dist/processors/translation-placeholder-leaks.d.ts.map +1 -0
  184. package/dist/processors/translation-placeholder-leaks.js +9 -0
  185. package/dist/processors/translation-placeholder-leaks.js.map +1 -0
  186. package/dist/processors/url-placeholders.d.ts +10 -0
  187. package/dist/processors/url-placeholders.d.ts.map +1 -0
  188. package/dist/processors/url-placeholders.js +29 -0
  189. package/dist/processors/url-placeholders.js.map +1 -0
  190. package/dist/processors/validator.d.ts +23 -0
  191. package/dist/processors/validator.d.ts.map +1 -0
  192. package/dist/processors/validator.js +186 -0
  193. package/dist/processors/validator.js.map +1 -0
  194. package/dist/runtime/i18next-helpers.d.ts +146 -0
  195. package/dist/runtime/i18next-helpers.d.ts.map +1 -0
  196. package/dist/runtime/i18next-helpers.js +192 -0
  197. package/dist/runtime/i18next-helpers.js.map +1 -0
  198. package/dist/runtime/index.d.ts +4 -0
  199. package/dist/runtime/index.d.ts.map +1 -0
  200. package/dist/runtime/index.js +4 -0
  201. package/dist/runtime/index.js.map +1 -0
  202. package/dist/runtime/template.d.ts +21 -0
  203. package/dist/runtime/template.d.ts.map +1 -0
  204. package/dist/runtime/template.js +28 -0
  205. package/dist/runtime/template.js.map +1 -0
  206. package/dist/runtime/ui-language-display.d.ts +16 -0
  207. package/dist/runtime/ui-language-display.d.ts.map +1 -0
  208. package/dist/runtime/ui-language-display.js +26 -0
  209. package/dist/runtime/ui-language-display.js.map +1 -0
  210. package/dist/server/translation-editor.d.ts +25 -0
  211. package/dist/server/translation-editor.d.ts.map +1 -0
  212. package/dist/server/translation-editor.js +583 -0
  213. package/dist/server/translation-editor.js.map +1 -0
  214. package/dist/utils/concurrency.d.ts +31 -0
  215. package/dist/utils/concurrency.d.ts.map +1 -0
  216. package/dist/utils/concurrency.js +103 -0
  217. package/dist/utils/concurrency.js.map +1 -0
  218. package/dist/utils/hash.d.ts +5 -0
  219. package/dist/utils/hash.d.ts.map +1 -0
  220. package/dist/utils/hash.js +9 -0
  221. package/dist/utils/hash.js.map +1 -0
  222. package/dist/utils/ignore-parser.d.ts +7 -0
  223. package/dist/utils/ignore-parser.d.ts.map +1 -0
  224. package/dist/utils/ignore-parser.js +26 -0
  225. package/dist/utils/ignore-parser.js.map +1 -0
  226. package/dist/utils/logger.d.ts +45 -0
  227. package/dist/utils/logger.d.ts.map +1 -0
  228. package/dist/utils/logger.js +158 -0
  229. package/dist/utils/logger.js.map +1 -0
  230. package/docs/GETTING_STARTED.md +697 -0
  231. package/docs/PACKAGE_OVERVIEW.md +427 -0
  232. package/docs/ai-i18n-tools-context.md +481 -0
  233. package/package.json +117 -0
  234. package/translated-docs/README.de.md +157 -0
  235. package/translated-docs/README.es.md +157 -0
  236. package/translated-docs/README.fr.md +157 -0
  237. package/translated-docs/README.hi.md +157 -0
  238. package/translated-docs/README.ja.md +157 -0
  239. package/translated-docs/README.ko.md +157 -0
  240. package/translated-docs/README.pt-BR.md +157 -0
  241. package/translated-docs/README.zh-CN.md +157 -0
  242. package/translated-docs/README.zh-TW.md +157 -0
  243. package/translated-docs/docs/GETTING_STARTED.de.md +682 -0
  244. package/translated-docs/docs/GETTING_STARTED.es.md +682 -0
  245. package/translated-docs/docs/GETTING_STARTED.fr.md +682 -0
  246. package/translated-docs/docs/GETTING_STARTED.hi.md +682 -0
  247. package/translated-docs/docs/GETTING_STARTED.ja.md +682 -0
  248. package/translated-docs/docs/GETTING_STARTED.ko.md +682 -0
  249. package/translated-docs/docs/GETTING_STARTED.pt-BR.md +682 -0
  250. package/translated-docs/docs/GETTING_STARTED.zh-CN.md +682 -0
  251. package/translated-docs/docs/GETTING_STARTED.zh-TW.md +682 -0
  252. package/translated-docs/docs/PACKAGE_OVERVIEW.de.md +428 -0
  253. package/translated-docs/docs/PACKAGE_OVERVIEW.es.md +428 -0
  254. package/translated-docs/docs/PACKAGE_OVERVIEW.fr.md +428 -0
  255. package/translated-docs/docs/PACKAGE_OVERVIEW.hi.md +428 -0
  256. package/translated-docs/docs/PACKAGE_OVERVIEW.ja.md +428 -0
  257. package/translated-docs/docs/PACKAGE_OVERVIEW.ko.md +428 -0
  258. package/translated-docs/docs/PACKAGE_OVERVIEW.pt-BR.md +428 -0
  259. package/translated-docs/docs/PACKAGE_OVERVIEW.zh-CN.md +428 -0
  260. package/translated-docs/docs/PACKAGE_OVERVIEW.zh-TW.md +428 -0
@@ -0,0 +1,157 @@
1
+ # ai-i18n-tools
2
+
3
+ JavaScript/TypeScript アプリケーションおよびドキュメントサイトの国際化のための CLI およびプログラムによるツールキット。UI 文字列を抽出し、OpenRouter 経由で LLM を使用して翻訳し、i18next 向けのロケール対応 JSON ファイルを生成します。さらに、Markdown、Docusaurus JSON、および(`features.translateSVG`、`translate-svg`、および `svg` ブロックを介して)スタンドアロンの SVG アセット向けのパイプラインも提供します。
4
+
5
+ **他の言語で読む:**
6
+
7
+ <small id="lang-list">[en-GB](../README.md) · [de](./README.de.md) · [es](./README.es.md) · [fr](./README.fr.md) · [hi](./README.hi.md) · [ja](./README.ja.md) · [ko](./README.ko.md) · [pt-BR](./README.pt-BR.md) · [zh-CN](./README.zh-CN.md) · [zh-TW](./README.zh-TW.md)</small>
8
+
9
+ ## 2つの主要なワークフロー
10
+
11
+ **ワークフロー 1 - UI 翻訳** (React, Next.js, Node.js、あらゆる i18next プロジェクト)
12
+
13
+ ソースファイルをスキャンして `t("…")` 呼び出しを検出し、マスターカタログ(オプションのロケールごとの **`models`** メタデータを含む `strings.json`)を構築し、OpenRouter を介してロケールごとに不足しているエントリを翻訳し、i18next で使用できるフラットな JSON ファイル(`de.json`、`pt-BR.json`、…)を書き出します。
14
+
15
+ **ワークフロー 2 - ドキュメント翻訳** (Markdown、Docusaurus JSON)
16
+
17
+ `documentations` ブロックの `contentPaths` にある `.md` および `.mdx` ファイル、およびそのブロックの `jsonSource` にある JSON ラベルファイルを、有効にした場合に翻訳します。ブロックごとに Docusaurus スタイルまたはフラットなロケール接尾辞付きレイアウトをサポート(`documentations[].markdownOutput`)。共有ルートの `cacheDir` に SQLite キャッシュを保持するため、LLM に送信されるのは新規または変更されたセグメントのみです。**SVG:** `features.translateSVG` を有効にし、トップレベルの `svg` ブロックを追加して、`translate-svg` を使用します(両方が設定されている場合、`sync` からも実行されます)。
18
+
19
+ 両方のワークフローは単一の `ai-i18n-tools.config.json` ファイルを共有しており、個別または併用が可能です。スタンドアロンの SVG 翻訳は `features.translateSVG` とトップレベルの `svg` ブロックを使用し、`translate-svg`(または `sync` 内の SVG ステージ)を通じて実行されます。
20
+
21
+ ---
22
+
23
+ ## インストール
24
+
25
+ 公開されているパッケージは **ESM のみ**(`"type": "module"`)です。Node.js、バンドラー、または `import()` から `import` を使用してください — **`require('ai-i18n-tools')` はサポートされていません。**
26
+
27
+ ```bash
28
+ npm install ai-i18n-tools
29
+ # or
30
+ pnpm add ai-i18n-tools
31
+ ```
32
+
33
+ OpenRouter API キーを設定してください:
34
+
35
+ ```bash
36
+ export OPENROUTER_API_KEY=sk-or-v1-your-key-here
37
+ ```
38
+
39
+ ---
40
+
41
+ ## クイックスタート
42
+
43
+ ### ワークフロー 1 - UI 文字列
44
+
45
+ ```bash
46
+ # 1. Create config
47
+ npx ai-i18n-tools init
48
+
49
+ # 2. Extract t("…") calls from source
50
+ npx ai-i18n-tools extract
51
+
52
+ # 3. Translate to all target locales
53
+ npx ai-i18n-tools translate-ui
54
+ ```
55
+
56
+ `'ai-i18n-tools/runtime'` のヘルパーを使用して、アプリに i18next を組み込みます:
57
+
58
+ ```js
59
+ import i18n from 'i18next';
60
+ import { initReactI18next } from 'react-i18next';
61
+ import uiLanguages from './locales/ui-languages.json';
62
+ import {
63
+ defaultI18nInitOptions,
64
+ wrapI18nWithKeyTrim,
65
+ makeLoadLocale,
66
+ applyDirection,
67
+ } from 'ai-i18n-tools/runtime';
68
+
69
+ // Must match sourceLocale in ai-i18n-tools.config.json
70
+ export const SOURCE_LOCALE = 'en-GB';
71
+
72
+ void i18n.use(initReactI18next).init(defaultI18nInitOptions(SOURCE_LOCALE));
73
+ wrapI18nWithKeyTrim(i18n);
74
+ i18n.on('languageChanged', applyDirection);
75
+ applyDirection(i18n.language);
76
+
77
+ const localeLoaders = Object.fromEntries(
78
+ uiLanguages
79
+ .filter(({ code }) => code !== SOURCE_LOCALE)
80
+ .map(({ code }) => [code, () => import(`./locales/${code}.json`)])
81
+ );
82
+ export const loadLocale = makeLoadLocale(i18n, localeLoaders, SOURCE_LOCALE);
83
+ export default i18n;
84
+ ```
85
+
86
+ ### ワークフロー 2 - ドキュメント
87
+
88
+ ```bash
89
+ # 1. Create config for Docusaurus
90
+ npx ai-i18n-tools init -t ui-docusaurus
91
+
92
+ # 2. Translate all docs
93
+ npx ai-i18n-tools translate-docs
94
+
95
+ # 3. Check status
96
+ npx ai-i18n-tools status
97
+ ```
98
+
99
+ ### 両方のワークフロー
100
+
101
+ ```bash
102
+ npx ai-i18n-tools sync # Extract UI strings, then translate UI strings, SVG, and docs
103
+ ```
104
+
105
+ ---
106
+
107
+ ## ランタイムヘルパー
108
+
109
+ `'ai-i18n-tools/runtime'` からエクスポート - あらゆる JS 環境で動作し、i18next のインポートは不要です:
110
+
111
+ | ヘルパー | 説明 |
112
+ |---|---|
113
+ | `defaultI18nInitOptions(sourceLocale)` | キーをデフォルト値として使用する設定のための標準的な i18next 初期化オプション。 |
114
+ | `wrapI18nWithKeyTrim(i18n)` | キーがルックアップ前にトリミングされるように `i18n.t` をラップします。 |
115
+ | `makeLoadLocale(i18n, loaders, sourceLocale)` | 非同期ロケールファイル読み込みのためのファクトリ関数。 |
116
+ | `getTextDirection(lng)` | BCP-47 コードに対して `'ltr'` または `'rtl'` を返します。 |
117
+ | `applyDirection(lng, element?)` | `document.documentElement` に `dir` 属性を設定します。 |
118
+ | `getUILanguageLabel(lang, t)` | 言語メニュー行の表示ラベル(i18n を使用)。 |
119
+ | `getUILanguageLabelNative(lang)` | `t()` を呼び出さない表示ラベル(ヘッダースタイル)。 |
120
+ | `interpolateTemplate(str, vars)` | プレーン文字列に対する `{{var}}` 置換の低レベル関数(内部で使用されます。アプリコードは代わりに `t()` を使用すべきです)。 |
121
+ | `flipUiArrowsForRtl(text, isRtl)` | RTL レイアウトのために `→` を `←` に反転します。 |
122
+
123
+ ---
124
+
125
+ ## CLI コマンド
126
+
127
+ ```
128
+ ai-i18n-tools init [-t ui-markdown|ui-docusaurus] Create config file
129
+ ai-i18n-tools extract Scan source for t("…") calls
130
+ ai-i18n-tools translate-docs [--locale <code>] Translate documentation (markdown, JSON); see docs for
131
+ --force-update, --force, --stats, --clear-cache,
132
+ --prompt-format (xml | json-array | json-object)
133
+ ai-i18n-tools translate-svg [--locale <code>] Standalone SVG assets (features.translateSVG + config.svg); see --no-cache
134
+ ai-i18n-tools translate-ui [--locale <code>] Translate UI strings only; see --force, --dry-run
135
+ ai-i18n-tools export-ui-xliff [--locale <code>] Export UI strings to XLIFF 2.0 (one file per locale); see --untranslated-only, -o
136
+ ai-i18n-tools sync Extract UI strings, then translate UI strings, SVG, and docs
137
+ ai-i18n-tools status Translation status per file × locale
138
+ ai-i18n-tools editor Open cache/glossary web editor
139
+ ai-i18n-tools cleanup [--dry-run] [--no-backup] [--backup <path>] Runs sync --force-update, then cleans stale + orphaned cache rows; backs up SQLite by default
140
+ ai-i18n-tools glossary-generate Create empty glossary CSV template
141
+ ```
142
+
143
+ すべてのコマンドは `-c <config>`(デフォルト: `ai-i18n-tools.config.json`)、`-v`(詳細)、およびオプションの `-w` / `--write-logs [path]` を受け入れ、コンソール出力をログファイルに追加します(デフォルト: 翻訳キャッシュディレクトリの下)。
144
+
145
+ ---
146
+
147
+ ## ドキュメント
148
+
149
+ - [はじめに](docs/GETTING_STARTED.ja.md) - 両方のワークフローの完全なセットアップガイド、すべてのCLIフラグ、および設定フィールドのリファレンス。
150
+ - [パッケージ概要](docs/PACKAGE_OVERVIEW.ja.md) - アーキテクチャ、内部構造、プログラムAPI、および拡張ポイント。
151
+ - [AIエージェントコンテキスト](../docs/ai-i18n-tools-context.md) - コードや設定変更を行うエージェントやメンテナのための簡潔なプロジェクトコンテキスト。
152
+
153
+ ---
154
+
155
+ ## ライセンス
156
+
157
+ MIT © [ヴァルデマール・スカデラー・ジュニア](https://github.com/wsj-br)
@@ -0,0 +1,157 @@
1
+ # ai-i18n-tools
2
+
3
+ JavaScript/TypeScript 애플리케이션 및 문서 사이트의 국제화를 위한 CLI 및 프로그래밍 도구모음입니다. UI 문자열을 추출하고 OpenRouter를 통해 LLM을 사용하여 번역한 후 i18next용 로케일 대응 JSON 파일을 생성하며, 마크다운, Docusaurus JSON, 그리고 (`features.translateSVG`, `translate-svg` 및 `svg` 블록을 통해) 독립형 SVG 자산에 대한 파이프라인도 제공합니다.
4
+
5
+ <small>**다른 언어로 읽기:** </small>
6
+
7
+ <small id="lang-list">[en-GB](../README.md) · [de](./README.de.md) · [es](./README.es.md) · [fr](./README.fr.md) · [hi](./README.hi.md) · [ja](./README.ja.md) · [ko](./README.ko.md) · [pt-BR](./README.pt-BR.md) · [zh-CN](./README.zh-CN.md) · [zh-TW](./README.zh-TW.md)</small>
8
+
9
+ ## 두 가지 핵심 워크플로우
10
+
11
+ **워크플로우 1 - UI 번역** (React, Next.js, Node.js, 모든 i18next 프로젝트)
12
+
13
+ 소스 파일에서 `t("…")` 호출을 스캔하여 마스터 카탈로그(`strings.json` 및 선택적 로케일별 **`models`** 메타데이터 포함)를 구축하고, OpenRouter를 통해 로케일별로 누락된 항목을 번역하며, i18next에 바로 사용 가능한 평면 JSON 파일(`de.json`, `pt-BR.json`, …)을 작성합니다.
14
+
15
+ **워크플로우 2 - 문서 번역** (마크다운, Docusaurus JSON)
16
+
17
+ `documentations` 블록의 `contentPaths`에서 `.md` 및 `.mdx` 파일을, 해당 블록의 `jsonSource`에서 JSON 레이블 파일을 활성화 시 번역합니다. 블록별로 Docusaurus 스타일 또는 단순 로케일 접미사 형식 레이아웃을 지원합니다(`documentations[].markdownOutput`). 공유 루트 `cacheDir`에 SQLite 캐시를 저장하여 새로운 또는 변경된 세그먼트만 LLM으로 전송합니다. **SVG:** `features.translateSVG`를 활성화하고 최상위 `svg` 블록을 추가한 후 `translate-svg`를 사용하세요(둘 다 설정된 경우 `sync`에서도 실행됨).
18
+
19
+ 두 워크플로우는 동일한 `ai-i18n-tools.config.json` 파일을 공유하며 독립적으로 또는 함께 사용할 수 있습니다. 독립형 SVG 번역은 `features.translateSVG`와 최상위 `svg` 블록을 사용하며 `translate-svg`(또는 `sync` 내의 SVG 단계)를 통해 실행됩니다.
20
+
21
+ ---
22
+
23
+ ## 설치
24
+
25
+ 배포된 패키지는 **ESM 전용**입니다(`"type": "module`). Node.js, 번들러 또는 `import()`에서 `import`를 사용하세요 — **`require('ai-i18n-tools')`는 지원되지 않습니다.**
26
+
27
+ ```bash
28
+ npm install ai-i18n-tools
29
+ # or
30
+ pnpm add ai-i18n-tools
31
+ ```
32
+
33
+ OpenRouter API 키를 설정하세요:
34
+
35
+ ```bash
36
+ export OPENROUTER_API_KEY=sk-or-v1-your-key-here
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 빠른 시작
42
+
43
+ ### 워크플로우 1 - UI 문자열
44
+
45
+ ```bash
46
+ # 1. Create config
47
+ npx ai-i18n-tools init
48
+
49
+ # 2. Extract t("…") calls from source
50
+ npx ai-i18n-tools extract
51
+
52
+ # 3. Translate to all target locales
53
+ npx ai-i18n-tools translate-ui
54
+ ```
55
+
56
+ `'ai-i18n-tools/runtime'`의 헬퍼를 사용하여 앱에 i18next를 연결하세요:
57
+
58
+ ```js
59
+ import i18n from 'i18next';
60
+ import { initReactI18next } from 'react-i18next';
61
+ import uiLanguages from './locales/ui-languages.json';
62
+ import {
63
+ defaultI18nInitOptions,
64
+ wrapI18nWithKeyTrim,
65
+ makeLoadLocale,
66
+ applyDirection,
67
+ } from 'ai-i18n-tools/runtime';
68
+
69
+ // Must match sourceLocale in ai-i18n-tools.config.json
70
+ export const SOURCE_LOCALE = 'en-GB';
71
+
72
+ void i18n.use(initReactI18next).init(defaultI18nInitOptions(SOURCE_LOCALE));
73
+ wrapI18nWithKeyTrim(i18n);
74
+ i18n.on('languageChanged', applyDirection);
75
+ applyDirection(i18n.language);
76
+
77
+ const localeLoaders = Object.fromEntries(
78
+ uiLanguages
79
+ .filter(({ code }) => code !== SOURCE_LOCALE)
80
+ .map(({ code }) => [code, () => import(`./locales/${code}.json`)])
81
+ );
82
+ export const loadLocale = makeLoadLocale(i18n, localeLoaders, SOURCE_LOCALE);
83
+ export default i18n;
84
+ ```
85
+
86
+ ### 워크플로우 2 - 문서
87
+
88
+ ```bash
89
+ # 1. Create config for Docusaurus
90
+ npx ai-i18n-tools init -t ui-docusaurus
91
+
92
+ # 2. Translate all docs
93
+ npx ai-i18n-tools translate-docs
94
+
95
+ # 3. Check status
96
+ npx ai-i18n-tools status
97
+ ```
98
+
99
+ ### 두 워크플로우 모두
100
+
101
+ ```bash
102
+ npx ai-i18n-tools sync # Extract UI strings, then translate UI strings, SVG, and docs
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 런타임 헬퍼
108
+
109
+ `'ai-i18n-tools/runtime'`에서 내보내집니다 - 모든 JS 환경에서 작동하며, i18next 가져오기가 필요하지 않습니다:
110
+
111
+ | 헬퍼 | 설명 |
112
+ |---|---|
113
+ | `defaultI18nInitOptions(sourceLocale)` | 키를 기본값으로 사용하는 설정을 위한 표준 i18next 초기화 옵션입니다. |
114
+ | `wrapI18nWithKeyTrim(i18n)` | 키가 조회되기 전에 트리밍되도록 `i18n.t`를 래핑합니다. |
115
+ | `makeLoadLocale(i18n, loaders, sourceLocale)` | 비동기 로케일 파일 로딩을 위한 팩토리 함수입니다. |
116
+ | `getTextDirection(lng)` | BCP-47 코드에 대해 `'ltr'` 또는 `'rtl'`을 반환합니다. |
117
+ | `applyDirection(lng, element?)` | `document.documentElement`에 `dir` 속성을 설정합니다. |
118
+ | `getUILanguageLabel(lang, t)` | 언어 메뉴 행에 대한 표시 레이블입니다(i18n 사용). |
119
+ | `getUILanguageLabelNative(lang)` | `t()`를 호출하지 않는 표시 레이블입니다(헤더 스타일). |
120
+ | `interpolateTemplate(str, vars)` | 일반 문자열에 대한 `{{var}}` 치환을 위한 저수준 함수(내부적으로 사용됨; 앱 코드는 대신 `t()`를 사용해야 함). |
121
+ | `flipUiArrowsForRtl(text, isRtl)` | RTL 레이아웃을 위해 `→`를 `←`로 뒤집습니다. |
122
+
123
+ ---
124
+
125
+ ## CLI 명령어
126
+
127
+ ```
128
+ ai-i18n-tools init [-t ui-markdown|ui-docusaurus] Create config file
129
+ ai-i18n-tools extract Scan source for t("…") calls
130
+ ai-i18n-tools translate-docs [--locale <code>] Translate documentation (markdown, JSON); see docs for
131
+ --force-update, --force, --stats, --clear-cache,
132
+ --prompt-format (xml | json-array | json-object)
133
+ ai-i18n-tools translate-svg [--locale <code>] Standalone SVG assets (features.translateSVG + config.svg); see --no-cache
134
+ ai-i18n-tools translate-ui [--locale <code>] Translate UI strings only; see --force, --dry-run
135
+ ai-i18n-tools export-ui-xliff [--locale <code>] Export UI strings to XLIFF 2.0 (one file per locale); see --untranslated-only, -o
136
+ ai-i18n-tools sync Extract UI strings, then translate UI strings, SVG, and docs
137
+ ai-i18n-tools status Translation status per file × locale
138
+ ai-i18n-tools editor Open cache/glossary web editor
139
+ ai-i18n-tools cleanup [--dry-run] [--no-backup] [--backup <path>] Runs sync --force-update, then cleans stale + orphaned cache rows; backs up SQLite by default
140
+ ai-i18n-tools glossary-generate Create empty glossary CSV template
141
+ ```
142
+
143
+ 모든 명령은 `-c <config>` (기본값: `ai-i18n-tools.config.json`), `-v` (자세한 정보), 및 선택적 `-w` / `--write-logs [path]`를 받아들이며, 콘솔 출력을 로그 파일에 추가합니다 (기본값: 번역 캐시 디렉토리 아래).
144
+
145
+ ---
146
+
147
+ ## 문서
148
+
149
+ - [시작하기](docs/GETTING_STARTED.ko.md) - 두 워크플로우에 대한 전체 설정 가이드, 모든 CLI 플래그 및 구성 필드 참조.
150
+ - [패키지 개요](docs/PACKAGE_OVERVIEW.ko.md) - 아키텍처, 내부 구조, 프로그래밍 API 및 확장 지점.
151
+ - [AI 에이전트 컨텍스트](../docs/ai-i18n-tools-context.md) - 코드 또는 구성 변경을 하는 에이전트 및 유지 관리자를 위한 간결한 프로젝트 컨텍스트.
152
+
153
+ ---
154
+
155
+ ## 라이센스
156
+
157
+ MIT © [Waldemar Scudeller Jr.](https://github.com/wsj-br)
@@ -0,0 +1,157 @@
1
+ # ai-i18n-tools
2
+
3
+ Kit de ferramentas CLI e programático para internacionalização de aplicações e sites de documentação em JavaScript/TypeScript. Extrai strings de interface, traduz com LLMs via OpenRouter e gera arquivos JSON prontos para uso em múltiplos idiomas para o i18next, além de pipelines para markdown, JSON do Docusaurus e (por meio de `features.translateSVG`, `translate-svg` e o bloco `svg`) ativos SVG autônomos.
4
+
5
+ <small>**Leia em outros idiomas:** </small>
6
+
7
+ <small id="lang-list">[en-GB](../README.md) · [de](./README.de.md) · [es](./README.es.md) · [fr](./README.fr.md) · [hi](./README.hi.md) · [ja](./README.ja.md) · [ko](./README.ko.md) · [pt-BR](./README.pt-BR.md) · [zh-CN](./README.zh-CN.md) · [zh-TW](./README.zh-TW.md)</small>
8
+
9
+ ## Dois fluxos de trabalho principais
10
+
11
+ **Fluxo de Trabalho 1 - Tradução de UI** (React, Next.js, Node.js, qualquer projeto i18next)
12
+
13
+ Escaneia arquivos fonte em busca de chamadas `t("…")`, constrói um catálogo mestre (`strings.json` com metadados **`models`** opcionais por localidade), traduz entradas ausentes por localidade via OpenRouter e escreve arquivos JSON planos (`de.json`, `pt-BR.json`, …) prontos para i18next.
14
+
15
+ **Fluxo de Trabalho 2 - Tradução de Documentos** (Markdown, JSON do Docusaurus)
16
+
17
+ Traduz arquivos `.md` e `.mdx` dos `contentPaths` de cada bloco `documentations` e arquivos JSON de rótulos da `jsonSource` desse bloco quando habilitado. Suporta layouts com sufixos de idioma no estilo Docusaurus e layouts planos por bloco (`documentations[].markdownOutput`). O `cacheDir` raiz compartilhado armazena o cache SQLite para que apenas segmentos novos ou alterados sejam enviados ao LLM. **SVG:** habilite `features.translateSVG`, adicione o bloco `svg` no nível superior e use `translate-svg` (também executado por `sync` quando ambos estiverem configurados).
18
+
19
+ Ambos os fluxos de trabalho compartilham um único arquivo `ai-i18n-tools.config.json` e podem ser usados de forma independente ou em conjunto. A tradução autônoma de SVG usa `features.translateSVG` mais o bloco `svg` no nível superior e é executada por meio de `translate-svg` (ou pelo estágio SVG dentro de `sync`).
20
+
21
+ ---
22
+
23
+ ## Instalação
24
+
25
+ O pacote publicado é **apenas ESM** (`"type": "module"`). Use `import` do Node.js, empacotadores ou `import()` — **`require('ai-i18n-tools')` não é suportado.**
26
+
27
+ ```bash
28
+ npm install ai-i18n-tools
29
+ # or
30
+ pnpm add ai-i18n-tools
31
+ ```
32
+
33
+ Defina sua chave de API do OpenRouter:
34
+
35
+ ```bash
36
+ export OPENROUTER_API_KEY=sk-or-v1-your-key-here
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Início rápido
42
+
43
+ ### Fluxo de Trabalho 1 - Strings da UI
44
+
45
+ ```bash
46
+ # 1. Create config
47
+ npx ai-i18n-tools init
48
+
49
+ # 2. Extract t("…") calls from source
50
+ npx ai-i18n-tools extract
51
+
52
+ # 3. Translate to all target locales
53
+ npx ai-i18n-tools translate-ui
54
+ ```
55
+
56
+ Conecte i18next em seu aplicativo usando os auxiliares de `'ai-i18n-tools/runtime'`:
57
+
58
+ ```js
59
+ import i18n from 'i18next';
60
+ import { initReactI18next } from 'react-i18next';
61
+ import uiLanguages from './locales/ui-languages.json';
62
+ import {
63
+ defaultI18nInitOptions,
64
+ wrapI18nWithKeyTrim,
65
+ makeLoadLocale,
66
+ applyDirection,
67
+ } from 'ai-i18n-tools/runtime';
68
+
69
+ // Must match sourceLocale in ai-i18n-tools.config.json
70
+ export const SOURCE_LOCALE = 'en-GB';
71
+
72
+ void i18n.use(initReactI18next).init(defaultI18nInitOptions(SOURCE_LOCALE));
73
+ wrapI18nWithKeyTrim(i18n);
74
+ i18n.on('languageChanged', applyDirection);
75
+ applyDirection(i18n.language);
76
+
77
+ const localeLoaders = Object.fromEntries(
78
+ uiLanguages
79
+ .filter(({ code }) => code !== SOURCE_LOCALE)
80
+ .map(({ code }) => [code, () => import(`./locales/${code}.json`)])
81
+ );
82
+ export const loadLocale = makeLoadLocale(i18n, localeLoaders, SOURCE_LOCALE);
83
+ export default i18n;
84
+ ```
85
+
86
+ ### Fluxo de Trabalho 2 - Documentação
87
+
88
+ ```bash
89
+ # 1. Create config for Docusaurus
90
+ npx ai-i18n-tools init -t ui-docusaurus
91
+
92
+ # 2. Translate all docs
93
+ npx ai-i18n-tools translate-docs
94
+
95
+ # 3. Check status
96
+ npx ai-i18n-tools status
97
+ ```
98
+
99
+ ### Ambos os fluxos de trabalho
100
+
101
+ ```bash
102
+ npx ai-i18n-tools sync # Extract UI strings, then translate UI strings, SVG, and docs
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Auxiliares em tempo de execução
108
+
109
+ Exportado de `'ai-i18n-tools/runtime'` - funciona em qualquer ambiente JS, sem necessidade de importação do i18next:
110
+
111
+ | Auxiliar | Descrição |
112
+ |---|---|
113
+ | `defaultI18nInitOptions(sourceLocale)` | Opções padrão de inicialização do i18next para configurações de chave como padrão. |
114
+ | `wrapI18nWithKeyTrim(i18n)` | Envolve `i18n.t` para que as chaves sejam cortadas antes da busca. |
115
+ | `makeLoadLocale(i18n, loaders, sourceLocale)` | Fábrica para carregamento assíncrono de arquivos de localidade. |
116
+ | `getTextDirection(lng)` | Retorna `'ltr'` ou `'rtl'` para um código BCP-47. |
117
+ | `applyDirection(lng, element?)` | Define o atributo `dir` em `document.documentElement`. |
118
+ | `getUILanguageLabel(lang, t)` | Rótulo exibido para uma linha de menu de idioma (com i18n). |
119
+ | `getUILanguageLabelNative(lang)` | Rótulo exibido sem chamar `t()` (estilo cabeçalho). |
120
+ | `interpolateTemplate(str, vars)` | Substituição de baixo nível `{{var}}` em uma string simples (usado internamente; o código do aplicativo deve usar `t()` em vez disso). |
121
+ | `flipUiArrowsForRtl(text, isRtl)` | Inverte `→` para `←` para layouts RTL. |
122
+
123
+ ---
124
+
125
+ ## Comandos CLI
126
+
127
+ ```
128
+ ai-i18n-tools init [-t ui-markdown|ui-docusaurus] Create config file
129
+ ai-i18n-tools extract Scan source for t("…") calls
130
+ ai-i18n-tools translate-docs [--locale <code>] Translate documentation (markdown, JSON); see docs for
131
+ --force-update, --force, --stats, --clear-cache,
132
+ --prompt-format (xml | json-array | json-object)
133
+ ai-i18n-tools translate-svg [--locale <code>] Standalone SVG assets (features.translateSVG + config.svg); see --no-cache
134
+ ai-i18n-tools translate-ui [--locale <code>] Translate UI strings only; see --force, --dry-run
135
+ ai-i18n-tools export-ui-xliff [--locale <code>] Export UI strings to XLIFF 2.0 (one file per locale); see --untranslated-only, -o
136
+ ai-i18n-tools sync Extract UI strings, then translate UI strings, SVG, and docs
137
+ ai-i18n-tools status Translation status per file × locale
138
+ ai-i18n-tools editor Open cache/glossary web editor
139
+ ai-i18n-tools cleanup [--dry-run] [--no-backup] [--backup <path>] Runs sync --force-update, then cleans stale + orphaned cache rows; backs up SQLite by default
140
+ ai-i18n-tools glossary-generate Create empty glossary CSV template
141
+ ```
142
+
143
+ Todos os comandos aceitam `-c <config>` (padrão: `ai-i18n-tools.config.json`), `-v` (verbose) e opcionalmente `-w` / `--write-logs [caminho]` para adicionar a saída do console a um arquivo de log (padrão: sob o diretório de cache de tradução).
144
+
145
+ ---
146
+
147
+ ## Documentação
148
+
149
+ - [Introdução](docs/GETTING_STARTED.pt-BR.md) - guia completo de configuração para ambos os fluxos de trabalho, todas as flags da CLI e referência de campos de configuração.
150
+ - [Visão Geral do Pacote](docs/PACKAGE_OVERVIEW.pt-BR.md) - arquitetura, internos, API programática e pontos de extensão.
151
+ - [Contexto do Agente de IA](../docs/ai-i18n-tools-context.md) - contexto conciso do projeto para agentes e mantenedores que fazem alterações de código ou configuração.
152
+
153
+ ---
154
+
155
+ ## Licença
156
+
157
+ MIT © [Waldemar Scudeller Jr.](https://github.com/wsj-br)
@@ -0,0 +1,157 @@
1
+ # ai-i18n-tools
2
+
3
+ 用于国际化 JavaScript/TypeScript 应用程序和文档站点的 CLI 和编程工具包。通过 OpenRouter 使用 LLM 提取 UI 字符串并进行翻译,并为 i18next 生成适用于各个语言环境的 JSON 文件,同时提供用于 markdown、Docusaurus JSON 的管道,以及(通过 `features.translateSVG`、`translate-svg` 和 `svg` 块)独立 SVG 资源的处理功能。
4
+
5
+ <small>**以其他语言阅读:**</small>
6
+
7
+ <small id="lang-list">[en-GB](../README.md) · [de](./README.de.md) · [es](./README.es.md) · [fr](./README.fr.md) · [hi](./README.hi.md) · [ja](./README.ja.md) · [ko](./README.ko.md) · [pt-BR](./README.pt-BR.md) · [zh-CN](./README.zh-CN.md) · [zh-TW](./README.zh-TW.md)</small>
8
+
9
+ ## 两种核心工作流
10
+
11
+ **工作流 1 - UI 翻译** (React, Next.js, Node.js, 任何 i18next 项目)
12
+
13
+ 扫描源文件中的 `t("…")` 调用,构建主目录(包含可选按语言区域划分的 **`models`** 元数据的 `strings.json`),通过 OpenRouter 为每个语言区域翻译缺失的条目,并生成可供 i18next 直接使用的扁平化 JSON 文件(`de.json`, `pt-BR.json`, …)。
14
+
15
+ **工作流 2 - 文档翻译** (Markdown, Docusaurus JSON)
16
+
17
+ 启用后,会翻译每个 `documentations` 块中 `contentPaths` 下的 `.md` 和 `.mdx` 文件,以及该块 `jsonSource` 中的 JSON 标签文件。每个块支持 Docusaurus 风格和扁平化带区域设置后缀的布局(`documentations[].markdownOutput`)。共享的根目录 `cacheDir` 用于存放 SQLite 缓存,因此只有新增或更改过的片段才会被发送到 LLM。**SVG:** 启用 `features.translateSVG`,添加顶层 `svg` 块,然后使用 `translate-svg`(当两者都设置时,也会在 `sync` 中运行)。
18
+
19
+ 两种工作流共享同一个 `ai-i18n-tools.config.json` 文件,可以独立使用或结合使用。独立的 SVG 翻译使用 `features.translateSVG` 加上顶层 `svg` 块,并通过 `translate-svg`(或 `sync` 中的 SVG 阶段)运行。
20
+
21
+ ---
22
+
23
+ ## 安装
24
+
25
+ 发布的包是 **仅支持 ESM** 的(`"type": "module"`)。在 Node.js、打包工具或 `import()` 中使用 `import` — **不支持 `require('ai-i18n-tools')`。**
26
+
27
+ ```bash
28
+ npm install ai-i18n-tools
29
+ # or
30
+ pnpm add ai-i18n-tools
31
+ ```
32
+
33
+ 设置您的 OpenRouter API 密钥:
34
+
35
+ ```bash
36
+ export OPENROUTER_API_KEY=sk-or-v1-your-key-here
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 快速开始
42
+
43
+ ### 工作流 1 - UI 字符串
44
+
45
+ ```bash
46
+ # 1. Create config
47
+ npx ai-i18n-tools init
48
+
49
+ # 2. Extract t("…") calls from source
50
+ npx ai-i18n-tools extract
51
+
52
+ # 3. Translate to all target locales
53
+ npx ai-i18n-tools translate-ui
54
+ ```
55
+
56
+ 使用 `'ai-i18n-tools/runtime'` 中的辅助函数在您的应用中配置 i18next:
57
+
58
+ ```js
59
+ import i18n from 'i18next';
60
+ import { initReactI18next } from 'react-i18next';
61
+ import uiLanguages from './locales/ui-languages.json';
62
+ import {
63
+ defaultI18nInitOptions,
64
+ wrapI18nWithKeyTrim,
65
+ makeLoadLocale,
66
+ applyDirection,
67
+ } from 'ai-i18n-tools/runtime';
68
+
69
+ // Must match sourceLocale in ai-i18n-tools.config.json
70
+ export const SOURCE_LOCALE = 'en-GB';
71
+
72
+ void i18n.use(initReactI18next).init(defaultI18nInitOptions(SOURCE_LOCALE));
73
+ wrapI18nWithKeyTrim(i18n);
74
+ i18n.on('languageChanged', applyDirection);
75
+ applyDirection(i18n.language);
76
+
77
+ const localeLoaders = Object.fromEntries(
78
+ uiLanguages
79
+ .filter(({ code }) => code !== SOURCE_LOCALE)
80
+ .map(({ code }) => [code, () => import(`./locales/${code}.json`)])
81
+ );
82
+ export const loadLocale = makeLoadLocale(i18n, localeLoaders, SOURCE_LOCALE);
83
+ export default i18n;
84
+ ```
85
+
86
+ ### 工作流 2 - 文档
87
+
88
+ ```bash
89
+ # 1. Create config for Docusaurus
90
+ npx ai-i18n-tools init -t ui-docusaurus
91
+
92
+ # 2. Translate all docs
93
+ npx ai-i18n-tools translate-docs
94
+
95
+ # 3. Check status
96
+ npx ai-i18n-tools status
97
+ ```
98
+
99
+ ### 两种工作流
100
+
101
+ ```bash
102
+ npx ai-i18n-tools sync # Extract UI strings, then translate UI strings, SVG, and docs
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 运行时辅助函数
108
+
109
+ 从 `'ai-i18n-tools/runtime'` 导出 - 适用于任何 JavaScript 环境,无需导入 i18next:
110
+
111
+ | 辅助函数 | 描述 |
112
+ |---|---|
113
+ | `defaultI18nInitOptions(sourceLocale)` | 适用于以键作为默认值的标准 i18next 初始化选项。 |
114
+ | `wrapI18nWithKeyTrim(i18n)` | 包装 `i18n.t`,使其在查找前对键进行修剪。 |
115
+ | `makeLoadLocale(i18n, loaders, sourceLocale)` | 用于异步加载语言区域文件的工厂函数。 |
116
+ | `getTextDirection(lng)` | 根据 BCP-47 代码返回 `'ltr'` 或 `'rtl'`。 |
117
+ | `applyDirection(lng, element?)` | 在 `document.documentElement` 上设置 `dir` 属性。 |
118
+ | `getUILanguageLabel(lang, t)` | 用于语言菜单行的显示标签(使用 i18n)。 |
119
+ | `getUILanguageLabelNative(lang)` | 不调用 `t()` 的显示标签(标题样式)。 |
120
+ | `interpolateTemplate(str, vars)` | 对纯字符串进行 `{{var}}` 替换的低级函数(内部使用;应用代码应使用 `t()`)。 |
121
+ | `flipUiArrowsForRtl(text, isRtl)` | 为 RTL 布局翻转 `→` 为 `←`。 |
122
+
123
+ ---
124
+
125
+ ## CLI 命令
126
+
127
+ ```
128
+ ai-i18n-tools init [-t ui-markdown|ui-docusaurus] Create config file
129
+ ai-i18n-tools extract Scan source for t("…") calls
130
+ ai-i18n-tools translate-docs [--locale <code>] Translate documentation (markdown, JSON); see docs for
131
+ --force-update, --force, --stats, --clear-cache,
132
+ --prompt-format (xml | json-array | json-object)
133
+ ai-i18n-tools translate-svg [--locale <code>] Standalone SVG assets (features.translateSVG + config.svg); see --no-cache
134
+ ai-i18n-tools translate-ui [--locale <code>] Translate UI strings only; see --force, --dry-run
135
+ ai-i18n-tools export-ui-xliff [--locale <code>] Export UI strings to XLIFF 2.0 (one file per locale); see --untranslated-only, -o
136
+ ai-i18n-tools sync Extract UI strings, then translate UI strings, SVG, and docs
137
+ ai-i18n-tools status Translation status per file × locale
138
+ ai-i18n-tools editor Open cache/glossary web editor
139
+ ai-i18n-tools cleanup [--dry-run] [--no-backup] [--backup <path>] Runs sync --force-update, then cleans stale + orphaned cache rows; backs up SQLite by default
140
+ ai-i18n-tools glossary-generate Create empty glossary CSV template
141
+ ```
142
+
143
+ 所有命令都接受 `-c <config>`(默认值:`ai-i18n-tools.config.json`)、`-v`(详细模式)以及可选的 `-w` / `--write-logs [path]`,用于将控制台输出附加到日志文件(默认值:在翻译缓存目录下)。
144
+
145
+ ---
146
+
147
+ ## 文档
148
+
149
+ - [入门指南](docs/GETTING_STARTED.zh-CN.md) - 包含两种工作流程的完整设置指南、所有 CLI 标志和配置字段参考。
150
+ - [包概述](docs/PACKAGE_OVERVIEW.zh-CN.md) - 架构、内部结构、编程 API 和扩展点。
151
+ - [AI 代理上下文](../docs/ai-i18n-tools-context.md) - 为进行代码或配置更改的代理和维护者提供简明的项目上下文。
152
+
153
+ ---
154
+
155
+ ## 许可证
156
+
157
+ MIT © [Waldemar Scudeller Jr.](https://github.com/wsj-br)