shallok 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,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,47 @@
1
+ # React & react-i18next Technical Reference
2
+
3
+ ## Configuration Pattern (`src/i18n.ts`)
4
+ Shallok sets up a deterministic configuration importing compiled runtime message bundles from `messages/runtime/`:
5
+
6
+ ```typescript
7
+ import i18n from 'i18next';
8
+ import { initReactI18next } from 'react-i18next';
9
+
10
+ import enMessages from '../messages/runtime/en.json';
11
+ import knMessages from '../messages/runtime/kn.json';
12
+ import hiMessages from '../messages/runtime/hi.json';
13
+
14
+ const resources = {
15
+ en: { translation: enMessages },
16
+ kn: { translation: knMessages },
17
+ hi: { translation: hiMessages },
18
+ };
19
+
20
+ i18n
21
+ .use(initReactI18next)
22
+ .init({
23
+ resources,
24
+ lng: 'en',
25
+ fallbackLng: 'en',
26
+ interpolation: {
27
+ escapeValue: false, // React already escapes values safely
28
+ },
29
+ });
30
+
31
+ export default i18n;
32
+ ```
33
+
34
+ ## Hook Usage (`useTranslation`)
35
+ - Import: `import { useTranslation } from 'react-i18next';`
36
+ - Call inside functional component: `const { t, i18n } = useTranslation();`
37
+ - Text replacement: `<h1>{t('key')}</h1>`
38
+ - Interpolation: `{t('welcome_user', { name: user.name })}`
39
+ - Language switching: `i18n.changeLanguage('kn');`
40
+
41
+ ## JSX Attributes to Localize
42
+ The Babel AST extractor automatically targets:
43
+ - `placeholder` (e.g. `<input placeholder={t('form.email_placeholder')} />`)
44
+ - `aria-label` (e.g. `<button aria-label={t('nav.close_menu')} />`)
45
+ - `title`
46
+ - `alt`
47
+ - `label`
@@ -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.