@scopeact/autoi18n 1.2.0 โ 1.2.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 +117 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
|
|
2
|
+
# @scopeact/autoi18n
|
|
3
|
+
|
|
4
|
+
[](https://www.npmjs.com/package/@scopeact/autoi18n)
|
|
5
|
+
[](https://github.com/felipevetter/auto-i18n/actions)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://github.com/felipevetter/auto-i18n/pulls)
|
|
8
|
+
|
|
9
|
+
> The only i18n tool that handles both **Extraction** (via AST + AI) and **Runtime** (Zero-Config).
|
|
10
|
+
|
|
11
|
+
**autoi18n** is a dual-purpose tool designed to take a hardcoded React/Next.js project to full internationalization in minutes, not hours.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## โก The Core: CLI Migration
|
|
16
|
+
|
|
17
|
+
The CLI scans your `TSX` files, extracts hardcoded strings using **Abstract Syntax Tree (AST)**, and uses **AI to generate semantic keys**.
|
|
18
|
+
|
|
19
|
+
- **No Regex:** Safe code transformations that won't break your syntax.
|
|
20
|
+
- **AI-Powered:** Keys like `welcome_title` instead of `text_1`.
|
|
21
|
+
- **Auto-Inject:** Automatically adds imports to your files.
|
|
22
|
+
|
|
23
|
+
### Quick Start
|
|
24
|
+
```bash
|
|
25
|
+
npx @scopeact/autoi18n init
|
|
26
|
+
npx @scopeact/autoi18n run
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ๐ The Feature: Zero-Config Runtime
|
|
32
|
+
|
|
33
|
+
We noticed that even after extracting strings, configuring i18n in **Next.js (App Router)** is a nightmare (Middleware, `[locale]` folders, etc).
|
|
34
|
+
|
|
35
|
+
So we built a **minimalist, high-performance runtime** specifically for the CLI output.
|
|
36
|
+
|
|
37
|
+
### 1. Setup the Provider (Root Layout)
|
|
38
|
+
No need to move files into `[locale]` folders. Just wrap your layout.
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
// app/layout.tsx
|
|
42
|
+
import { I18nProvider } from "@scopeact/autoi18n/client";
|
|
43
|
+
import { getI18nConfig } from "@scopeact/autoi18n/server";
|
|
44
|
+
|
|
45
|
+
export default async function RootLayout({ children }) {
|
|
46
|
+
const i18n = await getI18nConfig('en'); // Default language
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<html lang={i18n.locale}>
|
|
50
|
+
<body>
|
|
51
|
+
<I18nProvider locale={i18n.locale} messages={i18n.messages}>
|
|
52
|
+
{children}
|
|
53
|
+
</I18nProvider>
|
|
54
|
+
</body>
|
|
55
|
+
</html>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2. Usage in Server Components
|
|
61
|
+
```tsx
|
|
62
|
+
// app/page.tsx (Server)
|
|
63
|
+
import { getI18n } from '@scopeact/autoi18n/server';
|
|
64
|
+
|
|
65
|
+
export default async function Page() {
|
|
66
|
+
const { t } = await getI18n();
|
|
67
|
+
return <h1>{t("hero_title")}</h1>;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3. Usage in Client Components
|
|
72
|
+
```tsx
|
|
73
|
+
// components/Button.tsx (Client)
|
|
74
|
+
'use client';
|
|
75
|
+
import { useI18n } from '@scopeact/autoi18n/client';
|
|
76
|
+
|
|
77
|
+
export function HeroButton() {
|
|
78
|
+
const { t } = useI18n();
|
|
79
|
+
return <button>{t("get_started")}</button>;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## ๐ Configuration
|
|
86
|
+
|
|
87
|
+
Created via `init`, the `auto-i18n.config.json` controls the magic:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"sourceLang": "pt",
|
|
92
|
+
"targetLangs": ["en", "es"],
|
|
93
|
+
"i18nLibrary": "@scopeact/autoi18n",
|
|
94
|
+
"provider": "openai",
|
|
95
|
+
"localesDir": "./locales",
|
|
96
|
+
"files": ["src/**/*.tsx"]
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## ๐ Why autoi18n?
|
|
103
|
+
|
|
104
|
+
| Feature | Tradicional (next-intl/i18next) | **autoi18n** |
|
|
105
|
+
| :--- | :--- | :--- |
|
|
106
|
+
| **Key Creation** | Manual (Hours of copy-paste) | **AI-Automated** (Seconds) |
|
|
107
|
+
| **Code Rewrite** | Manual | **AST-Automated** |
|
|
108
|
+
| **Folder Structure** | Forced `[locale]` nesting | **Stay as you are** |
|
|
109
|
+
| **Next.js Setup** | Complex (Middleware/Config) | **Zero-Config** |
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## ๐ง๐ท Born in Brazil
|
|
114
|
+
Projeto desenvolvido com foco em resolver a dor real de desenvolvedores que precisam entregar projetos globais rรกpido.
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
MIT ยฉ [Felipe Vetter](https://github.com/felipevetter)
|