Python i18n API. Many thanks to Campbell and Brecht for the reviews and suggestions!
This commit adds:
* A new bpy.app.translations module giving some info about locales/translation stuff (current active locale, all locales currently known by blender, all translation contexts currently defined, etc.).
* The ability for addons to feature translations, using the (un)register functions of above module.
* Also cleans up "translate py string when storing into RNA prop" by removing "PROP_TRANSLATE" string's subtype, and adding a PROP_STRING_PY_TRANSLATE flag instead (this way it is no more exposed to python...).
Addon translations work with py dictionaries: each addon features a dict {lang: {(context, message): translation, ...}, ...}, which is registered when the addon is enabled (and unregistered when disabled).
Then, when a key (context, message) is not found in regular mo catalog, a cache dict for current locale is built from all registered addon translations, and key is searched in it.
Note: currently addons writers have to do all the work by hand, will add something (probably extend "edit translation" addon) to automate messages extraction from addons soon(ish)! To get a look to expected behavior from addons, have a look at render_copy_settings/__init__.py and render_copy_settings/translations.py (rather stupid example currently, but...). Once we have a complete process, I'll also update relevant wiki pages.
This commit is contained in:
@@ -36,6 +36,10 @@
|
||||
#include "bpy_app_ffmpeg.h"
|
||||
#include "bpy_app_build_options.h"
|
||||
|
||||
#ifdef WITH_INTERNATIONAL
|
||||
# include "bpy_app_translations.h"
|
||||
#endif
|
||||
|
||||
#include "bpy_app_handlers.h"
|
||||
#include "bpy_driver.h"
|
||||
|
||||
@@ -86,7 +90,10 @@ static PyStructSequence_Field app_info_fields[] = {
|
||||
{(char *)"ffmpeg", (char *)"FFmpeg library information backend"},
|
||||
{(char *)"build_options", (char *)"A set containing most important enabled optional build features"},
|
||||
{(char *)"handlers", (char *)"Application handler callbacks"},
|
||||
{NULL}
|
||||
#ifdef WITH_INTERNATIONAL
|
||||
{(char *)"translations", (char *)"Application and addons internationalization API"},
|
||||
#endif
|
||||
{NULL},
|
||||
};
|
||||
|
||||
static PyStructSequence_Desc app_info_desc = {
|
||||
@@ -152,6 +159,9 @@ static PyObject *make_app_info(void)
|
||||
SetObjItem(BPY_app_ffmpeg_struct());
|
||||
SetObjItem(BPY_app_build_options_struct());
|
||||
SetObjItem(BPY_app_handlers_struct());
|
||||
#ifdef WITH_INTERNATIONAL
|
||||
SetObjItem(BPY_app_translations_struct());
|
||||
#endif
|
||||
|
||||
#undef SetIntItem
|
||||
#undef SetStrItem
|
||||
|
||||
Reference in New Issue
Block a user