Skip to content

feat(lang): use the Telegram language for new chats - #120

Merged
d-Rickyy-b merged 1 commit into
masterfrom
claude/fix-issue-34-9ly16n
Oct 20, 2026
Merged

d-Rickyy-b merged 1 commit into
masterfrom
claude/fix-issue-34-9ly16n

Conversation

@d-Rickyy-b

Copy link
Copy Markdown
Owner

Requested by Rico · project thread

Closes #34

What was missing

add_user already stores the user's language_code for 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

  • New Database.set_default_lang_id(chat_id, lang_id): stores the (lower-cased) language for a chat via INSERT OR IGNORE, so a language picked via /language is never overwritten. It does nothing when Telegram sends no language_code, and it invalidates the get_lang_id cache so the new language takes effect immediately.
  • start_cmd calls 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 unused lang_id/translator lookup there, which would otherwise have cached "en" for the chat.
  • Codes without a translation (e.g. fr) fall back to English through the existing get_language logic, and pt-br style codes match the existing translation files.

Tests

  • database_test.py: new chat gets the Telegram language (and cache is refreshed), existing language is kept, missing language_code stores nothing.
  • commands_test.py: start_cmd stores the chat language before create_game runs.

73 tests pass on Python 3.11; the 4 new tests fail without the fix. Note: statistics_test.py::test_set_game_won fails on a second local run because it leaves user 123 in database/users.db. That is pre-existing and unrelated (it passes on a fresh DB, as in CI).


Generated by Claude Code

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
@d-Rickyy-b d-Rickyy-b self-assigned this Oct 20, 2026
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 73.279% (+1.8%) from 71.505% — claude/fix-issue-34-9ly16n into master

@d-Rickyy-b
d-Rickyy-b merged commit bae6761 into master Oct 20, 2026
4 checks passed
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.

Take language ID from Telegram API

3 participants