Application Translations (bpy.app.translations)¶
This object contains some data/methods regarding internationalization in Blender, and allows every py script to feature translations for its own UI messages.
Intro¶
Warning
Most of this object should only be useful if you actually manipulate i18n stuff from Python.
If you are a regular addon, you should only bother about contexts
member,
and the register()
/unregister()
functions! The pgettext()
family of functions
should only be used in rare, specific cases (like e.g. complex “composited” UI strings...).
{locale: {msg_key: msg_translation, ...}, ...}
- locale is either a lang iso code (e.g.
fr
), a lang+country code (e.g.pt_BR
), a lang+variant code (e.g.sr@latin
), or a full code (e.g.uz_UZ@cyrilic
). - msg_key is a tuple (context, org message) - use, as much as possible, the predefined
contexts
. - msg_translation is the translated message in given language!
Then, call bpy.app.translations.register(__name__, your_dict)
in your register()
function, and n”
bpy.app.translations.unregister(__name__)
in your unregister()
one.
The Manage UI translations
addon has several functions to help you collect strings to translate, and
generate the needed python code (the translation dictionary), as well as optional intermediary po files
if you want some... See
How to Translate Blender and
Using i18n in Blender Code
for more info.
Module References¶
-
bpy.app.translations.
locale
¶ The actual locale currently in use (will always return a void string when Blender is built without internationalization support).
-
bpy.app.translations.
locales
¶ All locales currently known by Blender (i.e. available as translations).
-
bpy.app.translations.
contexts_C_to_py
¶ A readonly dict mapping contexts’ C-identifiers to their py-identifiers.
-
bpy.app.translations.
contexts
¶ constant value bpy.app.translations.contexts(default_real=None, default=’*’, operator_default=’Operator’, plural=’Plural’, id_action=’Action’, id_armature=’Armature’, id_brush=’Brush’, id_camera=’Camera’, id_curve=’Curve’, id_fs_linestyle=’FreestyleLineStyle’, id_gpencil=’GPencil’, id_group=’Group’, id_id=’ID’, id_image=’Image’, id_shapekey=’Key’, id_lamp=’Lamp’, id_library=’Library’, id_lattice=’Lattice’, id_mask=’Mask’, id_material=’Material’, id_metaball=’Metaball’, id_mesh=’Mesh’, id_movieclip=’MovieClip’, ...)
-
bpy.app.translations.
locale_explode
(locale)¶ Return all components and their combinations of the given ISO locale string.
>>> bpy.app.translations.locale_explode("sr_RS@latin") ("sr", "RS", "latin", "sr_RS", "sr@latin")
For non-complete locales, missing elements will be None.
Parameters: locale – The ISO locale string to explode. Returns: A tuple (language, country, variant, language_country, language@variant)
.
-
bpy.app.translations.
pgettext
(msgid, msgctxt)¶ Try to translate the given msgid (with optional msgctxt).
Note
The
(msgid, msgctxt)
parameters order has been switched compared to gettext function, to allow single-parameter calls (context then defaults to BLT_I18NCONTEXT_DEFAULT).Note
You should really rarely need to use this function in regular addon code, as all translation should be handled by Blender internal code. The only exception are string containing formatting (like “File: %r”), but you should rather use
pgettext_iface()
/pgettext_tip()
in those cases!Note
Does nothing when Blender is built without internationalization support (hence always returns
msgid
).Parameters: - msgid (string) – The string to translate.
- msgctxt (string or None) – The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).
Returns: The translated string (or msgid if no translation was found).
-
bpy.app.translations.
pgettext_data
(msgid, msgctxt)¶ Try to translate the given msgid (with optional msgctxt), if new data name’s translation is enabled.
Note
See
pgettext()
notes.Parameters: - msgid (string) – The string to translate.
- msgctxt (string or None) – The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).
Returns: The translated string (or
msgid
if no translation was found).
-
bpy.app.translations.
pgettext_iface
(msgid, msgctxt)¶ Try to translate the given msgid (with optional msgctxt), if labels’ translation is enabled.
Note
See
pgettext()
notes.Parameters: - msgid (string) – The string to translate.
- msgctxt (string or None) – The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).
Returns: The translated string (or msgid if no translation was found).
-
bpy.app.translations.
pgettext_tip
(msgid, msgctxt)¶ Try to translate the given msgid (with optional msgctxt), if tooltips’ translation is enabled.
Note
See
pgettext()
notes.Parameters: - msgid (string) – The string to translate.
- msgctxt (string or None) – The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).
Returns: The translated string (or msgid if no translation was found).
-
bpy.app.translations.
register
(module_name, translations_dict)¶ Registers an addon’s UI translations.
Note
Does nothing when Blender is built without internationalization support.
Parameters: - module_name (string) – The name identifying the addon.
- translations_dict (dict) – A dictionary built like that:
{locale: {msg_key: msg_translation, ...}, ...}