tane/docs/i18n.md
vjrj baa8867287 feat(i18n): full RTL/CJK support — fonts, Japanese locale, directional fixes
Bundle Noto Sans Arabic + Noto Sans JP (SIL OFL 1.1) as per-glyph fallbacks
for both the UI text theme and every generated PDF, so RTL (Arabic) and CJK
render on all platforms — including desktop, where the system font may lack
them — instead of tofu. A shared pdf_fonts.dart centralizes the PDF theme and
the three label/catalog/recovery services reuse it.

Add Japanese (ja) as the CJK reference locale — fittingly, the app's own name
is Japanese (種, tane, 'seed'). Core strings translated; the rest fall back to
English via slang. Wired into supportedLocales (automatic) and the settings
picker.

Fix three physical Alignment.centerLeft -> AlignmentDirectional.centerStart in
variety_detail_screen, and make month-abbreviation and avatar-initial
truncation grapheme-safe (.characters) so CJK text is never cut mid-character.

Tests: CJK/Arabic PDF glyph render, ja locale resolution + English fallback.
The chat-bubble mirroring flagged by the audit was verified correct (already
respects Directionality) and left unchanged.
2026-07-14 11:11:19 +02:00

2.8 KiB

Translating Tane

Tane is multilingual by design — international, not any-country-first (see the golden rules in ../CLAUDE.md). Translations live as one JSON file per locale, a format Weblate (and any translation platform that speaks nested JSON) handles natively.

Where strings live

apps/app_seeds/lib/i18n/
  en.i18n.json   ← base locale (source of truth for keys)
  es.i18n.json   ast, pt, fr, de, ja …
  strings*.g.dart  ← generated, do not edit

Live locales: es, ast, en, pt, fr, de, ja. Japanese (ja) is the CJK reference — fittingly, the app's own name is Japanese (種, tane, "seed"). It ships only a core set of strings translated; the rest fall back to English, which is exactly how a partial locale is meant to grow.

  • Placeholders use braces: "{count} entries added". Keep them verbatim.
  • Keys are code and never change per locale; only values are translated.
  • Missing keys fall back to English at runtime (fallback_strategy: base_locale in slang.yaml), so a partial translation is shippable from day one.

Adding a locale

  1. Copy en.i18n.json to <code>.i18n.json (e.g. fr.i18n.json) and translate what you can.
  2. Regenerate the Dart bindings:
    cd apps/app_seeds && dart run slang
    
  3. Add a language tile in settings_screen.dart (label = the language's own name, e.g. "Français") plus the langXx key in every locale file.
  4. Run the tests: flutter test (an i18n test guards against hardcoded strings; the RTL smoke test guards right-to-left layouts).

RTL and scripts

Right-to-left locales (Arabic, Hebrew, Persian) are first-class: layouts use directional insets and are exercised by rtl_smoke_test.dart.

Fonts cover the scripts we claim. The UI text theme carries Noto Sans Arabic + Noto Sans JP as per-glyph fallbacks (see theme.dart), so RTL and CJK render on every platform — including desktop, where the system font may lack them. Every generated PDF shares the same fallbacks via pdf_fonts.dart, so labels and catalogs print Arabic/CJK instead of tofu. Fonts are a per-locale resource, extensible to any script; widen the fallback list as more scripts land.

Locale-specific resources ship with their locale, never hardcoded: OCR language packs (assets/tessdata/), PDF fonts (assets/fonts/), and species common names (assets/catalog/species.json, a locale-keyed map).

Weblate

The JSON-per-locale layout is Weblate-ready (component per file, base en.i18n.json). Hosting is not set up yet; when it is, this page will link to the project. Until then, translation PRs/patches are welcome directly on the files above.