|
| 1 | +# Multi-Language Support |
| 2 | + |
| 3 | +Ways supports multilingual matching and output across 52 languages. The system uses two embedding models: a precise English model and a broad multilingual model, routed per-way via frontmatter. |
| 4 | + |
| 5 | +## Setting output language |
| 6 | + |
| 7 | +The agent writes commit messages, comments, and documentation in the configured language. Resolution order: |
| 8 | + |
| 9 | +1. **`ways.json`** `output_language` field — explicit override |
| 10 | +2. **Claude Code** `settings.json` `language` field — agent config (project then user) |
| 11 | +3. **System locale** (`$LC_ALL` → `$LC_MESSAGES` → `$LANG`) |
| 12 | +4. **Default**: `en` |
| 13 | + |
| 14 | +```json |
| 15 | +// ways.json — explicit override |
| 16 | +{"disabled": [], "output_language": "ja"} |
| 17 | +``` |
| 18 | + |
| 19 | +```json |
| 20 | +// Claude Code settings.json — agent-level |
| 21 | +{"language": "japanese"} |
| 22 | +``` |
| 23 | + |
| 24 | +Setting `output_language: "auto"` skips the override and cascades to Claude Code settings → system locale. |
| 25 | + |
| 26 | +The output language directive is injected via `core.md` at session start. Way content (the guidance text) stays English — the agent reads it fine in any language. Only the file output changes. |
| 27 | + |
| 28 | +## How matching works across languages |
| 29 | + |
| 30 | +Two embedding models handle different matching scenarios: |
| 31 | + |
| 32 | +| Model | File | Size | Languages | Use case | |
| 33 | +|-------|------|------|-----------|----------| |
| 34 | +| all-MiniLM-L6-v2 | `minilm-l6-v2.gguf` | 21MB | English | Precise EN matching (default) | |
| 35 | +| paraphrase-multilingual-MiniLM-L12-v2 | `multilingual-minilm-l12-v2-q8.gguf` | 127MB | 52 | Cross-language and same-language matching | |
| 36 | + |
| 37 | +Both are downloaded by `make setup` and stored in `~/.cache/claude-ways/user/`. |
| 38 | + |
| 39 | +Each way declares which model it uses via the `embed_model` frontmatter field: |
| 40 | + |
| 41 | +```yaml |
| 42 | +--- |
| 43 | +description: security vulnerability scanning |
| 44 | +vocabulary: security vulnerability CVE audit |
| 45 | +embed_model: en # default — uses English model |
| 46 | +embed_threshold: 0.35 |
| 47 | +--- |
| 48 | +``` |
| 49 | + |
| 50 | +Ways with `embed_model: multilingual` are scored by the multilingual model against a separate corpus. |
| 51 | + |
| 52 | +## Creating language stubs |
| 53 | + |
| 54 | +A language stub is a frontmatter-only `.{lang}.md` file that provides native-language matching vocabulary for an existing way. The way body stays English — only the matching changes. |
| 55 | + |
| 56 | +``` |
| 57 | +hooks/ways/softwaredev/code/security/ |
| 58 | + security.md # English way — full body + frontmatter |
| 59 | + security.ja.md # Japanese stub — frontmatter only, no body |
| 60 | + security.ko.md # Korean stub — frontmatter only, no body |
| 61 | +``` |
| 62 | + |
| 63 | +Example stub (`security.ja.md`): |
| 64 | + |
| 65 | +```yaml |
| 66 | +--- |
| 67 | +description: セキュリティ脆弱性スキャンと監査 |
| 68 | +vocabulary: セキュリティ 脆弱性 CVE 監査 認証 暗号化 |
| 69 | +embed_model: multilingual |
| 70 | +embed_threshold: 0.25 |
| 71 | +--- |
| 72 | +``` |
| 73 | + |
| 74 | +When a Japanese user types a prompt, the scanner: |
| 75 | +1. Matches `security.ja.md`'s frontmatter using the multilingual model |
| 76 | +2. Injects `security.md`'s English body (the guidance text) |
| 77 | + |
| 78 | +The agent reads the English guidance and responds in the configured output language. |
| 79 | + |
| 80 | +### Why same-language stubs matter |
| 81 | + |
| 82 | +Cross-language matching (Japanese prompt → English description) scores ~0.69. Same-language matching (Japanese prompt → Japanese description) scores ~0.93. The stub's native-language description dramatically improves matching precision. |
| 83 | + |
| 84 | +| Scenario | Cosine similarity | |
| 85 | +|----------|----------------:| |
| 86 | +| EN prompt → EN description (baseline) | 0.76 | |
| 87 | +| JA prompt → EN description (cross-language) | 0.69 | |
| 88 | +| JA prompt → JA description (same-language stub) | 0.93 | |
| 89 | + |
| 90 | +See `docs/architecture/system/multilingual-model-evaluation.md` for full test results. |
| 91 | + |
| 92 | +## Supported languages |
| 93 | + |
| 94 | +Languages are defined in `tools/ways-cli/languages.json`. Each entry specifies: |
| 95 | + |
| 96 | +- **`name`** / **`native`** — display names for normalization |
| 97 | +- **`bm25_stemmer`** — Snowball stemmer algorithm name, or `"impossible"` if BM25 cannot support this language |
| 98 | + |
| 99 | +### BM25 feasibility |
| 100 | + |
| 101 | +BM25 is the fallback matching engine when the embedding model is unavailable. It works for languages with whitespace word boundaries and suffix-stripping morphology: |
| 102 | + |
| 103 | +**BM25 works**: Danish, Dutch, English, Finnish, French, German, Greek, Hungarian, Italian, Norwegian, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish |
| 104 | + |
| 105 | +**BM25 impossible**: Arabic, Burmese, Chinese, Georgian, Gujarati, Hebrew, Hindi, Japanese, Korean, Marathi, Mongolian, Thai, Urdu, Vietnamese — and others marked `"impossible"` in `languages.json` |
| 106 | + |
| 107 | +For "impossible" languages, the embedding engine is required — not optional. Without it, only keyword/regex patterns fire. |
| 108 | + |
| 109 | +## Checking language status |
| 110 | + |
| 111 | +```bash |
| 112 | +# Language coverage report |
| 113 | +ways language |
| 114 | + |
| 115 | +# Filter to a specific language |
| 116 | +ways language --filter ja |
| 117 | + |
| 118 | +# Machine-readable |
| 119 | +ways language --json |
| 120 | + |
| 121 | +# Engine status with corpus breakdown |
| 122 | +ways status |
| 123 | +``` |
| 124 | + |
| 125 | +`ways status` warns if multilingual ways exist in the corpus but the multilingual model is missing. |
| 126 | + |
| 127 | +## Architecture decisions |
| 128 | + |
| 129 | +- **ADR-107**: Full design rationale — language cascade, dual model approach, matching tiers |
| 130 | +- **Evaluation report**: `docs/architecture/system/multilingual-model-evaluation.md` — test data across 11 languages × 3 domains |
0 commit comments