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:
2013-01-20 17:29:07 +00:00
parent 08bcbafe36
commit cef730d969
23 changed files with 890 additions and 50 deletions

View File

@@ -1623,8 +1623,12 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
}
}
else {
/* Unicode String */
#ifdef WITH_INTERNATIONAL
bool do_translate = RNA_property_flag(prop) & PROP_STRING_PY_TRANSLATE;
#else
bool do_translate = false;
#endif /* WITH_INTERNATIONAL */
#ifdef USE_STRING_COERCE
PyObject *value_coerce = NULL;
@@ -1634,17 +1638,16 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
}
else {
param = _PyUnicode_AsString(value);
#ifdef WITH_INTERNATIONAL
if (subtype == PROP_TRANSLATE) {
param = IFACE_(param);
}
#endif /* WITH_INTERNATIONAL */
}
#else /* USE_STRING_COERCE */
param = _PyUnicode_AsString(value);
#endif /* USE_STRING_COERCE */
/* Any half-brained compiler should be able to optimize this out when WITH_INTERNATIONAL is off */
if (do_translate) {
param = IFACE_(param);
}
if (param == NULL) {
if (PyUnicode_Check(value)) {
/* there was an error assigning a string type,