shallok 0.1.1 → 0.1.3
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 +132 -24
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/package.json +10 -11
- package/skills/astro-localization-and-translation-i18n/SKILL.md +105 -32
- package/skills/astro-localization-and-translation-i18n/references/astro-i18n.md +15 -0
- package/skills/astro-localization-and-translation-i18n/references/extraction.md +6 -1
- package/skills/astro-localization-and-translation-i18n/references/frameworks.md +59 -0
- package/skills/astro-localization-and-translation-i18n/references/translation.md +30 -4
- package/skills/astro-localization-and-translation-i18n/references/versioning.md +22 -6
- package/skills/expo-localization-and-translation-i18n/SKILL.md +116 -35
- package/skills/expo-localization-and-translation-i18n/references/expo-localization.md +56 -11
- package/skills/expo-localization-and-translation-i18n/references/extraction.md +6 -1
- package/skills/expo-localization-and-translation-i18n/references/frameworks.md +59 -0
- package/skills/expo-localization-and-translation-i18n/references/translation.md +30 -4
- package/skills/expo-localization-and-translation-i18n/references/versioning.md +22 -6
- package/skills/localization-and-translation-i18n/SKILL.md +116 -28
- package/skills/localization-and-translation-i18n/references/extraction.md +6 -1
- package/skills/localization-and-translation-i18n/references/frameworks.md +26 -7
- package/skills/localization-and-translation-i18n/references/translation.md +30 -4
- package/skills/localization-and-translation-i18n/references/versioning.md +22 -6
- package/skills/nextjs-localization-and-translation-i18n/SKILL.md +107 -35
- package/skills/nextjs-localization-and-translation-i18n/references/extraction.md +6 -1
- package/skills/nextjs-localization-and-translation-i18n/references/frameworks.md +59 -0
- package/skills/nextjs-localization-and-translation-i18n/references/next-intl.md +14 -2
- package/skills/nextjs-localization-and-translation-i18n/references/translation.md +30 -4
- package/skills/nextjs-localization-and-translation-i18n/references/versioning.md +22 -6
- package/skills/react-localization-and-translation-i18n/SKILL.md +116 -35
- package/skills/react-localization-and-translation-i18n/references/extraction.md +6 -1
- package/skills/react-localization-and-translation-i18n/references/frameworks.md +59 -0
- package/skills/react-localization-and-translation-i18n/references/react-i18next.md +54 -8
- package/skills/react-localization-and-translation-i18n/references/translation.md +30 -4
- package/skills/react-localization-and-translation-i18n/references/versioning.md +22 -6
- package/skills/localize-app/SKILL.md +0 -80
- package/skills/localize-app/references/extraction.md +0 -29
- package/skills/localize-app/references/frameworks.md +0 -25
- package/skills/localize-app/references/translation.md +0 -45
- package/skills/localize-app/references/versioning.md +0 -57
|
@@ -14,20 +14,95 @@ Use this skill when asked to add, configure, update, or audit localization in **
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
## Agent Step 0:
|
|
17
|
+
## Agent Step 0: Mandatory Pre-Flight Checklist (Run Before ANY Code or Config Changes)
|
|
18
18
|
|
|
19
|
-
**Before
|
|
19
|
+
**Before making ANY changes to a new repo or an existing repo, you (the AI Agent) MUST execute the following checks in order:**
|
|
20
20
|
|
|
21
|
-
1. Check
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
### 1. Check if Shallok is Installed
|
|
22
|
+
- Inspect `package.json` for `"shallok"` or `"@shallok/cli"` in `devDependencies` (or `dependencies`), or run:
|
|
23
|
+
```bash
|
|
24
|
+
npx shallok --version
|
|
25
|
+
```
|
|
26
|
+
- **If `shallok` is NOT installed, install it immediately into `devDependencies`:**
|
|
27
|
+
- If `pnpm-lock.yaml` exists: `pnpm add -D shallok`
|
|
28
|
+
- If `yarn.lock` exists: `yarn add -D shallok`
|
|
29
|
+
- If `bun.lockb` / `bun.lock` exists: `bun add -d shallok`
|
|
30
|
+
- Otherwise: `npm install -D shallok`
|
|
31
|
+
|
|
32
|
+
### 2. Check if `localization.json` and `localization_base/` Exist
|
|
33
|
+
- Verify that `localization.json` exists in the project root.
|
|
34
|
+
- Verify that the `localization_base/` directory exists with `<source_locale>.json` and `metadata.json`.
|
|
35
|
+
- **If either does NOT exist, create them using Shallok:**
|
|
36
|
+
```bash
|
|
37
|
+
shallok init --source en --locales kn,hi --framework <name> --yes
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. NEVER Delete `localization.json` or `localization_base/`
|
|
41
|
+
> [!CAUTION]
|
|
42
|
+
> **CRITICAL PERSISTENCE RULE: NEVER DELETE `localization.json` OR `localization_base/`!**
|
|
43
|
+
> - `localization.json` is the single source-of-truth project manifest.
|
|
44
|
+
> - `localization_base/` contains the canonical catalog (`<source_locale>.json`) with per-key version numbers (`key_version`), cryptographic content hashes (`sha256:`), source code occurrences, and enriched semantic context, alongside `metadata.json`.
|
|
45
|
+
> - **Under NO circumstances should you EVER delete `localization.json` or `localization_base/`**. Deleting them destroys the versioning history, wipes out human- and AI-enriched context, resets version counters, breaks incremental translation, and corrupts catalog synchronization.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Core Architectural & Formatting Rules
|
|
50
|
+
|
|
51
|
+
### Rule 1: Always Use Normalized Paths for Keys (Never Object-Based Paths)
|
|
52
|
+
- **Always use normalized dot-separated key paths**: e.g., `"auth.login.title"`, `"checkout.pay_now"`, `"settings.profile.change_password"`.
|
|
53
|
+
- **Never use nested object-based paths**: Do not structure keys or catalogs as nested JSON objects (e.g., `{ "auth": { "login": { "title": "..." } } }`). All keys in `localization_base/<source_locale>.json`, `messages/<locale>.json`, and runtime bundles MUST be flat normalized string paths.
|
|
54
|
+
- **If an existing project is using object-based keys**:
|
|
55
|
+
- **STOP and ask the user** for confirmation to flatten them into normalized dot-separated key paths before proceeding with extraction or catalog edits.
|
|
56
|
+
- Explain that normalized dot-paths are required for deterministic AST extraction, per-key versioning, and collision-free reconciliation.
|
|
57
|
+
- Upon user approval, migrate and flatten all nested keys to normalized dot-paths.
|
|
58
|
+
|
|
59
|
+
### Rule 2: Always Use the `messages/` Directory Structure (Ask User & Migrate If Different)
|
|
60
|
+
- **Standard translations folder**: Shallok strictly standardizes on `messages/` for authoritative locale catalogs (`messages/<locale>.json`) and compiled runtime bundles (`messages/runtime/<locale>.json`).
|
|
61
|
+
- **If the project uses any other folder structure** (e.g., `locales/`, `src/locales/`, `translations/`, `lang/`, `src/i18n/locales/`):
|
|
62
|
+
- **STOP and ask the user** for approval to switch to the standardized `messages/` directory structure.
|
|
63
|
+
- Upon user approval, **migrate** all existing translation files into `messages/`, update framework configuration and import paths, reconcile existing strings into `localization_base/`, and clean up the old directory.
|
|
64
|
+
|
|
65
|
+
### Rule 3: Check Context for All Keys in `localization_base/{source_locale}` Before Translating
|
|
66
|
+
- **Before generating any translations for any target locale**:
|
|
67
|
+
- Inspect all active keys in `localization_base/<source_locale>.json` (e.g., `localization_base/en.json`).
|
|
68
|
+
- Verify that **every key has meaningful, accurate semantic `context`**.
|
|
69
|
+
- If any key lacks context, has an empty context (`""`), or contains only generic AST descriptions (e.g., `"JSX text in button"`), you MUST inspect the component/screen and **generate rich semantic context for all such keys BEFORE generating translations**.
|
|
70
|
+
- Enrich context via:
|
|
71
|
+
```bash
|
|
72
|
+
shallok context set <key> "<semantic_description>"
|
|
73
|
+
```
|
|
74
|
+
or directly edit the `"context"` field in `localization_base/<source_locale>.json`.
|
|
75
|
+
|
|
76
|
+
### Rule 4: Always Generate Translations from `localization_base/{source_locale}` and Its Context
|
|
77
|
+
- **Never translate raw strings in isolation**:
|
|
78
|
+
- All translations MUST be generated directly from `localization_base/<source_locale>.json`, reading BOTH the source string (`content`) and its semantic `context`.
|
|
79
|
+
- The `context` provides critical disambiguation (grammatical gender, button vs label vs heading, formality, technical terminology).
|
|
80
|
+
- Strictly preserve all interpolation tokens (`{userName}`, `{count}`, `{amount}`) exactly as formatted in the source `content`.
|
|
81
|
+
|
|
82
|
+
### Rule 5: Migrate Legacy Base Locale References to Specified Structure
|
|
83
|
+
- **If the application already has a localization setup**:
|
|
84
|
+
- Inspect how the base/source locale (`source_locale`, e.g., `en`) is loaded.
|
|
85
|
+
- If any configuration or code file (e.g., `i18n.ts`, `src/i18n.ts`, `src/i18n/request.ts`, `app/_layout.tsx`, `main.tsx`) is importing or referencing a legacy file other than our specified structure (e.g., `src/locales/en.json`, `locales/en.json`, `public/locales/en.json`):
|
|
86
|
+
1. **Reconcile legacy base strings** into `localization_base/<source_locale>.json` and `messages/<source_locale>.json`.
|
|
87
|
+
2. **Update all code imports and references** across the project to point to the standardized compiled runtime bundle (`messages/runtime/<locale>.json`) or the CDN loader.
|
|
88
|
+
3. Remove or deprecate the legacy base locale file so that Shallok's AST extraction does NOT falsely extract the legacy JSON file as source code.
|
|
89
|
+
|
|
90
|
+
### Rule 6: Translation Loading Strategy: Local for Static/SSR vs. CDN for Client/Mobile
|
|
91
|
+
Choose the loading strategy based on application architecture:
|
|
92
|
+
- **Static & SSR Applications (Astro, Next.js, and similar static/SSR apps)**:
|
|
93
|
+
- **Recommend keeping translations LOCAL** in `messages/runtime/<locale>.json`.
|
|
94
|
+
- Load directly from the local bundle or filesystem during server rendering or static build.
|
|
95
|
+
- **Benefits**: Zero network latency, instant First Contentful Paint (FCP), seamless Server Component hydration, and zero remote network failure risks.
|
|
96
|
+
- **Client & Mobile Applications (Expo, React Native, React SPA / Vite)**:
|
|
97
|
+
- **Recommend loading translations from a CDN**:
|
|
98
|
+
- For mobile apps and client SPAs, suggest uploading compiled `messages/runtime/<locale>.json` to a CDN (e.g. Cloudflare R2, AWS S3/CloudFront, Supabase Storage, Vercel Blob).
|
|
99
|
+
- **Why?** Enables instant Over-the-Air (OTA) translation and typo fixes without requiring App Store / Google Play review cycles or full client web redeployments.
|
|
100
|
+
- **Scaffold CDN Environment Variables**:
|
|
101
|
+
- For Expo: `EXPO_PUBLIC_TRANSLATIONS_CDN_URL=https://cdn.yourdomain.com/locales`
|
|
102
|
+
- For React / Vite: `VITE_TRANSLATIONS_CDN_URL=https://cdn.yourdomain.com/locales`
|
|
103
|
+
- **Ask the user to set/update these ENV variables** with their actual CDN endpoint.
|
|
104
|
+
- **Resilient Runtime with Local Fallback**: The client loader fetches from CDN with caching (e.g., `AsyncStorage` / `localStorage`), while always maintaining bundled `messages/runtime/<locale>.json` as an offline fallback.
|
|
105
|
+
- **Upload Script**: Provide an upload script (e.g. `scripts/upload-locales.mjs`) to upload `messages/runtime/` bundles to the CDN.
|
|
31
106
|
|
|
32
107
|
---
|
|
33
108
|
|
|
@@ -56,6 +131,10 @@ Inspect repository architecture without modifying files:
|
|
|
56
131
|
shallok analyze --json
|
|
57
132
|
```
|
|
58
133
|
- Examine detected framework, router, programming language, and source paths (`src/`).
|
|
134
|
+
- Check existing translation catalogs and folders (`locales/`, `src/locales/`, `messages/`).
|
|
135
|
+
- Check if existing base locale is referencing legacy files (e.g., `src/locales/en.json`, `locales/en.json`).
|
|
136
|
+
- Check if existing keys use object-based nesting or normalized dot-paths.
|
|
137
|
+
- Determine if the project is Static/SSR (Next.js, Astro) or Client/Mobile (Expo, React Native, React SPA).
|
|
59
138
|
- Determine candidate source files and target locales from the user request.
|
|
60
139
|
- **Never edit files during Phase A.**
|
|
61
140
|
|
|
@@ -64,18 +143,27 @@ Present a concise plan to the developer:
|
|
|
64
143
|
1. **Detected Framework**: Framework name and router type.
|
|
65
144
|
2. **Runtime Localization Solution**: Suggested runtime library (e.g. `next-intl`, `react-i18next`, `expo-localization`).
|
|
66
145
|
3. **Locales**: Source locale (e.g. `en`) and target locales (e.g. `kn` Kannada, `hi` Hindi).
|
|
67
|
-
4. **
|
|
146
|
+
4. **Directory & Key Architecture Check**:
|
|
147
|
+
- If non-standard locale folders or legacy base locale references exist: Propose migrating to `messages/` and updating all import references to `messages/runtime/<locale>.json`.
|
|
148
|
+
- If object-based keys exist: Propose flattening to normalized dot-path keys and request user confirmation.
|
|
149
|
+
5. **Loading Strategy Recommendation**:
|
|
150
|
+
- For **Astro / Next.js**: Recommend local bundle loading from `messages/runtime/`.
|
|
151
|
+
- For **Expo / React Native / React SPA**: Recommend CDN loading with `EXPO_PUBLIC_TRANSLATIONS_CDN_URL` or `VITE_TRANSLATIONS_CDN_URL`, with local fallback, and ask the user to configure the CDN ENV.
|
|
152
|
+
6. **Planned Scaffolding**:
|
|
68
153
|
- `localization.json` (Project manifest)
|
|
69
|
-
- `localization_base/<source_locale>.json` & `metadata.json` (Canonical catalog & versions)
|
|
70
|
-
- `messages/<locale>.json` (
|
|
154
|
+
- `localization_base/<source_locale>.json` & `metadata.json` (Canonical catalog & versions — **never delete**)
|
|
155
|
+
- `messages/<locale>.json` (Authoritative locale catalogs)
|
|
71
156
|
- Framework adapter configuration
|
|
72
|
-
|
|
157
|
+
7. Confirm with the user before proceeding (or proceed if `--yes` / user requested).
|
|
73
158
|
|
|
74
159
|
### Phase C: Initialize
|
|
75
160
|
Initialize project configuration and catalogs:
|
|
76
161
|
```bash
|
|
77
162
|
shallok init --source en --locales kn,hi --framework <name> --yes
|
|
78
163
|
```
|
|
164
|
+
1. If migrating from an existing non-standard folder (e.g., `src/locales/en.json`), copy/migrate existing translations into `messages/` and reconcile into `localization_base/`.
|
|
165
|
+
2. **Update all code references**: Replace legacy imports like `import en from './locales/en.json'` with `messages/runtime/` or CDN loader.
|
|
166
|
+
3. If using CDN loading (Expo / React Native / React), create/update `.env` / `.env.example` with the CDN URL variable and prompt the user to configure it.
|
|
79
167
|
|
|
80
168
|
### Phase D: Extract & Enrich Context (AI-Driven)
|
|
81
169
|
1. **Preview proposed extraction**:
|
|
@@ -86,32 +174,32 @@ shallok init --source en --locales kn,hi --framework <name> --yes
|
|
|
86
174
|
```bash
|
|
87
175
|
shallok extract
|
|
88
176
|
```
|
|
89
|
-
3. **
|
|
177
|
+
3. **Mandatory Context Check & Enrichment (Performed by AI Agent)**:
|
|
90
178
|
- Inspect `localization_base/<source_locale>.json`.
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
- Use the CLI:
|
|
179
|
+
- **Verify that every key has proper semantic context**.
|
|
180
|
+
- If any key lacks context or has only generic AST descriptions, analyze the screen and component purpose and enrich `context` BEFORE proceeding to translation:
|
|
94
181
|
```bash
|
|
95
182
|
shallok context set <key> "<semantic_description>"
|
|
96
183
|
```
|
|
97
184
|
Or edit `"context"` directly in `localization_base/<source_locale>.json`.
|
|
98
185
|
- **Preservation Guarantee**: Shallok's reconciliation algorithm strictly preserves your enriched context across all future extractions.
|
|
99
186
|
|
|
100
|
-
### Phase E: Translate (AI-Driven)
|
|
187
|
+
### Phase E: Translate (AI-Driven from `localization_base/{source_locale}` + Context)
|
|
101
188
|
**No external API keys or LLM provider subscriptions are required.**
|
|
102
189
|
You, as the AI coding agent, generate the translations directly:
|
|
103
190
|
|
|
104
|
-
1. **
|
|
191
|
+
1. **Verify Context First**: Ensure all keys in `localization_base/<source_locale>.json` have proper semantic context.
|
|
192
|
+
2. **Identify entries needing translation**:
|
|
105
193
|
```bash
|
|
106
194
|
shallok status --json
|
|
107
195
|
```
|
|
108
196
|
Inspect `messages/<locale>.json` for keys with `status: "missing"` or `status: "stale"`.
|
|
109
197
|
|
|
110
|
-
|
|
111
|
-
- Translate each entry into natural, culturally accurate target language
|
|
198
|
+
3. **Generate Translations from `localization_base/{source_locale}` and Its Context**:
|
|
199
|
+
- Translate each entry into natural, culturally accurate target language reading the source `content` AND its semantic `context` from `localization_base/<source_locale>.json`.
|
|
112
200
|
- **Rule**: Strictly preserve all interpolation placeholders (`{name}`, `{count}`, `{price}`).
|
|
113
201
|
|
|
114
|
-
|
|
202
|
+
4. **Update Target Locale Catalogs**:
|
|
115
203
|
Update `messages/<locale>.json` directly or using the CLI:
|
|
116
204
|
```bash
|
|
117
205
|
shallok entry set <locale> <key> "<translated_text>"
|
|
@@ -133,7 +221,7 @@ You, as the AI coding agent, generate the translations directly:
|
|
|
133
221
|
```bash
|
|
134
222
|
shallok extract --apply
|
|
135
223
|
```
|
|
136
|
-
Replaces hardcoded strings with `{t('key')}` and injects necessary hooks.
|
|
224
|
+
Replaces hardcoded strings with `{t('key')}` using normalized dot-separated key paths and injects necessary hooks.
|
|
137
225
|
|
|
138
226
|
2. **Build runtime message bundles**:
|
|
139
227
|
```bash
|
|
@@ -161,10 +249,10 @@ You, as the AI coding agent, generate the translations directly:
|
|
|
161
249
|
```bash
|
|
162
250
|
shallok locale add <locale>
|
|
163
251
|
```
|
|
164
|
-
|
|
252
|
+
Check context in `localization_base/<source_locale>.json`, translate active keys into `messages/<locale>.json` using source content and context, then run `shallok build && shallok validate`.
|
|
165
253
|
|
|
166
254
|
- **Source wording changed**:
|
|
167
|
-
Run `shallok extract`. Only modified keys increment version (`key_version`); only dependent entries are flagged `stale`.
|
|
255
|
+
Run `shallok extract`. Only modified keys increment version (`key_version`); only dependent entries are flagged `stale`. Check and update context if needed, translate the changed string from `localization_base/<source_locale>.json` and context, then `shallok build`.
|
|
168
256
|
|
|
169
257
|
- **Rename a key**:
|
|
170
258
|
```bash
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
## Extraction Strategy
|
|
4
4
|
Shallok uses Babel AST parsing (`@babel/parser` and `@babel/traverse`) with full JSX and TypeScript support to safely inspect and transform source files without regular expressions.
|
|
5
5
|
|
|
6
|
+
## Normalized Dot-Paths for Keys (Never Object-Based)
|
|
7
|
+
- **Always use normalized dot-separated key paths**: e.g., `"checkout.pay_now"`, `"auth.login.title"`, `"dashboard.metrics.active_users"`.
|
|
8
|
+
- **Never use object-based or nested object paths**: Catalogs must never store nested object trees.
|
|
9
|
+
- **If an existing project uses object-based keys**: Ask the user for confirmation to flatten them to normalized dot-path keys before running extraction or migrating catalogs.
|
|
10
|
+
|
|
6
11
|
## What is Extracted
|
|
7
12
|
1. **JSX Text Nodes**:
|
|
8
13
|
- `<h1>Welcome</h1>` → `{t('home.welcome')}`
|
|
@@ -26,4 +31,4 @@ Shallok uses Babel AST parsing (`@babel/parser` and `@babel/traverse`) with full
|
|
|
26
31
|
- Already localized calls: `t(...)`, `i18n.t(...)`.
|
|
27
32
|
|
|
28
33
|
## Dry-Run Mode
|
|
29
|
-
Always use `
|
|
34
|
+
Always use `shallok extract --dry-run` to preview keys and occurrences before committing changes to source files.
|
|
@@ -1,39 +1,58 @@
|
|
|
1
1
|
# Framework Adapters Reference
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Loading Strategies: Local vs. CDN
|
|
4
|
+
|
|
5
|
+
| Framework Type | Recommended Strategy | Primary Rationale | Configuration & ENV |
|
|
6
|
+
| :--- | :--- | :--- | :--- |
|
|
7
|
+
| **Astro** (`astro:i18n`) | **Local** (`messages/runtime/`) | Static builds (SSG) & SSR; zero network hops, zero build dependency on external services. | Bundled in `src/i18n/utils.ts` |
|
|
8
|
+
| **Next.js** (`next-intl`) | **Local** (`messages/runtime/`) | Server Components & SSR; instant First Contentful Paint, zero latency in Node/Edge. | Bundled in `src/i18n/request.ts` |
|
|
9
|
+
| **Expo / React Native** | **CDN-Backed** (+ Local Fallback) | Instant Over-The-Air (OTA) translation & typo fixes without waiting for App Store review. | `EXPO_PUBLIC_TRANSLATIONS_CDN_URL` + AsyncStorage caching + local fallback |
|
|
10
|
+
| **React SPA** (Vite / CRA) | **CDN-Backed** (+ Local Fallback) | Instant copy updates without rebuilding web bundle. | `VITE_TRANSLATIONS_CDN_URL` + localStorage caching + local fallback |
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Supported Frameworks & Adapters
|
|
4
15
|
|
|
5
16
|
### 1. React (`react-i18next`)
|
|
6
17
|
- **Initialization**: Generates `src/i18n.ts` configuring `i18next` with `initReactI18next`.
|
|
7
18
|
- **Runtime Messages**: Generates clean key-value message files in `messages/runtime/<locale>.json`.
|
|
19
|
+
- **CDN Loading**: Suggest `VITE_TRANSLATIONS_CDN_URL` in `.env` with local `messages/runtime/` fallback and `scripts/upload-locales.mjs`.
|
|
20
|
+
- **Legacy Migration**: If `src/main.tsx` or `src/i18n.ts` imported `src/locales/en.json`, migrate to `messages/runtime/` or CDN loader.
|
|
8
21
|
- **AST Transformation**:
|
|
9
22
|
- Adds `import { useTranslation } from 'react-i18next';`
|
|
10
23
|
- Injects `const { t } = useTranslation();` in components
|
|
11
|
-
- Replaces text with `{t('key')}`
|
|
24
|
+
- Replaces text with `{t('key')}` using normalized dot-separated key paths.
|
|
12
25
|
|
|
13
26
|
### 2. Next.js (`next-intl`)
|
|
14
27
|
- **App Router Support**:
|
|
15
28
|
- Generates `src/i18n/routing.ts` defining `locales` and `defaultLocale`.
|
|
16
|
-
- Generates `src/i18n/request.ts` using `getRequestConfig`.
|
|
29
|
+
- Generates `src/i18n/request.ts` using `getRequestConfig` loading local `messages/runtime/<locale>.json`.
|
|
17
30
|
- **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
|
|
31
|
+
- **Loading Strategy**: Local loading recommended for Server Components and SSR.
|
|
32
|
+
- **Legacy Migration**: If `src/i18n/request.ts` or `middleware.ts` imported old locale JSONs, update imports to `messages/runtime/<locale>.json`.
|
|
18
33
|
- **AST Transformation**:
|
|
19
34
|
- Adds `import { useTranslations } from 'next-intl';`
|
|
20
35
|
- Injects `const t = useTranslations();` in components
|
|
21
|
-
- Replaces text with `{t('key')}`
|
|
36
|
+
- Replaces text with `{t('key')}` using normalized dot-separated key paths.
|
|
22
37
|
|
|
23
38
|
### 3. Expo / React Native (`expo-localization` + `react-i18next`)
|
|
24
39
|
- **Initialization**: Generates `i18n.ts` using `getLocales` from `expo-localization` and `i18next`.
|
|
25
40
|
- **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
|
|
41
|
+
- **CDN Loading**: Suggest `EXPO_PUBLIC_TRANSLATIONS_CDN_URL` in `.env` with `AsyncStorage` caching and local `messages/runtime/` fallback.
|
|
42
|
+
- **Legacy Migration**: If `app/_layout.tsx` or `src/i18n.ts` imported `src/locales/en.json`, migrate to `messages/runtime/` or CDN loader.
|
|
26
43
|
- **AST Transformation**:
|
|
27
44
|
- Adds `import { useTranslation } from 'react-i18next';`
|
|
28
45
|
- Injects `const { t } = useTranslation();` in mobile components
|
|
29
|
-
- Replaces text inside `<Text>` and attributes like `placeholder` with `{t('key')}`
|
|
46
|
+
- Replaces text inside `<Text>` and attributes like `placeholder` with `{t('key')}` using normalized dot-separated key paths.
|
|
30
47
|
|
|
31
48
|
### 4. Astro (`astro:i18n`)
|
|
32
|
-
- **Initialization**: Generates `src/i18n/utils.ts` defining `locales`, `defaultLocale`, and `useTranslations`.
|
|
49
|
+
- **Initialization**: Generates `src/i18n/utils.ts` defining `locales`, `defaultLocale`, and `useTranslations` loading local `messages/runtime/<locale>.json`.
|
|
33
50
|
- **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
|
|
51
|
+
- **Loading Strategy**: Local loading recommended for fast static SSG and hybrid SSR.
|
|
52
|
+
- **Legacy Migration**: If `src/i18n/utils.ts` or `.astro` files imported old locale JSONs, update imports to `messages/runtime/<locale>.json`.
|
|
34
53
|
- **Component Usage**:
|
|
35
54
|
- In Astro components frontmatter: `const t = await useTranslations(locale);`
|
|
36
|
-
- Renders `{t('key')}` in templates and islands.
|
|
55
|
+
- Renders `{t('key')}` in templates and islands using normalized dot-separated key paths.
|
|
37
56
|
|
|
38
57
|
### 5. Vue (`vue-i18n`)
|
|
39
58
|
- **Initialization**: Generates `src/i18n.ts` using `createI18n`.
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
# Translation Engine & Agent-Native Translation Reference
|
|
2
2
|
|
|
3
3
|
## Agent-Native Translation (Primary Workflow)
|
|
4
|
-
When using Shallok via an AI coding agent (e.g., in Claude, Cursor, Copilot
|
|
4
|
+
When using Shallok via an AI coding agent (e.g., in Antigravity, Claude, Cursor, Copilot):
|
|
5
5
|
- **No external API keys or LLM provider subscriptions are needed.**
|
|
6
6
|
- The AI agent itself generates accurate, natural translations for each target locale.
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- **Always verify context first**: Before translating any key, check that all keys in `localization_base/<source_locale>.json` have proper semantic context. If any key lacks context or has generic AST context, generate rich context before translating.
|
|
8
|
+
- **Always translate from `localization_base/<source_locale>.json` and its context**: Never translate raw isolated string fragments. Combine the canonical source `content` and its semantic `context` to generate culturally authentic, grammatically correct translations.
|
|
9
|
+
- Inspect `messages/<locale>.json` or run `shallok status --json` to identify entries with `status: "missing"` or `status: "stale"`.
|
|
10
|
+
- Write the translated strings into `messages/<locale>.json` (or use `shallok entry set <locale> <key> "<translated_text>"`).
|
|
11
|
+
|
|
12
|
+
## Core Rules for Translations
|
|
13
|
+
|
|
14
|
+
### 1. Pre-Flight Verification & Persistence
|
|
15
|
+
- Before making changes to a new or existing repo, verify `shallok` is installed and check that `localization.json` and `localization_base/` exist. If not, initialize with `shallok init`.
|
|
16
|
+
- **NEVER delete `localization.json` or `localization_base/`**. They hold the single source of truth, content hashes, version counters, and context.
|
|
17
|
+
|
|
18
|
+
### 2. Normalized Dot-Paths for Keys
|
|
19
|
+
- All keys must use normalized dot notation (e.g., `"checkout.pay_now"`, `"auth.login.title"`).
|
|
20
|
+
- Never use nested object structures. If an existing codebase uses nested objects for keys, ask the user to convert/flatten them to normalized dot-path keys.
|
|
21
|
+
|
|
22
|
+
### 3. Standardized `messages/` Folder
|
|
23
|
+
- All translations must reside in `messages/` (`messages/<locale>.json` and `messages/runtime/<locale>.json`).
|
|
24
|
+
- If an existing project uses another directory (such as `locales/`, `src/locales/`, `translations/`), ask the user to switch to `messages/` and migrate existing files.
|
|
25
|
+
|
|
26
|
+
### 4. Context Verification Before Translation
|
|
27
|
+
- Check all keys in `localization_base/<source_locale>.json` have meaningful semantic context.
|
|
28
|
+
- If any key lacks context, generate clear context describing the screen, element, and user action before initiating translation.
|
|
29
|
+
|
|
30
|
+
### 5. Always Translate from Source Locale Catalog + Context
|
|
31
|
+
- Read both `content` and `context` from `localization_base/<source_locale>.json`.
|
|
32
|
+
- Preserve all interpolation placeholders (`{name}`, `{count}`, `{amount}`) exactly as formatted.
|
|
33
|
+
|
|
34
|
+
---
|
|
9
35
|
|
|
10
36
|
### Translation Schema
|
|
11
37
|
Each entry in `messages/<locale>.json` maintains:
|
|
@@ -35,7 +61,7 @@ The AI agent must strictly preserve all interpolation placeholders in target tra
|
|
|
35
61
|
- Kannada: `"ಮರಳಿ ಸ್ವಾಗತ, {userName}! ನಿಮ್ಮ ಕಾರ್ಟ್ನಲ್ಲಿ {itemCount} ಐಟಂಗಳು ಇವೆ."`
|
|
36
62
|
- Hindi: `"वापसी पर स्वागत है, {userName}! आपके कार्ट में {itemCount} आइटम हैं।"`
|
|
37
63
|
|
|
38
|
-
If a translation drops a placeholder or introduces an invalid placeholder, `
|
|
64
|
+
If a translation drops a placeholder or introduces an invalid placeholder, `shallok validate` will fail with an error.
|
|
39
65
|
|
|
40
66
|
---
|
|
41
67
|
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
# Per-Key Versioning & Context Reference
|
|
2
2
|
|
|
3
|
+
## Strict Catalog Persistence: NEVER Delete `localization.json` or `localization_base/`
|
|
4
|
+
> [!CAUTION]
|
|
5
|
+
> `localization.json` and `localization_base/` are the permanent foundation of the localization system:
|
|
6
|
+
> - `localization.json` stores project settings, locales, paths, and key strategies.
|
|
7
|
+
> - `localization_base/` stores canonical source strings, per-key version counters (`key_version`), cryptographic SHA-256 hashes (`content_hash`), occurrence positions, and enriched semantic `context`.
|
|
8
|
+
> - **Under NO circumstances should you EVER delete `localization.json` or `localization_base/`**. Deleting them resets version counters, destroys human- and AI-enriched context, breaks incremental translation, and corrupts catalog synchronization.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
3
12
|
## Canonical Source Catalog (`localization_base/`)
|
|
4
13
|
The canonical catalog is the single source of truth for all active and obsolete keys, including their cryptographic content hashes and version counters.
|
|
5
14
|
|
|
15
|
+
### Key Format: Normalized Dot-Separated Paths Only
|
|
16
|
+
- All keys must use normalized dot-separated string paths (e.g. `"checkout.pay_now"`, `"auth.login.title"`).
|
|
17
|
+
- **Never use nested object-based keys**.
|
|
18
|
+
- If an existing project uses object-based keys, ask the user to convert and flatten them to normalized dot-paths before modifying catalogs.
|
|
19
|
+
|
|
6
20
|
### Structure of a Canonical Entry
|
|
7
21
|
```json
|
|
8
22
|
{
|
|
@@ -26,12 +40,14 @@ The canonical catalog is the single source of truth for all active and obsolete
|
|
|
26
40
|
}
|
|
27
41
|
```
|
|
28
42
|
|
|
29
|
-
## Context Enrichment
|
|
30
|
-
1. When strings are extracted via `
|
|
31
|
-
2.
|
|
32
|
-
|
|
43
|
+
## Context Enrichment & Verification Before Translation
|
|
44
|
+
1. When strings are extracted via `shallok extract`, the CLI provides baseline AST context (e.g. `JSX text in <button> (in App <button>)`).
|
|
45
|
+
2. **Mandatory Check Before Translation**: Before generating any translations, check that all active keys in `localization_base/<source_locale>.json` have proper, high-quality semantic context.
|
|
46
|
+
3. If any key lacks context or has only generic AST descriptions, analyze the source code, component hierarchy, and user flow, and enrich the `context` with semantic clarity:
|
|
47
|
+
- CLI method: `shallok context set <key> "<semantic_description>"`
|
|
33
48
|
- Direct edit: Update `"context"` in `localization_base/<source_locale>.json`.
|
|
34
|
-
|
|
49
|
+
4. **Always Translate from Source Locale + Context**: Translations must be derived directly from `localization_base/<source_locale>.json` using BOTH `content` and `context`.
|
|
50
|
+
5. **Preservation Guarantee**:
|
|
35
51
|
Shallok's reconciliation algorithm (`reconcileCanonicalCatalog`) checks if a key already has an enriched context. Unless the source code introduces an explicit inline comment (`{/* context: ... */}`), the AI agent's enriched context is **strictly preserved** across all future extractions and will not be overwritten by generic AST node descriptions.
|
|
36
52
|
|
|
37
53
|
## Reconciliation & Versioning Rules
|
|
@@ -54,4 +70,4 @@ In `messages/<locale>.json`, each entry records:
|
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
```
|
|
57
|
-
A translation is **stale** when `entry.source_version < canonicalEntry.key_version`. Stale entries retain their existing translated value for reference until the AI agent updates them
|
|
73
|
+
A translation is **stale** when `entry.source_version < canonicalEntry.key_version`. Stale entries retain their existing translated value for reference until the AI agent updates them from `localization_base/<source_locale>.json` and its enriched `context`.
|
|
@@ -14,20 +14,86 @@ Use this skill when asked to add, configure, update, or audit localization in **
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
## Agent Step 0:
|
|
17
|
+
## Agent Step 0: Mandatory Pre-Flight Checklist (Run Before ANY Code or Config Changes)
|
|
18
|
+
|
|
19
|
+
**Before making ANY changes to a new repo or an existing repo, you (the AI Agent) MUST execute the following checks in order:**
|
|
20
|
+
|
|
21
|
+
### 1. Check if Shallok is Installed
|
|
22
|
+
- Inspect `package.json` for `"shallok"` or `"@shallok/cli"` in `devDependencies` (or `dependencies`), or run:
|
|
23
|
+
```bash
|
|
24
|
+
npx shallok --version
|
|
25
|
+
```
|
|
26
|
+
- **If `shallok` is NOT installed, install it immediately into `devDependencies`:**
|
|
27
|
+
- If `pnpm-lock.yaml` exists: `pnpm add -D shallok`
|
|
28
|
+
- If `yarn.lock` exists: `yarn add -D shallok`
|
|
29
|
+
- If `bun.lockb` / `bun.lock` exists: `bun add -d shallok`
|
|
30
|
+
- Otherwise: `npm install -D shallok`
|
|
31
|
+
|
|
32
|
+
### 2. Check if `localization.json` and `localization_base/` Exist
|
|
33
|
+
- Verify that `localization.json` exists in the project root.
|
|
34
|
+
- Verify that the `localization_base/` directory exists with `<source_locale>.json` and `metadata.json`.
|
|
35
|
+
- **If either does NOT exist, create them using Shallok:**
|
|
36
|
+
```bash
|
|
37
|
+
shallok init --source en --locales kn,hi --framework nextjs --yes
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. NEVER Delete `localization.json` or `localization_base/`
|
|
41
|
+
> [!CAUTION]
|
|
42
|
+
> **CRITICAL PERSISTENCE RULE: NEVER DELETE `localization.json` OR `localization_base/`!**
|
|
43
|
+
> - `localization.json` is the single source-of-truth project manifest.
|
|
44
|
+
> - `localization_base/` contains the canonical catalog (`<source_locale>.json`) with per-key version numbers (`key_version`), cryptographic content hashes (`sha256:`), source code occurrences, and enriched semantic context, alongside `metadata.json`.
|
|
45
|
+
> - **Under NO circumstances should you EVER delete `localization.json` or `localization_base/`**. Deleting them destroys the versioning history, wipes out human- and AI-enriched context, resets version counters, breaks incremental translation, and corrupts catalog synchronization.
|
|
18
46
|
|
|
19
|
-
|
|
47
|
+
---
|
|
20
48
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
## Core Architectural & Formatting Rules
|
|
50
|
+
|
|
51
|
+
### Rule 1: Always Use Normalized Paths for Keys (Never Object-Based Paths)
|
|
52
|
+
- **Always use normalized dot-separated key paths**: e.g., `"auth.login.title"`, `"checkout.pay_now"`, `"settings.profile.change_password"`.
|
|
53
|
+
- **Never use nested object-based paths**: Do not structure keys or catalogs as nested JSON objects (e.g., `{ "auth": { "login": { "title": "..." } } }`). All keys in `localization_base/<source_locale>.json`, `messages/<locale>.json`, and runtime bundles MUST be flat normalized string paths.
|
|
54
|
+
- **If an existing project is using object-based keys**:
|
|
55
|
+
- **STOP and ask the user** for confirmation to flatten them into normalized dot-separated key paths before proceeding with extraction or catalog edits.
|
|
56
|
+
- Explain that normalized dot-paths are required for deterministic AST extraction, per-key versioning, and collision-free reconciliation.
|
|
57
|
+
- Upon user approval, migrate and flatten all nested keys to normalized dot-paths.
|
|
58
|
+
|
|
59
|
+
### Rule 2: Always Use the `messages/` Directory Structure (Ask User & Migrate If Different)
|
|
60
|
+
- **Standard translations folder**: Shallok strictly standardizes on `messages/` for authoritative locale catalogs (`messages/<locale>.json`) and compiled runtime bundles (`messages/runtime/<locale>.json`).
|
|
61
|
+
- **If the project uses any other folder structure** (e.g., `locales/`, `src/locales/`, `translations/`, `lang/`, `src/i18n/locales/`):
|
|
62
|
+
- **STOP and ask the user** for approval to switch to the standardized `messages/` directory structure.
|
|
63
|
+
- Upon user approval, **migrate** all existing translation files into `messages/`, update framework configuration and import paths, reconcile existing strings into `localization_base/`, and clean up the old directory.
|
|
64
|
+
|
|
65
|
+
### Rule 3: Check Context for All Keys in `localization_base/{source_locale}` Before Translating
|
|
66
|
+
- **Before generating any translations for any target locale**:
|
|
67
|
+
- Inspect all active keys in `localization_base/<source_locale>.json` (e.g., `localization_base/en.json`).
|
|
68
|
+
- Verify that **every key has meaningful, accurate semantic `context`**.
|
|
69
|
+
- If any key lacks context, has an empty context (`""`), or contains only generic AST descriptions (e.g., `"JSX text in button"`), you MUST inspect the component/screen and **generate rich semantic context for all such keys BEFORE generating translations**.
|
|
70
|
+
- Enrich context via:
|
|
71
|
+
```bash
|
|
72
|
+
shallok context set <key> "<semantic_description>"
|
|
73
|
+
```
|
|
74
|
+
or directly edit the `"context"` field in `localization_base/<source_locale>.json`.
|
|
75
|
+
|
|
76
|
+
### Rule 4: Always Generate Translations from `localization_base/{source_locale}` and Its Context
|
|
77
|
+
- **Never translate raw strings in isolation**:
|
|
78
|
+
- All translations MUST be generated directly from `localization_base/<source_locale>.json`, reading BOTH the source string (`content`) and its semantic `context`.
|
|
79
|
+
- The `context` provides critical disambiguation (grammatical gender, button vs label vs heading, formality, technical terminology).
|
|
80
|
+
- Strictly preserve all interpolation tokens (`{userName}`, `{count}`, `{amount}`) exactly as formatted in the source `content`.
|
|
81
|
+
|
|
82
|
+
### Rule 5: Migrate Legacy Base Locale References to Specified Structure
|
|
83
|
+
- **If the Next.js app already has an existing localization setup**:
|
|
84
|
+
- Check how the base/source locale (`source_locale`, e.g., `en`) is imported and loaded.
|
|
85
|
+
- If any file (e.g. `src/i18n/request.ts`, `src/i18n.ts`, `middleware.ts`, `app/[locale]/layout.tsx`) is importing a legacy file (such as `src/locales/en.json`, `locales/en.json`, or arbitrary JSON files):
|
|
86
|
+
1. **Reconcile strings** into `localization_base/<source_locale>.json` and `messages/<source_locale>.json`.
|
|
87
|
+
2. **Update all code imports and request loaders** to point to the standardized compiled runtime bundle (`messages/runtime/<locale>.json`).
|
|
88
|
+
3. Remove or deprecate the legacy base locale file so that Shallok does NOT extract it as source code (preventing false occurrences like `"relative_file_path": "src/locales/en.json"`).
|
|
89
|
+
|
|
90
|
+
### Rule 6: Next.js Architecture: Keep Translations Local for Instant Server Rendering
|
|
91
|
+
- **Recommend keeping translations LOCAL in `messages/runtime/<locale>.json`**:
|
|
92
|
+
- Next.js Server Components, Server-Side Rendering (SSR), and Static Site Generation (SSG) execute in Node.js or Edge runtime.
|
|
93
|
+
- Loading compiled message bundles directly from `messages/runtime/<locale>.json` (via `src/i18n/request.ts`) guarantees:
|
|
94
|
+
- **Zero network latency**: Instant server execution and rapid First Contentful Paint (FCP).
|
|
95
|
+
- **Zero build or render failures**: Builds do not depend on external CDN uptime or network requests.
|
|
96
|
+
- **Optimal bundling**: Next.js automatically tree-shakes and splits locale chunks.
|
|
31
97
|
|
|
32
98
|
---
|
|
33
99
|
|
|
@@ -38,7 +104,7 @@ Shallok pairs a deterministic AST CLI (`shallok`) with **the AI Agent as the sem
|
|
|
38
104
|
1. **The CLI (`shallok`)** handles deterministic tasks:
|
|
39
105
|
- Scaffolds Next.js configuration files: `src/i18n/routing.ts` and `src/i18n/request.ts`.
|
|
40
106
|
- AST parses Next.js JSX/TSX components (`shallok extract`).
|
|
41
|
-
- Replaces user-facing strings with `{t('key')}` and imports `useTranslations` (`shallok extract --apply`).
|
|
107
|
+
- Replaces user-facing strings with `{t('key')}` using normalized dot-separated key paths and imports `useTranslations` (`shallok extract --apply`).
|
|
42
108
|
- Maintains per-key versioning and SHA-256 content hashes in `localization_base/`.
|
|
43
109
|
- Compiles runtime message bundles to `messages/runtime/<locale>.json` (`shallok build`).
|
|
44
110
|
- Validates 0 missing keys, 0 stale versions, and 0 broken placeholders (`shallok validate`).
|
|
@@ -62,6 +128,9 @@ shallok analyze --json
|
|
|
62
128
|
- Check router type:
|
|
63
129
|
- **App Router**: `app/` directory exists (with or without `src/`).
|
|
64
130
|
- **Pages Router**: `pages/` directory exists.
|
|
131
|
+
- Check existing translation catalogs and folders (`locales/`, `src/locales/`, `messages/`).
|
|
132
|
+
- Check if existing base locale is referencing legacy files (e.g., `src/locales/en.json`, `locales/en.json`).
|
|
133
|
+
- Check if existing keys use object-based nesting or normalized dot-paths.
|
|
65
134
|
- Identify candidate page and component files (`app/**/*.tsx`, `src/**/*.tsx`).
|
|
66
135
|
- Note user-requested target locales (e.g. `kn`, `hi`, `fr`, `es`).
|
|
67
136
|
- **Never edit files during Phase A.**
|
|
@@ -70,34 +139,35 @@ shallok analyze --json
|
|
|
70
139
|
Present a concise plan to the developer:
|
|
71
140
|
1. **Framework & Library**: Next.js with `next-intl`.
|
|
72
141
|
2. **Locales**: Source locale (e.g. `en`) and target locales (e.g. `kn` Kannada, `hi` Hindi).
|
|
73
|
-
3. **
|
|
142
|
+
3. **Directory & Legacy File Migration**:
|
|
143
|
+
- If non-standard locale folders or legacy base locale files exist (e.g. `src/locales/en.json`): Propose migrating to `messages/` and updating all import references to `messages/runtime/<locale>.json`.
|
|
144
|
+
- If object-based keys exist: Explicitly propose flattening to normalized dot-path keys and request user confirmation.
|
|
145
|
+
4. **Loading Strategy Recommendation**:
|
|
146
|
+
- Recommend keeping translations local in `messages/runtime/` for zero-latency Server Components and SSR.
|
|
147
|
+
5. **Dependencies to Install**:
|
|
74
148
|
```bash
|
|
75
149
|
pnpm add next-intl
|
|
76
150
|
```
|
|
77
|
-
|
|
151
|
+
6. **Planned Scaffolding**:
|
|
78
152
|
- `localization.json` (Project manifest)
|
|
79
153
|
- `src/i18n/routing.ts` (Routing definition for `next-intl`)
|
|
80
|
-
- `src/i18n/request.ts` (Request configuration for server-side loading)
|
|
154
|
+
- `src/i18n/request.ts` (Request configuration for server-side loading from `messages/runtime/`)
|
|
81
155
|
- `middleware.ts` (Locale detection and URL rewriting)
|
|
82
|
-
- `localization_base/<source_locale>.json` & `metadata.json` (Canonical catalog & versions)
|
|
156
|
+
- `localization_base/<source_locale>.json` & `metadata.json` (Canonical catalog & versions — **never delete**)
|
|
83
157
|
- `messages/<locale>.json` (Authoritative target catalogs)
|
|
84
158
|
- `messages/runtime/<locale>.json` (Compiled runtime message bundles)
|
|
85
|
-
|
|
159
|
+
7. **App Structure Updates**:
|
|
86
160
|
- Nest routes under `app/[locale]/...`
|
|
87
161
|
- Setup `NextIntlClientProvider` in `app/[locale]/layout.tsx` for client components
|
|
88
|
-
|
|
162
|
+
8. Confirm with user before proceeding (or proceed if `--yes` / requested).
|
|
89
163
|
|
|
90
164
|
### Phase C: Initialize
|
|
91
165
|
Initialize configuration and Next.js scaffolding:
|
|
92
166
|
```bash
|
|
93
167
|
shallok init --source en --locales kn,hi --framework nextjs --yes
|
|
94
168
|
```
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
- `src/i18n/routing.ts`
|
|
98
|
-
- `src/i18n/request.ts`
|
|
99
|
-
- Initial catalogs in `localization_base/` and `messages/`
|
|
100
|
-
- Installs `shallok` in `devDependencies` and copies skills
|
|
169
|
+
1. If migrating from an existing non-standard folder (e.g., `locales/` or `src/locales/`), copy/migrate existing translations into `messages/` and reconcile into `localization_base/`.
|
|
170
|
+
2. **Update all code references**: Replace legacy imports like `import en from './locales/en.json'` with `messages/runtime/<locale>.json` in `src/i18n/request.ts`.
|
|
101
171
|
|
|
102
172
|
Ensure dependencies are installed:
|
|
103
173
|
```bash
|
|
@@ -115,33 +185,33 @@ pnpm add next-intl
|
|
|
115
185
|
```
|
|
116
186
|
This extracts text and JSX expressions to `localization_base/en.json`.
|
|
117
187
|
|
|
118
|
-
3. **
|
|
188
|
+
3. **Mandatory Context Check & Enrichment (Performed by AI Agent)**:
|
|
119
189
|
- Review `localization_base/en.json`.
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
- Use the CLI:
|
|
190
|
+
- **Verify that every key has proper semantic context**.
|
|
191
|
+
- If any key lacks context or has only generic AST descriptions, inspect the Next.js page or component where each key originates and enrich `context` with semantic clarity BEFORE proceeding to translation:
|
|
123
192
|
```bash
|
|
124
193
|
shallok context set <key> "<semantic_description>"
|
|
125
194
|
```
|
|
126
195
|
Or edit `"context"` directly in `localization_base/en.json`.
|
|
127
196
|
- **Preservation Guarantee**: Shallok's reconciliation algorithm strictly preserves your enriched context across all future extractions.
|
|
128
197
|
|
|
129
|
-
### Phase E: Translate (AI-Driven)
|
|
198
|
+
### Phase E: Translate (AI-Driven from `localization_base/{source_locale}` + Context)
|
|
130
199
|
**No external API keys or LLM provider subscriptions are required.**
|
|
131
200
|
You, as the AI coding agent, generate the translations directly:
|
|
132
201
|
|
|
133
|
-
1. **
|
|
202
|
+
1. **Verify Context First**: Ensure all keys in `localization_base/<source_locale>.json` have proper semantic context.
|
|
203
|
+
2. **Check translation status**:
|
|
134
204
|
```bash
|
|
135
205
|
shallok status --json
|
|
136
206
|
```
|
|
137
207
|
Identify keys in `messages/<locale>.json` marked with `status: "missing"` or `status: "stale"`.
|
|
138
208
|
|
|
139
|
-
|
|
140
|
-
- Translate each string into culturally authentic target language (e.g. Kannada, Hindi)
|
|
141
|
-
- Use the source `content` and your enriched `context` for accurate terminology.
|
|
209
|
+
3. **Generate Translations from `localization_base/{source_locale}` and Its Context**:
|
|
210
|
+
- Translate each string into culturally authentic target language (e.g. Kannada, Hindi) reading source `content` AND its semantic `context` from `localization_base/<source_locale>.json`.
|
|
211
|
+
- Use the source `content` and your enriched `context` for accurate terminology and nuance.
|
|
142
212
|
- **Strict Rule**: Preserve all interpolation tokens (`{count}`, `{name}`, `{date}`) exactly as formatted in the source text.
|
|
143
213
|
|
|
144
|
-
|
|
214
|
+
4. **Update Target Locale Catalogs**:
|
|
145
215
|
Write directly into `messages/<locale>.json` or use:
|
|
146
216
|
```bash
|
|
147
217
|
shallok entry set <locale> <key> "<translated_text>"
|
|
@@ -152,6 +222,8 @@ You, as the AI coding agent, generate the translations directly:
|
|
|
152
222
|
```bash
|
|
153
223
|
shallok extract --apply
|
|
154
224
|
```
|
|
225
|
+
Replaces hardcoded strings with `{t('key')}` using normalized dot-separated key paths.
|
|
226
|
+
|
|
155
227
|
2. **Verify Next.js Integration Files**:
|
|
156
228
|
- `middleware.ts` configured with `next-intl/middleware`.
|
|
157
229
|
- `next.config.mjs` with `createNextIntlPlugin`.
|