Skip to content

Conversation

@blackg820
Copy link

use host lang for better translation than default for all users

use host lang for better translation than default for all users
Copy link
Owner

@jacklul jacklul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code completely overrides the language to hosts' language, I don't like it as there will be no option to change the language when needed.

A better approach would be to set the language to hosts' language on game creation:

    protected function newAction(): ServerResponse
    {
        if ($this->getUser('host')) {
            return $this->answerCallbackQuery(__('This game is already created!'), true);
        }

        $this->data['players']['host'] = (array) $this->getCurrentUser(true);
        $this->data['players']['guest'] = null;

        if (isset($this->data['settings']['use_old_mentions']) && $this->data['settings']['use_old_mentions'] === true) {
            $this->data['settings']['use_old_mentions'] = false;
        }
+
+       if (!empty($lang_code = $this->data['players']['host']['language_code'])) {
+           $current_lang = Language::getCurrentLanguage();
+           Language::set($lang_code);
+           $new_lang = Language::getCurrentLanguage();
+
+           if ($current_lang != $new_lang) {
+               $this->data['settings']['language'] = $new_lang;
+           }
+       }

        $this->data['game_data'] = null;

        if ($this->saveData($this->data)) {
            return $this->editMessage(__('{PLAYER_HOST} is waiting for opponent to join...', ['{PLAYER_HOST}' => $this->getUserMention('host')]) . PHP_EOL . __('Press {BUTTON} button to join.', ['{BUTTON}' => '<b>\'' . __('Join') . '\'</b>']), $this->getReplyMarkup('lobby'));
        }

        throw new StorageException();
    }

@jacklul jacklul changed the base branch from master to develop September 23, 2025 15:32
jacklul added a commit that referenced this pull request Jan 10, 2026
@jacklul jacklul closed this Jan 10, 2026
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.

2 participants