# Language files

Translation source of truth: **en.json**. Other locale files should have the same keys; values are translated.

## Check missing or untranslated keys

Keys are considered **untranslated** when the value is identical to the key (left in English).

```bash
# All locales
npm run i18n:check

# One locale
node lang/check-missing-translations.cjs --locale=de

# Machine-readable report (includes key lists)
node lang/check-missing-translations.cjs --json
```

## Translate automatically

The `translate-missing.cjs` script fills in untranslated keys. It only updates keys where the value is still the same as the key.

**Default: MyMemory** (no key; free, ~1000 words/day). Use `--limit=N` to stay under the daily quota, e.g. `--limit=50` per run.

**Optional: LibreTranslate** (higher limits with a free API key). Get a key at [portal.libretranslate.com](https://portal.libretranslate.com), then:

```bash
LIBRETRANSLATE_API_KEY=your_key node lang/translate-missing.cjs --locale=de
```

```bash
# Dry run: show what would be translated (no changes)
node lang/translate-missing.cjs --dry-run

# Translate one locale (MyMemory; use --limit=50 to avoid daily quota)
node lang/translate-missing.cjs --locale=de --limit=50

# Translate one locale with LibreTranslate key (no limit needed)
LIBRETRANSLATE_API_KEY=xxx node lang/translate-missing.cjs --locale=de

# Translate all locales (slow; use with LibreTranslate key)
LIBRETRANSLATE_API_KEY=xxx node lang/translate-missing.cjs
```

Optional: use your own LibreTranslate instance:

```bash
LIBRETRANSLATE_URL=https://your-instance.com LIBRETRANSLATE_API_KEY=xxx node lang/translate-missing.cjs --locale=de
```

Locale file names are mapped to API codes (e.g. `cn` → `zh-Hans`, `bd` → `bn`, `sa` → `ar`, `se` → `sv`). Edit `LOCALE_TO_API` in `translate-missing.cjs` to add or change mappings.

## Manual translation

After running the auto-translation, review and fix strings in each JSON file. Placeholder keys (numbers, emails, etc.) are skipped by the script on purpose.
