This object contains some data/methods regarding internationalization in Blender, and allows every py script to feature translations for its own UI messages.
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...).
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.
The actual locale currently in use (will always return a void string when Blender is built without internationalization support).
All locales currently known by Blender (i.e. available as translations).
A readonly dict mapping contexts’ C-identifiers to their py-identifiers.
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_material=’Material’, id_metaball=’Metaball’, id_mesh=’Mesh’, id_nodetree=’NodeTree’, id_object=’Object’, ...)
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). |
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 BLF_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: |
|
---|---|
Returns: | The translated string (or msgid if no translation was found). |
Try to translate the given msgid (with optional msgctxt), if new data name’s translation is enabled.
Note
See pgettext() notes.
Parameters: |
|
---|---|
Returns: | The translated string (or msgid if no translation was found). |
Try to translate the given msgid (with optional msgctxt), if labels’ translation is enabled.
Note
See pgettext() notes.
Parameters: |
|
---|---|
Returns: | The translated string (or msgid if no translation was found). |
Try to translate the given msgid (with optional msgctxt), if tooltips’ translation is enabled.
Note
See pgettext() notes.
Parameters: |
|
---|---|
Returns: | The translated string (or msgid if no translation was found). |
Registers an addon’s UI translations.
Note
Does nothing when Blender is built without internationalization support.
Parameters: |
|
---|
Unregisters an addon’s UI translations.
Note
Does nothing when Blender is built without internationalization support.
Parameters: | module_name (string) – The name identifying the addon. |
---|