py/rna string subtypes for strings which should be automatically translated:
authorCampbell Barton <ideasman42@gmail.com>
Wed, 21 Sep 2011 13:53:35 +0000 (13:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 21 Sep 2011 13:53:35 +0000 (13:53 +0000)
  layout.prop("blah", text="Translate Me!")

source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_define.c
source/blender/makesrna/intern/rna_rna.c
source/blender/makesrna/intern/rna_ui_api.c
source/blender/python/intern/CMakeLists.txt
source/blender/python/intern/bpy_props.c
source/blender/python/intern/bpy_rna.c

index 4a18518dde9f6a4192a6d9968aca4300a26aa272..8e8a2133b8955b1478d9cc17c7f15092b08c100f 100644 (file)
@@ -110,6 +110,7 @@ typedef enum PropertySubType {
        PROP_FILEPATH = 1,
        PROP_DIRPATH = 2,
        PROP_FILENAME = 3,
+       PROP_TRANSLATE = 4, /* a string which should be translated */
 
        /* numbers */
        PROP_UNSIGNED = 13,
index 23100fa8bd7a303345a29ca95c10d7fc953524f5..80352d3f03ee1bb74f5e26f86de553a90d97124d 100644 (file)
@@ -1815,6 +1815,7 @@ static const char *rna_property_subtypename(PropertySubType type)
                case PROP_FILEPATH: return "PROP_FILEPATH";
                case PROP_FILENAME: return "PROP_FILENAME";
                case PROP_DIRPATH: return "PROP_DIRPATH";
+               case PROP_TRANSLATE: return "PROP_TRANSLATE";
                case PROP_UNSIGNED: return "PROP_UNSIGNED";
                case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
                case PROP_FACTOR: return "PROP_FACTOR";
index 758ddc9ac6a14b8c1dca7ec88ae3b785c412122c..8af65b97ffc8c594bf699f0a354e035a677fc830 100644 (file)
@@ -2240,6 +2240,20 @@ 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)
+{
+       ContainerRNA *cont= cont_;
+       PropertyRNA *prop;
+
+       prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_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);
+
+       return prop;
+}
+
 PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, 
        const char *ui_name, const char *ui_description)
 {
index 7f85a2fa1d711a73b2749b09436ed6a6400e0da8..95c6b066510d691d79eaeca76a564a6055099465 100644 (file)
@@ -53,6 +53,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", ""},
 
        /* numbers */
        {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""},
index 84568d914af856e0b51d30f6d784604de3feba20..816a7ba9cd43963945fb0c3d6b00f47288ac7c3e 100644 (file)
@@ -84,7 +84,7 @@ static void api_ui_item_common(FunctionRNA *func)
 {
        PropertyRNA *prop;
 
-       RNA_def_string(func, "text", "", 0, "", "Override automatic text of the item");
+       prop= RNA_def_string_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);
@@ -309,7 +309,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(func, "text", "", 0, "", "Custom label to display in UI");
+       RNA_def_string_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");
@@ -318,7 +318,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(func, "text", "", 0, "", "Custom label to display in UI");
+       RNA_def_string_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);
index acdee5328e7907db8ac8d8e717613b09ae44db65..e628ea10e9c8c7a0dafb86e8fdaba324fa562c8b 100644 (file)
@@ -95,4 +95,8 @@ if(WITH_AUDASPACE)
        add_definitions(-DWITH_AUDASPACE)
 endif()
 
+if(WITH_INTERNATIONAL)
+        add_definitions(-DINTERNATIONAL)
+endif()
+
 blender_add_lib(bf_python "${SRC}" "${INC}" "${INC_SYS}")
index 5da142aeea704dc4fe533a0919205e460ac6cc70..a3d5bc99ad84f495127330ad80de34c230fb7f35 100644 (file)
@@ -72,6 +72,7 @@ static EnumPropertyItem property_subtype_string_items[]= {
        {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
        {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""},
        {PROP_FILENAME, "FILENAME", 0, "Filename", ""},
+    {PROP_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
 
        {PROP_NONE, "NONE", 0, "None", ""},
        {0, NULL, 0, NULL, NULL}};
index a63cee4e505ac3681d056ac38473318f898657b1..013eac7fd58c8552d629790159fccc40d541f065 100644 (file)
 #include "../generic/IDProp.h" /* for IDprop lookups */
 #include "../generic/py_capi_utils.h"
 
+#ifdef INTERNATIONAL
+#include "UI_interface.h" /* bad level call into editors */
+#endif
+
 #define USE_PEDANTIC_WRITE
 #define USE_MATHUTILS
 #define USE_STRING_COERCE
@@ -1519,6 +1523,12 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
                        }
                        else {
                                param= _PyUnicode_AsString(value);
+#ifdef INTERNATIONAL
+                               if(subtype == PROP_TRANSLATE) {
+                                       param= UI_translate_do_iface(param);
+                               }
+#endif // INTERNATIONAL
+
                        }
 #else // USE_STRING_COERCE
                        param= _PyUnicode_AsString(value);