Browse Source

Fix autocomplete translations calling unnecessary locales

pull/8340/head
Rapptz 3 years ago
parent
commit
49e6fe9a0c
  1. 10
      discord/app_commands/models.py
  2. 3
      discord/interactions.py

10
discord/app_commands/models.py

@ -484,6 +484,16 @@ class Choice(Generic[ChoiceT]):
return base
async def get_translated_payload_for_locale(self, translator: Translator, locale: Locale) -> Dict[str, Any]:
base = self.to_dict()
if self._locale_name:
context = TranslationContext(location=TranslationContextLocation.choice_name, data=self)
translation = await translator._checked_translate(self._locale_name, locale, context)
if translation is not None:
base['name'] = translation
return base
def to_dict(self) -> Dict[str, Any]:
base = {
'name': self.name,

3
discord/interactions.py

@ -880,8 +880,9 @@ class InteractionResponse:
translator = self._parent._state._translator
if translator is not None:
user_locale = self._parent.locale
payload: Dict[str, Any] = {
'choices': [await option.get_translated_payload(translator) for option in choices],
'choices': [await option.get_translated_payload_for_locale(translator, user_locale) for option in choices],
}
else:
payload: Dict[str, Any] = {

Loading…
Cancel
Save