Skip to content

feat: i18n system with TOML catalogs + language setting#121

Open
Nachtalb wants to merge 5 commits intomasterfrom
feature/i18n
Open

feat: i18n system with TOML catalogs + language setting#121
Nachtalb wants to merge 5 commits intomasterfrom
feature/i18n

Conversation

@Nachtalb
Copy link
Owner

@Nachtalb Nachtalb commented Mar 4, 2026

Full i18n system for the bot. Supersedes #120 (localised commands PR β€” this includes all of that plus everything else).

What's new

  • TOML-based string catalogs β€” all user-facing strings in reverse_image_search_bot/i18n/*.toml
  • 8 languages: English, Russian, Chinese, Spanish, Italian, Arabic, Japanese, German
  • Language picker in /settings β€” users/admins can override their language
  • Language priority: ChatConfig override β†’ Telegram user language_code β†’ English fallback
  • Localised bot commands via PTB's language_code parameter
  • SQLite migration β€” new language column auto-created on startup

Architecture

reverse_image_search_bot/i18n/
  __init__.py     # t(), lang(), available_languages()
  en.toml         # canonical (English)
  ru.toml, zh.toml, es.toml, it.toml, ar.toml, ja.toml, de.toml

Usage: t("search.no_results", lang(update), engines=engines_html)

Changes

  • commands.py β€” all hardcoded strings β†’ t() calls
  • bot.py β€” commands + bot started message β†’ TOML-driven
  • config/db.py β€” added language TEXT column
  • config/chat_config.py β€” added language: str | None field
  • tests/ β€” updated for new string format + localised command count

Tests

384 passing, 0 failures

Nachtalb added 5 commits March 4, 2026 07:56
- New i18n module with TOML string catalogs for 8 languages:
  en, ru, zh, es, it, ar, ja, de
- Language priority: ChatConfig override > Telegram user lang > en
- Added 'language' column to SQLite ChatConfig (auto-migrates)
- Language picker in /settings UI with flag display names
- All user-facing strings extracted from commands.py and bot.py
- Bot commands registered with per-language translations via PTB
- Admin commands remain English-only
- Removed emojize dependency from commands.py (literals in TOML)
- 384 tests passing
- _flatten: flat, nested, deep, prefix, empty, type coercion
- t(): lookup, fallback, kwargs, missing keys, HTML/emoji/newlines
- lang(): ChatConfig override, user lang, region codes, edge cases
- available_languages(): sorted, complete, expected count
- Catalog integrity: key parity, placeholder consistency, no empties
- Added [fields] section to all 8 TOML language files
- translate_field() maps English labels to i18n keys with fallback
- build_reply() now translates field names in search results
- Unknown/dynamic fields fall back to their original English label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant