mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 09:26:10 +00:00
Refactor TranslationContext to be more useful
The previous enum was good at accomplishing dynamic key generation for a few cases, but it fell short in others: 1. It could not discern group names and command names 2. It could not give you more contextual data such as the full object currently being translated. On top of that, the context being a required parameter for Translator.translate meant that it wouldn't be possible to re-use the translator for other use cases outside of the rigid ones defined in the library. To alleviate these concerns, new enum attributes were added along with a richer type for obtaining even more context.
This commit is contained in:
@ -26,7 +26,7 @@ from __future__ import annotations
|
||||
from datetime import datetime
|
||||
|
||||
from .errors import MissingApplicationID
|
||||
from .translator import Translator, TranslationContext, locale_str
|
||||
from .translator import TranslationContextLocation, Translator, TranslationContext, locale_str
|
||||
from ..permissions import Permissions
|
||||
from ..enums import AppCommandOptionType, AppCommandType, AppCommandPermissionType, ChannelType, Locale, try_enum
|
||||
from ..mixins import Hashable
|
||||
@ -463,9 +463,10 @@ class Choice(Generic[ChoiceT]):
|
||||
async def get_translated_payload(self, translator: Translator) -> Dict[str, Any]:
|
||||
base = self.to_dict()
|
||||
name_localizations: Dict[str, str] = {}
|
||||
context = TranslationContext(location=TranslationContextLocation.choice_name, data=self)
|
||||
if self._locale_name:
|
||||
for locale in Locale:
|
||||
translation = await translator._checked_translate(self._locale_name, locale, TranslationContext.choice_name)
|
||||
translation = await translator._checked_translate(self._locale_name, locale, context)
|
||||
if translation is not None:
|
||||
name_localizations[locale.value] = translation
|
||||
|
||||
|
Reference in New Issue
Block a user