shallok 0.0.0-stage → 0.1.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 (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -2
  3. package/dist/index.js +52324 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +60 -4
  6. package/skills/astro-localization-and-translation-i18n/SKILL.md +164 -0
  7. package/skills/astro-localization-and-translation-i18n/references/astro-i18n.md +40 -0
  8. package/skills/astro-localization-and-translation-i18n/references/extraction.md +29 -0
  9. package/skills/astro-localization-and-translation-i18n/references/translation.md +45 -0
  10. package/skills/astro-localization-and-translation-i18n/references/versioning.md +57 -0
  11. package/skills/expo-localization-and-translation-i18n/SKILL.md +169 -0
  12. package/skills/expo-localization-and-translation-i18n/references/expo-localization.md +46 -0
  13. package/skills/expo-localization-and-translation-i18n/references/extraction.md +29 -0
  14. package/skills/expo-localization-and-translation-i18n/references/translation.md +45 -0
  15. package/skills/expo-localization-and-translation-i18n/references/versioning.md +57 -0
  16. package/skills/localization-and-translation-i18n/SKILL.md +173 -0
  17. package/skills/localization-and-translation-i18n/references/extraction.md +29 -0
  18. package/skills/localization-and-translation-i18n/references/frameworks.md +40 -0
  19. package/skills/localization-and-translation-i18n/references/translation.md +45 -0
  20. package/skills/localization-and-translation-i18n/references/versioning.md +57 -0
  21. package/skills/localize-app/SKILL.md +80 -0
  22. package/skills/localize-app/references/extraction.md +29 -0
  23. package/skills/localize-app/references/frameworks.md +25 -0
  24. package/skills/localize-app/references/translation.md +45 -0
  25. package/skills/localize-app/references/versioning.md +57 -0
  26. package/skills/nextjs-localization-and-translation-i18n/SKILL.md +166 -0
  27. package/skills/nextjs-localization-and-translation-i18n/references/extraction.md +29 -0
  28. package/skills/nextjs-localization-and-translation-i18n/references/next-intl.md +63 -0
  29. package/skills/nextjs-localization-and-translation-i18n/references/translation.md +45 -0
  30. package/skills/nextjs-localization-and-translation-i18n/references/versioning.md +57 -0
  31. package/skills/react-localization-and-translation-i18n/SKILL.md +266 -0
  32. package/skills/react-localization-and-translation-i18n/references/extraction.md +29 -0
  33. package/skills/react-localization-and-translation-i18n/references/react-i18next.md +47 -0
  34. package/skills/react-localization-and-translation-i18n/references/translation.md +45 -0
  35. package/skills/react-localization-and-translation-i18n/references/versioning.md +57 -0
@@ -0,0 +1,45 @@
1
+ # Translation Engine & Agent-Native Translation Reference
2
+
3
+ ## Agent-Native Translation (Primary Workflow)
4
+ When using Shallok via an AI coding agent (e.g., in Claude, Cursor, Copilot, Antigravity):
5
+ - **No external API keys or LLM provider subscriptions are needed.**
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>"`).
9
+
10
+ ### Translation Schema
11
+ Each entry in `messages/<locale>.json` maintains:
12
+ ```json
13
+ {
14
+ "checkout.pay_now": {
15
+ "value": "ಈಗ ಪಾವತಿಸಿ",
16
+ "source_version": 1,
17
+ "translated_at": "2026-10-19T14:00:00.000Z",
18
+ "status": "translated"
19
+ }
20
+ }
21
+ ```
22
+
23
+ ### Supported Statuses
24
+ - `missing`: Key exists in canonical catalog but has no translation.
25
+ - `stale`: Key source version was incremented; old translation preserved for reference.
26
+ - `translated`: Translated and matching the current canonical `source_version`.
27
+ - `review_required`: Flagged for human review.
28
+ - `approved`: Formally approved translation.
29
+
30
+ ---
31
+
32
+ ## Placeholder Preservation Rules
33
+ The AI agent must strictly preserve all interpolation placeholders in target translations:
34
+ - Source: `"Welcome back, {userName}! You have {itemCount} items in your cart."`
35
+ - Kannada: `"ಮರಳಿ ಸ್ವಾಗತ, {userName}! ನಿಮ್ಮ ಕಾರ್ಟ್‌ನಲ್ಲಿ {itemCount} ಐಟಂಗಳು ಇವೆ."`
36
+ - Hindi: `"वापसी पर स्वागत है, {userName}! आपके कार्ट में {itemCount} आइटम हैं।"`
37
+
38
+ If a translation drops a placeholder or introduces an invalid placeholder, `localize validate` will fail with an error.
39
+
40
+ ---
41
+
42
+ ## CLI-Based Translation (Optional / Fallback)
43
+ For automated pipelines or scripts running outside an interactive AI agent:
44
+ 1. **Mock Provider (`mock`)**: Default provider with built-in dictionary for local development and CI testing.
45
+ 2. **LLM Provider (`llm`)**: Calls OpenAI, Gemini, or Anthropic HTTP APIs when `TRANSLATION_API_KEY` is provided.
@@ -0,0 +1,57 @@
1
+ # Per-Key Versioning & Context Reference
2
+
3
+ ## Canonical Source Catalog (`localization_base/`)
4
+ The canonical catalog is the single source of truth for all active and obsolete keys, including their cryptographic content hashes and version counters.
5
+
6
+ ### Structure of a Canonical Entry
7
+ ```json
8
+ {
9
+ "checkout.pay_now": {
10
+ "key": "checkout.pay_now",
11
+ "content": "Pay now",
12
+ "context": "Primary action button on checkout screen to trigger payment modal",
13
+ "relative_file_path": "src/components/checkout.tsx",
14
+ "occurrences": [
15
+ {
16
+ "relative_file_path": "src/components/checkout.tsx",
17
+ "line": 42,
18
+ "column": 12
19
+ }
20
+ ],
21
+ "last_updated_at": "2026-10-19T10:00:00.000Z",
22
+ "key_version": 1,
23
+ "content_hash": "sha256:...",
24
+ "status": "active"
25
+ }
26
+ }
27
+ ```
28
+
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>"`
33
+ - Direct edit: Update `"context"` in `localization_base/<source_locale>.json`.
34
+ 3. **Preservation Guarantee**:
35
+ 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
+
37
+ ## Reconciliation & Versioning Rules
38
+ 1. **New Key**: Initialized at `key_version = 1`, `status = "active"`.
39
+ 2. **Unchanged Content & Context**: `key_version` and `last_updated_at` remain unchanged.
40
+ 3. **Modified Source Content**: `key_version` increments by 1; `last_updated_at` is updated.
41
+ 4. **File Move / Occurrence Change**: Path and occurrence lines are updated; `key_version` does NOT increment.
42
+ 5. **Key Removed from Source**: Marked `status = "obsolete"`; preserved in catalog for historical retention.
43
+ 6. **Key Reintroduced**: Reactivated as `"active"`.
44
+
45
+ ## Stale Detection in Locale Catalogs
46
+ In `messages/<locale>.json`, each entry records:
47
+ ```json
48
+ {
49
+ "checkout.pay_now": {
50
+ "value": "ಈಗ ಪಾವತಿಸಿ",
51
+ "source_version": 1,
52
+ "translated_at": "2026-10-19T10:05:00.000Z",
53
+ "status": "translated"
54
+ }
55
+ }
56
+ ```
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.
@@ -0,0 +1,173 @@
1
+ ---
2
+ name: localization-and-translation-i18n
3
+ description: Framework-independent, agent-native localization and translation workflow. Uses Shallok CLI (shallok) for deterministic AST extraction, per-key versioning, and validation, with the AI coding agent directly enriching context and translating strings without external API keys.
4
+ ---
5
+
6
+ # Framework-Independent Localization & Translation Skill
7
+
8
+ Use this skill when asked to add, configure, update, or audit localization in **any JavaScript/TypeScript application** regardless of the specific web or mobile framework.
9
+
10
+ ## Two Ways Developers Use Shallok
11
+
12
+ 1. **Via CLI (`npx shallok init`)**: The developer runs `npx shallok init` in their project. Shallok initializes the catalogs, installs `shallok` into `devDependencies`, and adds the skills directly into `.agents/skills/` and `skills/`.
13
+ 2. **Direct Skill Installation**: The developer installs or links this skill into their AI coding agent and directly asks: *"Add localization to this application"* or *"Translate into Kannada and Hindi"*.
14
+
15
+ ---
16
+
17
+ ## Agent Step 0: Verify & Install Shallok CLI
18
+
19
+ **Before executing any localization commands, you (the AI Agent) MUST verify that `shallok` is available:**
20
+
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>`)*
31
+
32
+ ---
33
+
34
+ ## Architecture & Agent Role
35
+
36
+ Shallok pairs a deterministic AST CLI (`shallok`) with **the AI Agent as the semantic translator and context enricher**:
37
+
38
+ 1. **The CLI (`shallok`)** performs deterministic operations:
39
+ - AST parsing, string discovery, and safe code transformations (`shallok extract`).
40
+ - Per-key versioning and SHA-256 content hashing in `localization_base/`.
41
+ - Compiling runtime-ready message bundles in `messages/runtime/` (`shallok build`).
42
+ - Validating 0 missing keys, 0 stale versions, and 0 broken placeholders (`shallok validate`).
43
+
44
+ 2. **The AI Agent (You)** provides semantic intelligence:
45
+ - **No external API keys needed**: You generate natural, authentic translations directly into target languages (e.g. Kannada, Hindi, French, Spanish, German, etc.).
46
+ - **Context Enrichment**: You analyze the UI components and user journey to provide clear, high-quality semantic `context` in `localization_base/` for each key.
47
+ - **Integrity**: You preserve all interpolation tokens (`{count}`, `{name}`, `{amount}`) exactly as they appear in the source text.
48
+
49
+ ---
50
+
51
+ ## 6-Phase Agent Workflow
52
+
53
+ ### Phase A: Analyze
54
+ Inspect repository architecture without modifying files:
55
+ ```bash
56
+ shallok analyze --json
57
+ ```
58
+ - Examine detected framework, router, programming language, and source paths (`src/`).
59
+ - Determine candidate source files and target locales from the user request.
60
+ - **Never edit files during Phase A.**
61
+
62
+ ### Phase B: Plan and Review
63
+ Present a concise plan to the developer:
64
+ 1. **Detected Framework**: Framework name and router type.
65
+ 2. **Runtime Localization Solution**: Suggested runtime library (e.g. `next-intl`, `react-i18next`, `expo-localization`).
66
+ 3. **Locales**: Source locale (e.g. `en`) and target locales (e.g. `kn` Kannada, `hi` Hindi).
67
+ 4. **Planned Scaffolding**:
68
+ - `localization.json` (Project manifest)
69
+ - `localization_base/<source_locale>.json` & `metadata.json` (Canonical catalog & versions)
70
+ - `messages/<locale>.json` (Locale catalogs)
71
+ - Framework adapter configuration
72
+ 5. Confirm with the user before proceeding (or proceed if `--yes` / user requested).
73
+
74
+ ### Phase C: Initialize
75
+ Initialize project configuration and catalogs:
76
+ ```bash
77
+ shallok init --source en --locales kn,hi --framework <name> --yes
78
+ ```
79
+
80
+ ### Phase D: Extract & Enrich Context (AI-Driven)
81
+ 1. **Preview proposed extraction**:
82
+ ```bash
83
+ shallok extract --dry-run --json
84
+ ```
85
+ 2. **Extract strings and reconcile catalog**:
86
+ ```bash
87
+ shallok extract
88
+ ```
89
+ 3. **Enrich Context (Performed by AI Agent)**:
90
+ - Inspect `localization_base/<source_locale>.json`.
91
+ - While the CLI records initial AST element locations, you analyze the actual screen and component purpose.
92
+ - Enrich `context` with semantic clarity (e.g. *"Primary CTA button on checkout page to trigger payment modal"*).
93
+ - Use the CLI:
94
+ ```bash
95
+ shallok context set <key> "<semantic_description>"
96
+ ```
97
+ Or edit `"context"` directly in `localization_base/<source_locale>.json`.
98
+ - **Preservation Guarantee**: Shallok's reconciliation algorithm strictly preserves your enriched context across all future extractions.
99
+
100
+ ### Phase E: Translate (AI-Driven)
101
+ **No external API keys or LLM provider subscriptions are required.**
102
+ You, as the AI coding agent, generate the translations directly:
103
+
104
+ 1. **Identify entries needing translation**:
105
+ ```bash
106
+ shallok status --json
107
+ ```
108
+ Inspect `messages/<locale>.json` for keys with `status: "missing"` or `status: "stale"`.
109
+
110
+ 2. **Generate Translations**:
111
+ - Translate each entry into natural, culturally accurate target language using the source `content` and your enriched `context`.
112
+ - **Rule**: Strictly preserve all interpolation placeholders (`{name}`, `{count}`, `{price}`).
113
+
114
+ 3. **Update Target Locale Catalogs**:
115
+ Update `messages/<locale>.json` directly or using the CLI:
116
+ ```bash
117
+ shallok entry set <locale> <key> "<translated_text>"
118
+ ```
119
+ Or write catalog entries directly in `messages/<locale>.json`:
120
+ ```json
121
+ {
122
+ "checkout.pay_now": {
123
+ "value": "ಈಗ ಪಾವತಿಸಿ",
124
+ "source_version": 1,
125
+ "translated_at": "2026-10-19T14:00:00.000Z",
126
+ "status": "translated"
127
+ }
128
+ }
129
+ ```
130
+
131
+ ### Phase F: Apply, Build & Validate
132
+ 1. **Apply AST transformations to source files**:
133
+ ```bash
134
+ shallok extract --apply
135
+ ```
136
+ Replaces hardcoded strings with `{t('key')}` and injects necessary hooks.
137
+
138
+ 2. **Build runtime message bundles**:
139
+ ```bash
140
+ shallok build
141
+ ```
142
+ Compiles runtime dictionaries to `messages/runtime/<locale>.json`.
143
+
144
+ 3. **Validate catalog integrity**:
145
+ ```bash
146
+ shallok validate
147
+ ```
148
+ Verifies:
149
+ - 0 active keys missing translations.
150
+ - 0 stale versions.
151
+ - 0 dropped or altered placeholders.
152
+
153
+ 4. **Summarize results**:
154
+ Present modified files, supported locales, 100% completeness, and validation status.
155
+
156
+ ---
157
+
158
+ ## Maintenance Workflows
159
+
160
+ - **Add a new language**:
161
+ ```bash
162
+ shallok locale add <locale>
163
+ ```
164
+ Translate active keys into `messages/<locale>.json`, then run `shallok build && shallok validate`.
165
+
166
+ - **Source wording changed**:
167
+ Run `shallok extract`. Only modified keys increment version (`key_version`); only dependent entries are flagged `stale`. Translate the changed string, then `shallok build`.
168
+
169
+ - **Rename a key**:
170
+ ```bash
171
+ shallok key rename <oldKey> <newKey>
172
+ shallok build
173
+ ```
@@ -0,0 +1,29 @@
1
+ # AST Extraction Reference
2
+
3
+ ## Extraction Strategy
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
+
6
+ ## What is Extracted
7
+ 1. **JSX Text Nodes**:
8
+ - `<h1>Welcome</h1>` → `{t('home.welcome')}`
9
+ - `<button>Pay now</button>` → `<button>{t('checkout.pay_now')}</button>`
10
+ 2. **User-Facing Attributes**:
11
+ - `placeholder="Enter your email"`
12
+ - `aria-label="Submit login form"`
13
+ - `title="Cart summary"`
14
+ - `alt="Product thumbnail"`
15
+ - `label="Password"`
16
+ 3. **Conditional UI Expressions**:
17
+ - `{isMember ? 'VIP Member' : 'Guest User'}`
18
+ 4. **Template Literals with Variables**:
19
+ - `Hello, ${name}!` → `Hello, {name}!` with variable preservation.
20
+
21
+ ## What is Explicitly Ignored
22
+ - Technical attributes: `className`, `id`, `name`, `key`, `ref`, `type`, `href`, `src`, `data-testid`, `role`.
23
+ - Console and logger calls: `console.log(...)`, `console.error(...)`, `logger.debug(...)`.
24
+ - URLs, file paths, hex colors, CSS units.
25
+ - Non-user-facing strings, code constants, and symbols.
26
+ - Already localized calls: `t(...)`, `i18n.t(...)`.
27
+
28
+ ## Dry-Run Mode
29
+ Always use `localize extract --dry-run` to preview keys and occurrences before committing changes to source files.
@@ -0,0 +1,40 @@
1
+ # Framework Adapters Reference
2
+
3
+ ## Supported Frameworks
4
+
5
+ ### 1. React (`react-i18next`)
6
+ - **Initialization**: Generates `src/i18n.ts` configuring `i18next` with `initReactI18next`.
7
+ - **Runtime Messages**: Generates clean key-value message files in `messages/runtime/<locale>.json`.
8
+ - **AST Transformation**:
9
+ - Adds `import { useTranslation } from 'react-i18next';`
10
+ - Injects `const { t } = useTranslation();` in components
11
+ - Replaces text with `{t('key')}`
12
+
13
+ ### 2. Next.js (`next-intl`)
14
+ - **App Router Support**:
15
+ - Generates `src/i18n/routing.ts` defining `locales` and `defaultLocale`.
16
+ - Generates `src/i18n/request.ts` using `getRequestConfig`.
17
+ - **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
18
+ - **AST Transformation**:
19
+ - Adds `import { useTranslations } from 'next-intl';`
20
+ - Injects `const t = useTranslations();` in components
21
+ - Replaces text with `{t('key')}`
22
+
23
+ ### 3. Expo / React Native (`expo-localization` + `react-i18next`)
24
+ - **Initialization**: Generates `i18n.ts` using `getLocales` from `expo-localization` and `i18next`.
25
+ - **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
26
+ - **AST Transformation**:
27
+ - Adds `import { useTranslation } from 'react-i18next';`
28
+ - Injects `const { t } = useTranslation();` in mobile components
29
+ - Replaces text inside `<Text>` and attributes like `placeholder` with `{t('key')}`
30
+
31
+ ### 4. Astro (`astro:i18n`)
32
+ - **Initialization**: Generates `src/i18n/utils.ts` defining `locales`, `defaultLocale`, and `useTranslations`.
33
+ - **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
34
+ - **Component Usage**:
35
+ - In Astro components frontmatter: `const t = await useTranslations(locale);`
36
+ - Renders `{t('key')}` in templates and islands.
37
+
38
+ ### 5. Vue (`vue-i18n`)
39
+ - **Initialization**: Generates `src/i18n.ts` using `createI18n`.
40
+ - **Runtime Messages**: Generates runtime message files in `messages/runtime/<locale>.json`.
@@ -0,0 +1,45 @@
1
+ # Translation Engine & Agent-Native Translation Reference
2
+
3
+ ## Agent-Native Translation (Primary Workflow)
4
+ When using Shallok via an AI coding agent (e.g., in Claude, Cursor, Copilot, Antigravity):
5
+ - **No external API keys or LLM provider subscriptions are needed.**
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>"`).
9
+
10
+ ### Translation Schema
11
+ Each entry in `messages/<locale>.json` maintains:
12
+ ```json
13
+ {
14
+ "checkout.pay_now": {
15
+ "value": "ಈಗ ಪಾವತಿಸಿ",
16
+ "source_version": 1,
17
+ "translated_at": "2026-10-19T14:00:00.000Z",
18
+ "status": "translated"
19
+ }
20
+ }
21
+ ```
22
+
23
+ ### Supported Statuses
24
+ - `missing`: Key exists in canonical catalog but has no translation.
25
+ - `stale`: Key source version was incremented; old translation preserved for reference.
26
+ - `translated`: Translated and matching the current canonical `source_version`.
27
+ - `review_required`: Flagged for human review.
28
+ - `approved`: Formally approved translation.
29
+
30
+ ---
31
+
32
+ ## Placeholder Preservation Rules
33
+ The AI agent must strictly preserve all interpolation placeholders in target translations:
34
+ - Source: `"Welcome back, {userName}! You have {itemCount} items in your cart."`
35
+ - Kannada: `"ಮರಳಿ ಸ್ವಾಗತ, {userName}! ನಿಮ್ಮ ಕಾರ್ಟ್‌ನಲ್ಲಿ {itemCount} ಐಟಂಗಳು ಇವೆ."`
36
+ - Hindi: `"वापसी पर स्वागत है, {userName}! आपके कार्ट में {itemCount} आइटम हैं।"`
37
+
38
+ If a translation drops a placeholder or introduces an invalid placeholder, `localize validate` will fail with an error.
39
+
40
+ ---
41
+
42
+ ## CLI-Based Translation (Optional / Fallback)
43
+ For automated pipelines or scripts running outside an interactive AI agent:
44
+ 1. **Mock Provider (`mock`)**: Default provider with built-in dictionary for local development and CI testing.
45
+ 2. **LLM Provider (`llm`)**: Calls OpenAI, Gemini, or Anthropic HTTP APIs when `TRANSLATION_API_KEY` is provided.
@@ -0,0 +1,57 @@
1
+ # Per-Key Versioning & Context Reference
2
+
3
+ ## Canonical Source Catalog (`localization_base/`)
4
+ The canonical catalog is the single source of truth for all active and obsolete keys, including their cryptographic content hashes and version counters.
5
+
6
+ ### Structure of a Canonical Entry
7
+ ```json
8
+ {
9
+ "checkout.pay_now": {
10
+ "key": "checkout.pay_now",
11
+ "content": "Pay now",
12
+ "context": "Primary action button on checkout screen to trigger payment modal",
13
+ "relative_file_path": "src/components/checkout.tsx",
14
+ "occurrences": [
15
+ {
16
+ "relative_file_path": "src/components/checkout.tsx",
17
+ "line": 42,
18
+ "column": 12
19
+ }
20
+ ],
21
+ "last_updated_at": "2026-10-19T10:00:00.000Z",
22
+ "key_version": 1,
23
+ "content_hash": "sha256:...",
24
+ "status": "active"
25
+ }
26
+ }
27
+ ```
28
+
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>"`
33
+ - Direct edit: Update `"context"` in `localization_base/<source_locale>.json`.
34
+ 3. **Preservation Guarantee**:
35
+ 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
+
37
+ ## Reconciliation & Versioning Rules
38
+ 1. **New Key**: Initialized at `key_version = 1`, `status = "active"`.
39
+ 2. **Unchanged Content & Context**: `key_version` and `last_updated_at` remain unchanged.
40
+ 3. **Modified Source Content**: `key_version` increments by 1; `last_updated_at` is updated.
41
+ 4. **File Move / Occurrence Change**: Path and occurrence lines are updated; `key_version` does NOT increment.
42
+ 5. **Key Removed from Source**: Marked `status = "obsolete"`; preserved in catalog for historical retention.
43
+ 6. **Key Reintroduced**: Reactivated as `"active"`.
44
+
45
+ ## Stale Detection in Locale Catalogs
46
+ In `messages/<locale>.json`, each entry records:
47
+ ```json
48
+ {
49
+ "checkout.pay_now": {
50
+ "value": "ಈಗ ಪಾವತಿಸಿ",
51
+ "source_version": 1,
52
+ "translated_at": "2026-10-19T10:05:00.000Z",
53
+ "status": "translated"
54
+ }
55
+ }
56
+ ```
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.
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: localize-app
3
+ description: Instructions and workflows for AI coding agents to inspect, initialize, extract, version, enrich context, translate, and maintain localization in web applications without requiring external translation API keys.
4
+ ---
5
+
6
+ # Localize App Skill (Agent-Native Workflow)
7
+
8
+ Use this skill when asked to add, configure, update, or audit localization in a project (e.g., *"Add localization to this application"*, *"Add Kannada and Hindi"*, *"Translate new strings"*, *"Update stale translations"*).
9
+
10
+ ## Two Ways Developers Use Shallok
11
+
12
+ 1. **Via CLI (`npx shallok init`)**: The developer runs `npx shallok init` in their project. Shallok initializes the catalogs, installs `shallok` into `devDependencies`, and adds this skill directly into `.agents/skills/` and `skills/`.
13
+ 2. **Direct Skill Installation**: The developer installs or links this skill into their AI coding agent and directly asks: *"Add localization to this application"* or *"Translate into Kannada and Hindi"*.
14
+
15
+ ---
16
+
17
+ ## Agent Step 0: Verify & Install Shallok CLI
18
+
19
+ **Before executing any localization commands, you (the AI Agent) MUST verify that `shallok` is available:**
20
+
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>`)*
31
+
32
+ ---
33
+
34
+ ## Core Architecture & Agent Role
35
+
36
+ Shallok pairs a deterministic AST CLI (`shallok`) with **the AI Agent as the translator and context enricher**:
37
+
38
+ 1. **The CLI (`shallok`)** handles deterministic tasks:
39
+ - AST extraction and safe code transformations (`shallok extract`).
40
+ - Per-key versioning and SHA-256 hash reconciliation (`localization_base/`).
41
+ - Runtime message compilation (`shallok build`).
42
+ - Placeholder and catalog integrity checks (`shallok validate`).
43
+
44
+ 2. **The AI Agent (You)** handles semantic intelligence:
45
+ - **No external API keys or LLM provider keys needed!** You, as the AI agent, generate the translations directly.
46
+ - **Context Enrichment**: You analyze the UI components, user flows, and screen layouts to provide rich, meaningful semantic `context` in `localization_base/` for each key.
47
+ - **Culturally Appropriate Translations**: You translate the strings into configured target locales while strictly preserving interpolation tokens (e.g., `{count}`, `{name}`).
48
+
49
+ ---
50
+
51
+ ## 6-Phase Agent Workflow
52
+
53
+ ### Phase A: Analyze
54
+ Execute read-only repository inspection before making changes:
55
+ ```bash
56
+ shallok analyze --json
57
+ ```
58
+
59
+ ### Phase B: Plan and Review
60
+ Present a concise plan to the developer (framework, router, locales, scaffolding).
61
+
62
+ ### Phase C: Initialize
63
+ ```bash
64
+ shallok init --source en --locales kn,hi --framework <name> --yes
65
+ ```
66
+
67
+ ### Phase D: Extract & Enrich Context
68
+ 1. Preview proposed extraction: `shallok extract --dry-run --json`
69
+ 2. Extract strings: `shallok extract`
70
+ 3. Enrich Context: `shallok context set <key> "<semantic_description>"`
71
+
72
+ ### Phase E: Translate (AI-Driven)
73
+ 1. Check status: `shallok status --json`
74
+ 2. Generate Natural Translations preserving `{tokens}`.
75
+ 3. Update catalog directly or via: `shallok entry set <locale> <key> "<translated_text>"`
76
+
77
+ ### Phase F: Apply, Build & Validate
78
+ 1. Transform source components: `shallok extract --apply`
79
+ 2. Compile runtime message bundles: `shallok build`
80
+ 3. Validate catalog integrity: `shallok validate`
@@ -0,0 +1,29 @@
1
+ # AST Extraction Reference
2
+
3
+ ## Extraction Strategy
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
+
6
+ ## What is Extracted
7
+ 1. **JSX Text Nodes**:
8
+ - `<h1>Welcome</h1>` → `{t('home.welcome')}`
9
+ - `<button>Pay now</button>` → `<button>{t('checkout.pay_now')}</button>`
10
+ 2. **User-Facing Attributes**:
11
+ - `placeholder="Enter your email"`
12
+ - `aria-label="Submit login form"`
13
+ - `title="Cart summary"`
14
+ - `alt="Product thumbnail"`
15
+ - `label="Password"`
16
+ 3. **Conditional UI Expressions**:
17
+ - `{isMember ? 'VIP Member' : 'Guest User'}`
18
+ 4. **Template Literals with Variables**:
19
+ - `Hello, ${name}!` → `Hello, {name}!` with variable preservation.
20
+
21
+ ## What is Explicitly Ignored
22
+ - Technical attributes: `className`, `id`, `name`, `key`, `ref`, `type`, `href`, `src`, `data-testid`, `role`.
23
+ - Console and logger calls: `console.log(...)`, `console.error(...)`, `logger.debug(...)`.
24
+ - URLs, file paths, hex colors, CSS units.
25
+ - Non-user-facing strings, code constants, and symbols.
26
+ - Already localized calls: `t(...)`, `i18n.t(...)`.
27
+
28
+ ## Dry-Run Mode
29
+ Always use `localize extract --dry-run` to preview keys and occurrences before committing changes to source files.
@@ -0,0 +1,25 @@
1
+ # Framework Adapters Reference
2
+
3
+ ## Supported Frameworks
4
+
5
+ ### 1. React (`react-i18next`)
6
+ - **Initialization**: Generates `src/i18n.ts` configuring `i18next` with `initReactI18next`.
7
+ - **Runtime Messages**: Generates clean key-value message files in `messages/<locale>.json`.
8
+ - **AST Transformation**:
9
+ - Adds `import { useTranslation } from 'react-i18next';`
10
+ - Injects `const { t } = useTranslation();` in components
11
+ - Replaces text with `{t('key')}`
12
+
13
+ ### 2. Next.js (`next-intl`)
14
+ - **App Router Support**:
15
+ - Generates `src/i18n/routing.ts` defining `locales` and `defaultLocale`.
16
+ - Generates `src/i18n/request.ts` using `getRequestConfig`.
17
+ - **Runtime Messages**: Generates runtime message files in `messages/<locale>.json`.
18
+ - **AST Transformation**:
19
+ - Adds `import { useTranslations } from 'next-intl';`
20
+ - Injects `const t = useTranslations();` in components
21
+ - Replaces text with `{t('key')}`
22
+
23
+ ### 3. Vue (`vue-i18n`)
24
+ - **Initialization**: Generates `src/i18n.ts` using `createI18n`.
25
+ - **Runtime Messages**: Generates nested runtime message files in `messages/<locale>.json`.
@@ -0,0 +1,45 @@
1
+ # Translation Engine & Agent-Native Translation Reference
2
+
3
+ ## Agent-Native Translation (Primary Workflow)
4
+ When using Shallok via an AI coding agent (e.g., in Claude, Cursor, Copilot, Antigravity):
5
+ - **No external API keys or LLM provider subscriptions are needed.**
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>"`).
9
+
10
+ ### Translation Schema
11
+ Each entry in `messages/<locale>.json` maintains:
12
+ ```json
13
+ {
14
+ "checkout.pay_now": {
15
+ "value": "ಈಗ ಪಾವತಿಸಿ",
16
+ "source_version": 1,
17
+ "translated_at": "2026-10-19T14:00:00.000Z",
18
+ "status": "translated"
19
+ }
20
+ }
21
+ ```
22
+
23
+ ### Supported Statuses
24
+ - `missing`: Key exists in canonical catalog but has no translation.
25
+ - `stale`: Key source version was incremented; old translation preserved for reference.
26
+ - `translated`: Translated and matching the current canonical `source_version`.
27
+ - `review_required`: Flagged for human review.
28
+ - `approved`: Formally approved translation.
29
+
30
+ ---
31
+
32
+ ## Placeholder Preservation Rules
33
+ The AI agent must strictly preserve all interpolation placeholders in target translations:
34
+ - Source: `"Welcome back, {userName}! You have {itemCount} items in your cart."`
35
+ - Kannada: `"ಮರಳಿ ಸ್ವಾಗತ, {userName}! ನಿಮ್ಮ ಕಾರ್ಟ್‌ನಲ್ಲಿ {itemCount} ಐಟಂಗಳು ಇವೆ."`
36
+ - Hindi: `"वापसी पर स्वागत है, {userName}! आपके कार्ट में {itemCount} आइटम हैं।"`
37
+
38
+ If a translation drops a placeholder or introduces an invalid placeholder, `localize validate` will fail with an error.
39
+
40
+ ---
41
+
42
+ ## CLI-Based Translation (Optional / Fallback)
43
+ For automated pipelines or scripts running outside an interactive AI agent:
44
+ 1. **Mock Provider (`mock`)**: Default provider with built-in dictionary for local development and CI testing.
45
+ 2. **LLM Provider (`llm`)**: Calls OpenAI, Gemini, or Anthropic HTTP APIs when `TRANSLATION_API_KEY` is provided.