-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation
Name | Type | Description |
---|---|---|
localizations | Union[str , dict ] |
If str : relative path to the localization JSON or YAML file. If dict : dictionary containing the localizations. |
default_locale | Optional[str ] |
The default locale to use if a given locale is not found in the localization. |
error | Optional[bool ] |
Whether to raise an error if the localization is not found. If set to False , it will return the key itself. Defaults to False . |
Name | Type | Description |
---|---|---|
default_locale | Optional[str ] |
The default locale that was defined in the default_locale attribute. |
error | Optional[str ] |
Whether the library should raise errors (True ) or log them with the logging module and return the key False ) |
Operation | Description |
---|---|
x == y |
Returns whether two objects have the same localizations stored. |
x != y |
Returns whether two objects don't have the same localizations stored. |
dict(x) |
Returns the localization data. |
x |
Calling the object will automatically call the localize method. |
Formats the strings in a dictionary. This is used internally, to format strings in the localize
method.
data ( Any ) : The data to format.
**kwargs ( Any ) : The arguments to pass to the string formatter.
Any : The formatted data.
localize ( text: str, locale: Union[str, discord.Locale, discord.Guild, discord.Interaction, discord.ext.commands.Context], **kwargs: Any )
Gets the localization of a string like it's done in i18n.
text ( str
) : The key to find in the localization file.
locale ( Union[str
, Locale
, Guild
, Interaction
, Context
] ) : The locale to find the localization with, or an object that has an attribute that returns discord.Locale
.
**kwargs ( Any ) : The arguments to pass to the string formatter.
Union[str
, List[str
], dict
] : The localized data.
TypeError
: The locale parameter received an incorrect type.
InvalidLocale
: The locale parameter is not found in the localization file.
LocalizationNotFound
: The localization key is not found in the localization file.
_
, t
, translate
, localise
one ( text: str, number: Union[int, float], locale: Union[str, discord.Locale, discord.Guild, discord.Interaction, discord.ext.commands.Context], **kwargs: Any )
Gets the singular and plural form of a string like it's done in i18n.
For this, you need to have the key in the JSON be a list of two strings, the first being the singular form, the second being the plural form.
This method can raise any errors that the localize
method can raise.
text ( str
) : The key to find in the localization file. The number to determine whether to use the singular (list[0]
) or plural (list[-1]
) form.
number ( Union[int
, float
] ) :
locale ( Union[str
, Locale
, Guild
, Interaction
, Context
] ) : The locale to find the localization with, or an object that has an attribute that returns discord.Locale
.
**kwargs ( Any ) : The arguments to pass to the string formatter.
str
: If num
is 1, returns the first item of the list. Otherwise, it returns the last item of the list.
WrongLocalizationFormat
: The localization key is not a list.
_o
, o
Raised when there is incorrect formatting in the localization file.
Raised when the localization file is not found.
Raised when the localization is not found.
Raised when the locale is not found.
Raised when the localization is not a list.