@scopeact/autoi18n 1.1.1 → 1.2.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 (46) hide show
  1. package/dist/chunk-36HQJSGI.cjs +40 -0
  2. package/dist/chunk-36HQJSGI.cjs.map +1 -0
  3. package/dist/chunk-NYRK5OWZ.js +40 -0
  4. package/dist/chunk-NYRK5OWZ.js.map +1 -0
  5. package/dist/chunk-RLNUAAKC.js +296 -0
  6. package/dist/chunk-RLNUAAKC.js.map +1 -0
  7. package/dist/chunk-TJT6ONON.cjs +41 -0
  8. package/dist/chunk-TJT6ONON.cjs.map +1 -0
  9. package/dist/chunk-TWTG4RTI.cjs +296 -0
  10. package/dist/chunk-TWTG4RTI.cjs.map +1 -0
  11. package/dist/chunk-VBBY4GSW.js +41 -0
  12. package/dist/chunk-VBBY4GSW.js.map +1 -0
  13. package/dist/cli.cjs +18 -0
  14. package/dist/cli.cjs.map +1 -0
  15. package/dist/cli.d.cts +1 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +18 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/client.cjs +10 -0
  20. package/dist/client.cjs.map +1 -0
  21. package/dist/client.d.cts +17 -0
  22. package/dist/client.d.ts +17 -0
  23. package/dist/client.js +10 -0
  24. package/dist/client.js.map +1 -0
  25. package/dist/core/index.cjs +9 -0
  26. package/dist/core/index.cjs.map +1 -0
  27. package/dist/core/index.d.cts +4 -0
  28. package/dist/core/index.d.ts +4 -0
  29. package/dist/core/index.js +9 -0
  30. package/dist/core/index.js.map +1 -0
  31. package/dist/index.cjs +21 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +5 -0
  34. package/dist/index.d.ts +5 -3
  35. package/dist/index.js +20 -18
  36. package/dist/index.js.map +1 -1
  37. package/dist/server.cjs +9 -0
  38. package/dist/server.cjs.map +1 -0
  39. package/dist/server.d.cts +10 -0
  40. package/dist/server.d.ts +10 -0
  41. package/dist/server.js +9 -0
  42. package/dist/server.js.map +1 -0
  43. package/package.json +79 -26
  44. package/schema.json +51 -0
  45. package/README.md +0 -256
  46. package/dist/index.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/auto-i18n/auto-i18n/packages/autoi18n/dist/server.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,qGAAC","file":"/home/runner/work/auto-i18n/auto-i18n/packages/autoi18n/dist/server.cjs"}
@@ -0,0 +1,10 @@
1
+ declare function getI18nConfig(defaultLang?: string): Promise<{
2
+ locale: any;
3
+ messages: Record<string, string>;
4
+ }>;
5
+ declare function getI18n(): Promise<{
6
+ t: (key: string) => string;
7
+ locale: any;
8
+ }>;
9
+
10
+ export { getI18n, getI18nConfig };
@@ -0,0 +1,10 @@
1
+ declare function getI18nConfig(defaultLang?: string): Promise<{
2
+ locale: any;
3
+ messages: Record<string, string>;
4
+ }>;
5
+ declare function getI18n(): Promise<{
6
+ t: (key: string) => string;
7
+ locale: any;
8
+ }>;
9
+
10
+ export { getI18n, getI18nConfig };
package/dist/server.js ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ getI18n,
3
+ getI18nConfig
4
+ } from "./chunk-VBBY4GSW.js";
5
+ export {
6
+ getI18n,
7
+ getI18nConfig
8
+ };
9
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,26 +1,79 @@
1
- {
2
- "name": "@scopeact/autoi18n",
3
- "version": "1.1.1",
4
- "type": "module",
5
- "bin": {
6
- "@scopeact/autoi18n": "./dist/index.js"
7
- },
8
- "files": [
9
- "dist"
10
- ],
11
- "scripts": {
12
- "build": "tsc"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/felipevetter/auto-i18n.git"
17
- },
18
- "dependencies": {
19
- "@scopeact/autoi18n-core": "*",
20
- "commander": "^14.0.2",
21
- "chalk": "^5.6.2",
22
- "dotenv": "^17.2.3",
23
- "ora": "^9.0.0",
24
- "ts-morph": "^27.0.2"
25
- }
26
- }
1
+ {
2
+ "name": "@scopeact/autoi18n",
3
+ "version": "1.2.0",
4
+ "description": "Auto i18n tool",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/felipevetter/auto-i18n.git"
12
+ },
13
+ "bin": {
14
+ "@scopeact/autoi18n": "./dist/cli.js"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ },
22
+ "./core": {
23
+ "types": "./dist/core/index.d.ts",
24
+ "import": "./dist/core/index.js",
25
+ "require": "./dist/core/index.cjs"
26
+ },
27
+ "./server": {
28
+ "types": "./dist/server.d.ts",
29
+ "import": "./dist/server.js",
30
+ "require": "./dist/server.cjs"
31
+ },
32
+ "./client": {
33
+ "types": "./dist/client.d.ts",
34
+ "import": "./dist/client.js",
35
+ "require": "./dist/client.cjs"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "schema.json"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "lint": "tsc --noEmit"
46
+ },
47
+ "keywords": [
48
+ "i18n",
49
+ "translation",
50
+ "automation",
51
+ "ai"
52
+ ],
53
+ "author": "Felipe Vetter",
54
+ "license": "MIT",
55
+ "peerDependencies": {
56
+ "next": ">=13.0.0",
57
+ "react": ">=18.0.0",
58
+ "react-dom": ">=18.0.0"
59
+ },
60
+ "dependencies": {
61
+ "@google/generative-ai": "^0.24.1",
62
+ "chalk": "^5.6.2",
63
+ "commander": "^14.0.2",
64
+ "dotenv": "^17.2.3",
65
+ "openai": "^6.14.0",
66
+ "ora": "^9.0.0",
67
+ "ts-morph": "^27.0.2"
68
+ },
69
+ "devDependencies": {
70
+ "@types/node": "^25.0.3",
71
+ "@types/react": "^19.2.7",
72
+ "@types/react-dom": "^19.2.3",
73
+ "next": "^16.1.1",
74
+ "react": "^19.2.3",
75
+ "react-dom": "^19.2.3",
76
+ "tsup": "^8.5.1",
77
+ "typescript": "^5.9.3"
78
+ }
79
+ }
package/schema.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Auto i18n Config",
4
+ "type": "object",
5
+ "properties": {
6
+ "sourceLang": {
7
+ "type": "string",
8
+ "description": "O idioma de origem dos textos no seu código.",
9
+ "default": "pt"
10
+ },
11
+ "targetLangs": {
12
+ "type": "array",
13
+ "items": { "type": "string" },
14
+ "description": "Lista de idiomas para os quais você deseja traduzir."
15
+ },
16
+ "files": {
17
+ "type": "array",
18
+ "items": { "type": "string" },
19
+ "description": "Glob patterns dos arquivos que o CLI deve escanear.",
20
+ "default": ["src/**/*.tsx"]
21
+ },
22
+ "autoInject": {
23
+ "type": "boolean",
24
+ "description": "Se deve automaticamente injetar no topo do arquivo o import de i18n (caso não exista).",
25
+ "default": true
26
+ },
27
+ "i18nLibrary": {
28
+ "type": "string",
29
+ "description": "A biblioteca de i18n que será utilizada.",
30
+ "default": "react-i18next",
31
+ "enum": ["react-i18next", "next-i18n"]
32
+ },
33
+ "provider": {
34
+ "type": "string",
35
+ "description": "O Provider de IA que será utilizado para tradução.",
36
+ "default": "openai",
37
+ "enum": ["openai", "google", "deepseek", "openrouter", "ollama"]
38
+ },
39
+ "model": {
40
+ "type": "string",
41
+ "description": "O modelo de IA que será utilizado para tradução.",
42
+ "default": "gpt-3.5-turbo"
43
+ },
44
+ "localesDir": {
45
+ "type": "string",
46
+ "description": "O diretório onde os arquivos JSON de tradução estão localizados.",
47
+ "default": "./locales"
48
+ }
49
+ },
50
+ "required": ["sourceLang", "targetLangs", "localesDir"]
51
+ }
package/README.md DELETED
@@ -1,256 +0,0 @@
1
- # @scopeact/autoi18n
2
-
3
- [![npm version](https://img.shields.io/npm/v/@scopeact/autoi18n.svg)](https://www.npmjs.com/package/@scopeact/autoi18n)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
-
6
- > CLI to automatically migrate React / TypeScript projects to i18n using AST and LLMs.
7
-
8
- **auto-i18n** scans TS/TSX files, extracts hardcoded strings, replaces them with `t("key")`, generates translation files, and optionally injects the correct i18n imports — all with explicit, opinionated trade-offs.
9
-
10
- This is a **migration tool**, not a runtime framework.
11
-
12
- ---
13
-
14
- ## Why this exists
15
-
16
- Internationalizing a React codebase usually means:
17
-
18
- * Manually hunting hardcoded strings
19
- * Guessing translation keys
20
- * Rewriting components by hand
21
- * Copy-pasting JSON across languages
22
-
23
- It’s repetitive, boring, and easy to screw up.
24
-
25
- **auto-i18n automates the mechanical work and delegates semantic decisions to an LLM.**
26
-
27
- ---
28
-
29
- ## What this tool does
30
-
31
- * Parses **TypeScript and TSX using AST** (no regex hacks)
32
- * Detects static hardcoded strings
33
- * Rewrites code to use `t("key")`
34
- * Generates translation files
35
- * Uses an **LLM to generate semantic translation keys**
36
- * Optionally injects i18n imports automatically
37
- * Supports different i18n libraries
38
-
39
- ---
40
-
41
- ## Installation
42
-
43
- No global install required:
44
-
45
- ```bash
46
- npx @scopeact/auto-i18n init
47
- ```
48
-
49
- ---
50
-
51
- ## Usage
52
-
53
- ### 1. Initialize configuration
54
-
55
- ```bash
56
- npx @scopeact/auto-i18n init
57
- ```
58
-
59
- This creates:
60
-
61
- * `auto-i18n.config.json`
62
-
63
- ---
64
-
65
- ### 2. Run the migration
66
-
67
- ```bash
68
- npx @scopeact/auto-i18n run
69
- ```
70
-
71
- The tool will:
72
-
73
- 1. Parse files into AST
74
- 2. Detect static string literals
75
- 3. Ask the LLM to infer **semantic translation keys**
76
- 4. Rewrite source code
77
- 5. Inject i18n imports if missing
78
- 6. Generate translation files
79
-
80
- ---
81
-
82
- ## Example
83
-
84
- ### Before
85
-
86
- ```tsx
87
- export function Home() {
88
- return (
89
- <div>
90
- <h1>Hello world</h1>
91
- <p>Welcome to our platform</p>
92
- </div>
93
- );
94
- }
95
- ```
96
-
97
- ### After
98
-
99
- ```tsx
100
- import { useTranslation } from "react-i18next";
101
-
102
- export function Home() {
103
- return (
104
- <div>
105
- <h1>{t("greeting")}</h1>
106
- <p>{t("description")}</p>
107
- </div>
108
- );
109
- }
110
- ```
111
-
112
- Generated translation file:
113
-
114
- ```json
115
- {
116
- "greeting": "Hello world",
117
- "description": "Welcome to our platform"
118
- }
119
- ```
120
-
121
- ---
122
-
123
- ## Configuration
124
-
125
- Example `auto-i18n.config.json`:
126
-
127
- ```json
128
- {
129
- "sourceLang": "pt",
130
- "targetLangs": [ "en", "es", "de" ],
131
- "autoInject": true,
132
- "i18nLibrary": "react-i18next",
133
- "provider": "ollama",
134
- "localesDir": "./locales",
135
- "model": "gemma3-translator",
136
- "files": [ "**/*.tsx" ]
137
- }
138
- ```
139
-
140
- ### Options
141
-
142
- #### `autoInject`
143
-
144
- ```json
145
- {
146
- "autoInject": true
147
- }
148
- ```
149
-
150
- Automatically injects the required i18n import at the top of the file **if it does not already exist**.
151
-
152
- This avoids manual setup and keeps the migration fully automated.
153
-
154
- ---
155
-
156
- #### `i18nLibrary`
157
-
158
- ```json
159
- {
160
- "i18nLibrary": "react-i18next"
161
- }
162
- ```
163
-
164
- Defines which i18n library should be used when injecting imports and hooks.
165
-
166
- Supported values:
167
-
168
- * `react-i18next`
169
- * `next-i18n`
170
-
171
- This affects:
172
-
173
- * import statements
174
- * generated code structure
175
-
176
- ---
177
-
178
- ## Why keys are AI-generated (no dry-run)
179
-
180
- Translation key naming is a **semantic problem**, not a mechanical one.
181
-
182
- For example:
183
-
184
- * Is `"Hello world"` a title, a CTA, or a heading?
185
- * Does it belong to `home`, `layout`, or `marketing`?
186
-
187
- These decisions cannot be inferred deterministically.
188
-
189
- **auto-i18n intentionally requires an LLM to:**
190
-
191
- * infer intent
192
- * generate meaningful keys
193
- * avoid arbitrary conventions
194
-
195
- Because of this, a traditional dry-run would produce **misleading results** and is intentionally not supported.
196
-
197
- This trade-off is explicit.
198
-
199
- ---
200
-
201
- ## Why AST instead of regex
202
-
203
- Regex does not understand JSX or TypeScript.
204
-
205
- AST parsing:
206
-
207
- * Preserves syntax structure
208
- * Avoids accidental replacements
209
- * Handles real-world React code
210
- * Produces predictable transformations
211
-
212
- This tool is designed for **production codebases**, not demos.
213
-
214
- ---
215
-
216
- ## Limitations
217
-
218
- This tool does **not** handle:
219
-
220
- * Dynamic strings (`"Hello " + name`)
221
- * Template literals with expressions
222
- * Runtime-generated text
223
- * Context-dependent translations
224
-
225
- It is meant to **bootstrap i18n**, not replace human review.
226
-
227
- ---
228
-
229
- ## When you should NOT use this
230
-
231
- * Your project already has a mature i18n setup
232
- * Translations depend heavily on runtime logic
233
- * You expect zero review after migration
234
-
235
- ---
236
-
237
- ## Design philosophy
238
-
239
- * Explicit over clever
240
- * Predictable over magical
241
- * Narrow scope over feature bloat
242
-
243
- This tool solves **one specific problem**, deliberately.
244
-
245
- ---
246
-
247
- ## License
248
-
249
- Distributed under MIT license. See [LICENSE](LICENSE) for more details.
250
-
251
- ---
252
-
253
- ## 🇧🇷 Nota
254
-
255
- README principal em inglês por usabilidade global.
256
- Português aqui só pra lembrar que esse projeto nasceu no Brasil.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}