Repository navigation
feat(lang): use the Telegram language for new chats - #120
Merged
Merged
Conversation
When /start is sent in a chat that has no language stored yet, the language_code of the user's Telegram client is now saved for that chat. Before, only the private chat was seeded (and only for users not yet in the database), so groups always started in English. A language chosen via /language is never overwritten. Closes #34 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GT89dKDN1hzS5xThFhA8yF
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.
Requested by Rico · project thread
Closes #34
What was missing
add_useralready stores the user'slanguage_codefor their private chat, but only the first time a user is saved. Group chats never got a language, so they always started in English until someone used/language. Users saved before the private chat was seeded also stayed on English.Changes
Database.set_default_lang_id(chat_id, lang_id): stores the (lower-cased) language for a chat viaINSERT OR IGNORE, so a language picked via/languageis never overwritten. It does nothing when Telegram sends nolanguage_code, and it invalidates theget_lang_idcache so the new language takes effect immediately.start_cmdcalls it for the current chat (private or group) before the game is created, so the very first game message is already translated. Also drops the unusedlang_id/translatorlookup there, which would otherwise have cached"en"for the chat.fr) fall back to English through the existingget_languagelogic, andpt-brstyle codes match the existing translation files.Tests
database_test.py: new chat gets the Telegram language (and cache is refreshed), existing language is kept, missinglanguage_codestores nothing.commands_test.py:start_cmdstores the chat language beforecreate_gameruns.73 tests pass on Python 3.11; the 4 new tests fail without the fix. Note:
statistics_test.py::test_set_game_wonfails on a second local run because it leaves user 123 indatabase/users.db. That is pre-existing and unrelated (it passes on a fresh DB, as in CI).Generated by Claude Code