shallok 0.1.1 → 0.1.2

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 (36) hide show
  1. package/dist/index.js +0 -0
  2. package/package.json +9 -9
  3. package/skills/astro-localization-and-translation-i18n/SKILL.md +105 -32
  4. package/skills/astro-localization-and-translation-i18n/references/astro-i18n.md +15 -0
  5. package/skills/astro-localization-and-translation-i18n/references/extraction.md +6 -1
  6. package/skills/astro-localization-and-translation-i18n/references/frameworks.md +59 -0
  7. package/skills/astro-localization-and-translation-i18n/references/translation.md +30 -4
  8. package/skills/astro-localization-and-translation-i18n/references/versioning.md +22 -6
  9. package/skills/expo-localization-and-translation-i18n/SKILL.md +116 -35
  10. package/skills/expo-localization-and-translation-i18n/references/expo-localization.md +56 -11
  11. package/skills/expo-localization-and-translation-i18n/references/extraction.md +6 -1
  12. package/skills/expo-localization-and-translation-i18n/references/frameworks.md +59 -0
  13. package/skills/expo-localization-and-translation-i18n/references/translation.md +30 -4
  14. package/skills/expo-localization-and-translation-i18n/references/versioning.md +22 -6
  15. package/skills/localization-and-translation-i18n/SKILL.md +116 -28
  16. package/skills/localization-and-translation-i18n/references/extraction.md +6 -1
  17. package/skills/localization-and-translation-i18n/references/frameworks.md +26 -7
  18. package/skills/localization-and-translation-i18n/references/translation.md +30 -4
  19. package/skills/localization-and-translation-i18n/references/versioning.md +22 -6
  20. package/skills/nextjs-localization-and-translation-i18n/SKILL.md +107 -35
  21. package/skills/nextjs-localization-and-translation-i18n/references/extraction.md +6 -1
  22. package/skills/nextjs-localization-and-translation-i18n/references/frameworks.md +59 -0
  23. package/skills/nextjs-localization-and-translation-i18n/references/next-intl.md +14 -2
  24. package/skills/nextjs-localization-and-translation-i18n/references/translation.md +30 -4
  25. package/skills/nextjs-localization-and-translation-i18n/references/versioning.md +22 -6
  26. package/skills/react-localization-and-translation-i18n/SKILL.md +116 -35
  27. package/skills/react-localization-and-translation-i18n/references/extraction.md +6 -1
  28. package/skills/react-localization-and-translation-i18n/references/frameworks.md +59 -0
  29. package/skills/react-localization-and-translation-i18n/references/react-i18next.md +54 -8
  30. package/skills/react-localization-and-translation-i18n/references/translation.md +30 -4
  31. package/skills/react-localization-and-translation-i18n/references/versioning.md +22 -6
  32. package/skills/localize-app/SKILL.md +0 -80
  33. package/skills/localize-app/references/extraction.md +0 -29
  34. package/skills/localize-app/references/frameworks.md +0 -25
  35. package/skills/localize-app/references/translation.md +0 -45
  36. package/skills/localize-app/references/versioning.md +0 -57
package/dist/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shallok",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "AI-Powered, Versioned Localization Tool for AI Coding Agents",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -37,14 +37,10 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "scripts": {
41
- "build": "tsup && node scripts/copy-skills.js",
42
- "typecheck": "tsc --noEmit"
43
- },
44
40
  "dependencies": {
45
- "@shallok/core": "workspace:*",
46
- "@shallok/framework-adapters": "workspace:*",
47
- "@shallok/translation-providers": "workspace:*",
41
+ "@shallok/core": "0.1.0",
42
+ "@shallok/framework-adapters": "0.1.0",
43
+ "@shallok/translation-providers": "0.1.0",
48
44
  "chalk": "^5.4.1",
49
45
  "commander": "^13.1.0",
50
46
  "dotenv": "^16.4.7",
@@ -58,5 +54,9 @@
58
54
  "@types/react": "^18.3.18",
59
55
  "tsup": "^9.0.0",
60
56
  "typescript": "^5.7.3"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup && node scripts/copy-skills.js",
60
+ "typecheck": "tsc --noEmit"
61
61
  }
62
- }
62
+ }
@@ -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: Verify & Install Shallok CLI
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 astro --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
- **Before executing any localization commands, you (the AI Agent) MUST verify that `shallok` is available:**
47
+ ---
20
48
 
21
- 1. Check `package.json` for `"shallok"` in `devDependencies` or run:
22
- ```bash
23
- npx shallok --version
24
- ```
25
- 2. **If `shallok` is NOT installed, install it immediately** using the project's package manager:
26
- - If `pnpm-lock.yaml` exists: `pnpm add -D shallok`
27
- - If `yarn.lock` exists: `yarn add -D shallok`
28
- - If `bun.lockb` / `bun.lock` exists: `bun add -d shallok`
29
- - Otherwise: `npm install -D shallok`
30
- *(Alternatively, run commands directly via `npx shallok <command>`)*
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 Astro project 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/utils.ts`, `astro.config.mjs`, layout files) 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 translation helpers** 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: Astro Architecture: Keep Translations Local for Static SSG & SSR
91
+ - **Recommend keeping translations LOCAL in `messages/runtime/<locale>.json`**:
92
+ - Astro generates static HTML at build time (SSG) or renders on the server (Hybrid/SSR).
93
+ - Loading compiled message bundles directly from `messages/runtime/<locale>.json` (via `src/i18n/utils.ts`) guarantees:
94
+ - **Zero build network overhead**: Static site builds execute without making external HTTP requests.
95
+ - **Zero runtime latency**: Pre-rendered static pages contain translated text directly in the HTML.
96
+ - **No CDN failure risk**: Prevents blank or unlocalized pages due to network hiccups.
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 `src/i18n/utils.ts` integrating with `astro:i18n`.
40
106
  - AST parses Astro templates and UI islands (`shallok extract`).
41
- - Replaces user-facing strings with `{t('key')}` (`shallok extract --apply`).
107
+ - Replaces user-facing strings with `{t('key')}` using normalized dot-separated key paths (`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`).
@@ -59,6 +125,9 @@ shallok analyze --json
59
125
  ```
60
126
  - Verify framework is detected as `astro`.
61
127
  - Check `astro.config.mjs` (or `.ts`) for existing `i18n` block.
128
+ - Check existing translation catalogs and folders (`locales/`, `src/locales/`, `messages/`).
129
+ - Check if existing base locale is referencing legacy files (e.g., `src/locales/en.json`, `locales/en.json`).
130
+ - Check if existing keys use object-based nesting or normalized dot-paths.
62
131
  - Identify page routing structure (`src/pages/`, `src/pages/[locale]/`).
63
132
  - Identify interactive islands (React, Vue, Svelte, Solid components).
64
133
  - Note user-requested target locales (e.g. `kn`, `hi`, `fr`, `es`).
@@ -68,28 +137,30 @@ shallok analyze --json
68
137
  Present a concise plan to the developer:
69
138
  1. **Framework & Approach**: Astro with built-in `astro:i18n` and Shallok runtime translation helper (`src/i18n/utils.ts`).
70
139
  2. **Locales**: Source locale (e.g. `en`) and target locales (e.g. `kn` Kannada, `hi` Hindi).
71
- 3. **Planned Scaffolding**:
140
+ 3. **Directory & Legacy File Migration**:
141
+ - 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`.
142
+ - If object-based keys exist: Explicitly propose flattening to normalized dot-path keys and request user confirmation.
143
+ 4. **Loading Strategy Recommendation**:
144
+ - Recommend keeping translations local in `messages/runtime/` for fast static compilation (SSG) and zero-latency SSR.
145
+ 5. **Planned Scaffolding**:
72
146
  - `localization.json` (Project manifest)
73
- - `src/i18n/utils.ts` (Translation helper and locale type definitions)
147
+ - `src/i18n/utils.ts` (Translation helper loading from `messages/runtime/`)
74
148
  - `astro.config.mjs` i18n configuration
75
- - `localization_base/<source_locale>.json` & `metadata.json` (Canonical catalog & versions)
149
+ - `localization_base/<source_locale>.json` & `metadata.json` (Canonical catalog & versions — **never delete**)
76
150
  - `messages/<locale>.json` (Authoritative target catalogs)
77
151
  - `messages/runtime/<locale>.json` (Compiled runtime message bundles)
78
- 4. **Routing Structure**:
152
+ 6. **Routing Structure**:
79
153
  - Localized routes under `src/pages/[locale]/...`
80
154
  - Default locale route under `src/pages/` or prefixed.
81
- 5. Confirm with user before proceeding (or proceed if `--yes` / requested).
155
+ 7. Confirm with user before proceeding (or proceed if `--yes` / requested).
82
156
 
83
157
  ### Phase C: Initialize
84
158
  Initialize configuration and Astro scaffolding:
85
159
  ```bash
86
160
  shallok init --source en --locales kn,hi --framework astro --yes
87
161
  ```
88
- This automatically creates:
89
- - `localization.json`
90
- - `src/i18n/utils.ts`
91
- - Initial catalogs in `localization_base/` and `messages/`
92
- - Installs `shallok` in `devDependencies` and copies skills
162
+ 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/`.
163
+ 2. **Update all code references**: Replace legacy imports like `import en from './locales/en.json'` with `messages/runtime/<locale>.json` in `src/i18n/utils.ts`.
93
164
 
94
165
  Ensure `astro.config.mjs` specifies the locales:
95
166
  ```javascript
@@ -117,33 +188,33 @@ export default defineConfig({
117
188
  ```
118
189
  This extracts text and expressions into `localization_base/en.json`.
119
190
 
120
- 3. **Enrich Context (Performed by AI Agent)**:
191
+ 3. **Mandatory Context Check & Enrichment (Performed by AI Agent)**:
121
192
  - Review `localization_base/en.json`.
122
- - Inspect the `.astro` page or component where each key originates.
123
- - Enrich `context` with semantic clarity (e.g. *"Landing page hero subtitle describing product mission"*).
124
- - Use the CLI:
193
+ - **Verify that every key has proper semantic context**.
194
+ - If any key lacks context or has only generic AST descriptions, inspect the `.astro` page or component where each key originates and enrich `context` with semantic clarity BEFORE proceeding to translation:
125
195
  ```bash
126
196
  shallok context set <key> "<semantic_description>"
127
197
  ```
128
198
  Or edit `"context"` directly in `localization_base/en.json`.
129
199
  - **Preservation Guarantee**: Shallok's reconciliation algorithm strictly preserves your enriched context across all future extractions.
130
200
 
131
- ### Phase E: Translate (AI-Driven)
201
+ ### Phase E: Translate (AI-Driven from `localization_base/{source_locale}` + Context)
132
202
  **No external API keys or LLM provider subscriptions are required.**
133
203
  You, as the AI coding agent, generate the translations directly:
134
204
 
135
- 1. **Check translation status**:
205
+ 1. **Verify Context First**: Ensure all keys in `localization_base/<source_locale>.json` have proper semantic context.
206
+ 2. **Check translation status**:
136
207
  ```bash
137
208
  shallok status --json
138
209
  ```
139
210
  Identify keys in `messages/<locale>.json` marked with `status: "missing"` or `status: "stale"`.
140
211
 
141
- 2. **Generate Natural Translations**:
142
- - Translate each string into culturally authentic target language (e.g. Kannada, Hindi).
212
+ 3. **Generate Translations from `localization_base/{source_locale}` and Its Context**:
213
+ - 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`.
143
214
  - Use the source `content` and your enriched `context` for accurate terminology.
144
215
  - **Strict Rule**: Preserve all interpolation tokens (`{count}`, `{name}`, `{date}`) exactly as formatted in the source text.
145
216
 
146
- 3. **Update Target Locale Catalogs**:
217
+ 4. **Update Target Locale Catalogs**:
147
218
  Write directly into `messages/<locale>.json` or use:
148
219
  ```bash
149
220
  shallok entry set <locale> <key> "<translated_text>"
@@ -154,6 +225,8 @@ You, as the AI coding agent, generate the translations directly:
154
225
  ```bash
155
226
  shallok extract --apply
156
227
  ```
228
+ Replaces hardcoded strings with `{t('key')}` using normalized dot-separated key paths.
229
+
157
230
  2. **Compile runtime message bundles**:
158
231
  ```bash
159
232
  shallok build
@@ -1,5 +1,20 @@
1
1
  # Astro & astro:i18n Technical Reference
2
2
 
3
+ ## Loading Architecture: Local Bundled Loading for Static SSG & SSR
4
+
5
+ For Astro websites and applications, **always keep translations LOCAL** in `messages/runtime/<locale>.json`.
6
+ - **Zero Build-Time Latency**: Static site generation renders all pages without making external HTTP requests.
7
+ - **Resilient Static Output**: Builds do not fail when third-party CDN or bucket services are unreachable.
8
+ - **Instant Hydration**: HTML pages already include the translated strings directly in the static markup.
9
+
10
+ ### Legacy Base Locale Migration
11
+ If an existing Astro app was importing from `src/locales/en.json` or `locales/en.json`:
12
+ 1. Reconcile keys into `localization_base/en.json`.
13
+ 2. Update the dynamic import in `src/i18n/utils.ts` to target `../../messages/runtime/${locale}.json`.
14
+ 3. Deprecate and remove the old legacy locale folder.
15
+
16
+ ---
17
+
3
18
  ## Configuration Pattern
4
19
 
5
20
  ### 1. `astro.config.mjs`
@@ -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 `localize extract --dry-run` to preview keys and occurrences before committing changes to source files.
34
+ Always use `shallok extract --dry-run` to preview keys and occurrences before committing changes to source files.
@@ -0,0 +1,59 @@
1
+ # Framework Adapters Reference
2
+
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
15
+
16
+ ### 1. React (`react-i18next`)
17
+ - **Initialization**: Generates `src/i18n.ts` configuring `i18next` with `initReactI18next`.
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.
21
+ - **AST Transformation**:
22
+ - Adds `import { useTranslation } from 'react-i18next';`
23
+ - Injects `const { t } = useTranslation();` in components
24
+ - Replaces text with `{t('key')}` using normalized dot-separated key paths.
25
+
26
+ ### 2. Next.js (`next-intl`)
27
+ - **App Router Support**:
28
+ - Generates `src/i18n/routing.ts` defining `locales` and `defaultLocale`.
29
+ - Generates `src/i18n/request.ts` using `getRequestConfig` loading local `messages/runtime/<locale>.json`.
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`.
33
+ - **AST Transformation**:
34
+ - Adds `import { useTranslations } from 'next-intl';`
35
+ - Injects `const t = useTranslations();` in components
36
+ - Replaces text with `{t('key')}` using normalized dot-separated key paths.
37
+
38
+ ### 3. Expo / React Native (`expo-localization` + `react-i18next`)
39
+ - **Initialization**: Generates `i18n.ts` using `getLocales` from `expo-localization` and `i18next`.
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.
43
+ - **AST Transformation**:
44
+ - Adds `import { useTranslation } from 'react-i18next';`
45
+ - Injects `const { t } = useTranslation();` in mobile components
46
+ - Replaces text inside `<Text>` and attributes like `placeholder` with `{t('key')}` using normalized dot-separated key paths.
47
+
48
+ ### 4. Astro (`astro:i18n`)
49
+ - **Initialization**: Generates `src/i18n/utils.ts` defining `locales`, `defaultLocale`, and `useTranslations` loading local `messages/runtime/<locale>.json`.
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`.
53
+ - **Component Usage**:
54
+ - In Astro components frontmatter: `const t = await useTranslations(locale);`
55
+ - Renders `{t('key')}` in templates and islands using normalized dot-separated key paths.
56
+
57
+ ### 5. Vue (`vue-i18n`)
58
+ - **Initialization**: Generates `src/i18n.ts` using `createI18n`.
59
+ - **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
@@ -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, Antigravity):
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
- - The AI agent inspects `messages/<locale>.json` or runs `localize status --json` to identify entries with `status: "missing"` or `status: "stale"`.
8
- - The AI agent writes the translated strings into `messages/<locale>.json` (or uses `localize entry set <locale> <key> "<translated_text>"`).
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, `localize validate` will fail with an error.
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 by AI Agents
30
- 1. When strings are extracted via `localize extract`, the CLI provides baseline AST context (e.g. `JSX text in <button> (in App <button>)`).
31
- 2. The AI Agent analyzes the source code, component hierarchy, and user flow, and enriches the `context` with semantic clarity:
32
- - CLI method: `localize context set <key> "<semantic_description>"`
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
- 3. **Preservation Guarantee**:
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`.