-
-
Notifications
You must be signed in to change notification settings - Fork 0
Localizing commands
Mmesek edited this page Jun 5, 2022
·
2 revisions
Simply run MFramework with -update-translation flag, it will generate translation files with command name, description, arguments and choices for each found locale and then exit
If you don't have any locale yet, create empty directory named en-US in locale folder to get started
Example:
python3 -m MFramework bot -update-translation
- Go to
locale - Copy
enand paste - Rename to another locale's language code, preferable according to this table: https://discord.com/developers/docs/reference#locales
- Dive into each file you find there and rewrite values (right hand side to
:) into your language.
- Run MFramework with
-update-translationflag:python3 -m MFramework bot -update-translation - Check diff of changes
- Edit changes
- Keys has to stay as-is
- Internalization works based on python-18n module:
- Placeholders are marked with
%{}like:%{variable}and their content shouldn't be translated - If a string can be pluralized, like one, few or many, value should be a mapping containing keys for
zero,one,fewandmanyand respective values for singular/plural forms:"key":{ "zero": "Nothing", "one": "One key", "few": "Only %{count} keys", "many": "${count} keys!" }
- Placeholders are marked with
- If you want to use your translated string in code, you can do so in command's function by using
ctx.t("key", count=5, another_placeholder="your_name"). Note however, this method is automatically choosing Context's language as well as setting up a namespace of your localization (therefore, if your key is nested in locale according to function's path likebot.commands.stuff.command_name.keyyou only need to supply"key"as a localization key). - If there is no
Contextavailable, you can usetranslatefunction fromutils.localizations. This method doesn't know the namespace or language therefore full key has to be supplied.