feat: i18n system with TOML catalogs + language setting#121
Open
feat: i18n system with TOML catalogs + language setting#121
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Full i18n system for the bot. Supersedes #120 (localised commands PR β this includes all of that plus everything else).
What's new
reverse_image_search_bot/i18n/*.tomllanguage_codeβ English fallbacklanguage_codeparameterlanguagecolumn auto-created on startupArchitecture
Usage:
t("search.no_results", lang(update), engines=engines_html)Changes
commands.pyβ all hardcoded strings βt()callsbot.pyβ commands + bot started message β TOML-drivenconfig/db.pyβ addedlanguage TEXTcolumnconfig/chat_config.pyβ addedlanguage: str | Nonefieldtests/β updated for new string format + localised command countTests
384 passing, 0 failures