diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2013-01-20 21:29:07 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2013-01-20 21:29:07 +0400 |
commit | cef730d969b35d7cc25006acded05c361602b319 (patch) | |
tree | 7b2b5f2412aac91cb9247866992cc8ae935cd241 /source/blender/makesrna | |
parent | 08bcbafe36e28330f98d9143fe4743e69f6d6289 (diff) |
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.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_types.h | 13 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_rna.c | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 6 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui_api.c | 6 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 6 |
8 files changed, 21 insertions, 25 deletions
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 463e0e04679..cd6d74c3488 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -87,7 +87,7 @@ PropertyRNA *RNA_def_string(StructOrFunctionRNA *cont, const char *identifier, c PropertyRNA *RNA_def_string_file_path(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description); PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description); PropertyRNA *RNA_def_string_file_name(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description); -PropertyRNA *RNA_def_string_translate(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description); +PropertyRNA *RNA_def_string_py_translate(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description); PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description); PropertyRNA *RNA_def_enum_flag(StructOrFunctionRNA *cont, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index c76f9824c73..5f34fad09c6 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -110,10 +110,9 @@ typedef enum PropertySubType { PROP_FILEPATH = 1, PROP_DIRPATH = 2, PROP_FILENAME = 3, - PROP_BYTESTRING = 4, /* a string which should be represented as bytes - * in python, still NULL terminated though. */ - PROP_TRANSLATE = 5, /* a string which should be translated */ - PROP_PASSWORD = 6, /* a string which should not be displayed in UI */ + PROP_BYTESTRING = 4, /* a string which should be represented as bytes in python, still NULL terminated though. */ + /* 5 was used by "PROP_TRANSLATE" sub-type, which is now a flag. */ + PROP_PASSWORD = 6, /* a string which should not be displayed in UI */ /* numbers */ PROP_UNSIGNED = 13, @@ -144,6 +143,7 @@ typedef enum PropertySubType { } PropertySubType; /* Make sure enums are updated with thses */ +/* HIGHEST FLAG IN USE: 1 << 29 */ typedef enum PropertyFlag { /* editable means the property is editable in the user * interface, properties are editable by default except @@ -200,6 +200,11 @@ typedef enum PropertyFlag { */ PROP_ENUM_FLAG = (1 << 21), + /* A string which should be translated when converting from py string to RNA prop. + * Should only be used in some functions' properties (currently only "text" one of funcs in UI API). + */ + PROP_STRING_PY_TRANSLATE = (1 << 28), + /* need context for update function */ PROP_CONTEXT_UPDATE = (1 << 22), PROP_CONTEXT_PROPERTY_UPDATE = (1 << 22) | (1 << 27), diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 4b512b650a5..605fb18d5aa 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -2444,7 +2444,6 @@ static const char *rna_property_subtypename(PropertySubType type) case PROP_FILENAME: return "PROP_FILENAME"; case PROP_DIRPATH: return "PROP_DIRPATH"; case PROP_BYTESTRING: return "PROP_BYTESTRING"; - case PROP_TRANSLATE: return "PROP_TRANSLATE"; case PROP_UNSIGNED: return "PROP_UNSIGNED"; case PROP_PERCENTAGE: return "PROP_PERCENTAGE"; case PROP_FACTOR: return "PROP_FACTOR"; diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index b94d7eb691f..ac307139860 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -2534,13 +2534,14 @@ PropertyRNA *RNA_def_string_file_name(StructOrFunctionRNA *cont_, const char *id return prop; } -PropertyRNA *RNA_def_string_translate(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, - int maxlen, const char *ui_name, const char *ui_description) +PropertyRNA *RNA_def_string_py_translate(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, + int maxlen, const char *ui_name, const char *ui_description) { ContainerRNA *cont = cont_; PropertyRNA *prop; - prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_TRANSLATE); + prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_STRING_PY_TRANSLATE); if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen); if (default_value) RNA_def_property_string_default(prop, default_value); RNA_def_property_ui_text(prop, ui_name, ui_description); diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index f86f6010e27..b5b3897ed46 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -46,6 +46,9 @@ EnumPropertyItem property_type_items[] = { {0, NULL, 0, NULL, NULL} }; +/* XXX Keep in sync with bpy_props.c's property_subtype_xxx_items ??? + * Currently it is not... + */ EnumPropertyItem property_subtype_items[] = { {PROP_NONE, "NONE", 0, "None", ""}, @@ -53,7 +56,7 @@ EnumPropertyItem property_subtype_items[] = { {PROP_FILEPATH, "FILEPATH", 0, "File Path", ""}, {PROP_DIRPATH, "DIRPATH", 0, "Directory Path", ""}, {PROP_FILENAME, "FILENAME", 0, "File Name", ""}, - {PROP_TRANSLATE, "TRANSLATE", 0, "Translate", ""}, + {PROP_PASSWORD, "PASSWORD", 0, "Password", "A string that is displayed hidden ('********')"}, /* numbers */ {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""}, diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 00124a82dd1..fad93ea9054 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -813,9 +813,6 @@ static void rna_def_panel(BlenderRNA *brna) "class name is \"OBJECT_PT_hello\", and bl_idname is not set by the " "script, then bl_idname = \"OBJECT_PT_hello\""); - /* panel's label indeed doesn't need PROP_TRANSLATE flag: translation of label happens in runtime - * when drawing panel and having this flag set will make runtime switching of language much more tricky - * because label will be stored translated */ prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->label"); RNA_def_property_flag(prop, PROP_REGISTER); @@ -992,9 +989,6 @@ static void rna_def_menu(BlenderRNA *brna) "class name is \"OBJECT_MT_hello\", and bl_idname is not set by the " "script, then bl_idname = \"OBJECT_MT_hello\")"); - /* menu's label indeed doesn't need PROP_TRANSLATE flag: translation of label happens in runtime - * when drawing panel and having this flag set will make runtime switching of language much more tricky - * because label will be stored translated */ prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->label"); RNA_def_property_flag(prop, PROP_REGISTER); diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 366d0dc1fd9..93410383a58 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -196,7 +196,7 @@ static void api_ui_item_common(FunctionRNA *func) { PropertyRNA *prop; - RNA_def_string_translate(func, "text", "", 0, "", "Override automatic text of the item"); + RNA_def_string_py_translate(func, "text", "", 0, "", "Override automatic text of the item"); prop = RNA_def_property(func, "icon", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, icon_items); @@ -466,7 +466,7 @@ void RNA_api_ui_layout(StructRNA *srna) parm = RNA_def_string(func, "type_property", "", 0, "", "Identifier of property in data giving the type of the ID-blocks to use"); RNA_def_property_flag(parm, PROP_REQUIRED); - RNA_def_string_translate(func, "text", "", 0, "", "Custom label to display in UI"); + RNA_def_string_py_translate(func, "text", "", 0, "", "Custom label to display in UI"); func = RNA_def_function(srna, "template_path_builder", "uiTemplatePathBuilder"); parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property"); @@ -475,7 +475,7 @@ void RNA_api_ui_layout(StructRNA *srna) RNA_def_property_flag(parm, PROP_REQUIRED); parm = RNA_def_pointer(func, "root", "ID", "", "ID-block from which path is evaluated from"); RNA_def_property_flag(parm, PROP_REQUIRED | PROP_RNAPTR); - RNA_def_string_translate(func, "text", "", 0, "", "Custom label to display in UI"); + RNA_def_string_py_translate(func, "text", "", 0, "", "Custom label to display in UI"); func = RNA_def_function(srna, "template_modifier", "uiTemplateModifier"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index f416d3403ad..c0fb2a7238f 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1330,9 +1330,6 @@ static void rna_def_operator(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_REGISTER | PROP_NEVER_CLAMP); RNA_def_struct_name_property(srna, prop); - /* operator's label indeed doesn't need PROP_TRANSLATE flag: translation of label happens in runtime - * when drawing panel and having this flag set will make runtime switching of language much more tricky - * because label will be stored translated */ prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->name"); RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */ @@ -1397,9 +1394,6 @@ static void rna_def_macro_operator(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_REGISTER | PROP_NEVER_CLAMP); RNA_def_struct_name_property(srna, prop); - /* menu's label indeed doesn't need PROP_TRANSLATE flag: translation of label happens in runtime - * when drawing panel and having this flag set will make runtime switching of language much more tricky - * because label will be stored translated */ prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->name"); RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */ |