core.text¶
Module Contents¶
Classes¶
Class for getting translations from INI text files. |
Attributes¶
- core.text.config¶
- class core.text.Translator(file: str)¶
Class for getting translations from INI text files.
The INI file retrieval is fully based on file’s location, so it can be initiated by calling
1from core import text 2 3tr = text.Translator(__file__).translate
- translate(self, command: str, string: str, ctx: Union[guilded.ext.commands.Context, core.TranslationContext] = None, **values) str¶
Get translation for requested key.
- Parameters
command – The INI section.
[foo]string – Command key.
keyctx – Translation context. Used to determine preferred language.
values – Substitution pairs.
key = value
- Returns
Translated string.
- Raises
BadTranslation – Command, string or some of the values key do not exist.
Given the following language file, you can really easily load strings in user preferred language.
1[_] 2help = Module help 3 4[foo] 5help = Foo command help 6reply = Bar, ((user))!
1await ctx.reply(tr("foo", "reply", ctx, user=ctx.author.name))
- get_language_preference(self, ctx: Union[guilded.ext.commands.Context, core.TranslationContext]) str¶
Get language for the string.
Preference hierarchy:
Try to get user information: if they have language preference, return it.
Try to get guild information: if it has language preference, return it.
Return the bot default.