switch language in User Preference's System page. with some known switch failure...
authorXiao Xiangquan <xiaoxiangquan@gmail.com>
Fri, 22 Jul 2011 14:14:28 +0000 (14:14 +0000)
committerXiao Xiangquan <xiaoxiangquan@gmail.com>
Fri, 22 Jul 2011 14:14:28 +0000 (14:14 +0000)
12 files changed:
po/update_mo.py
po/update_po.py
release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenfont/BLF_api.h
source/blender/blenfont/intern/blf.c
source/blender/blenfont/intern/blf_lang.c
source/blender/editors/interface/interface_style.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_init_exit.c

index 840d2ff0fea5cfd9b78af706c25570f84ef5e349..e361f70d96349ae742af6d3b6fdff20ab559cf52 100755 (executable)
@@ -29,7 +29,8 @@ LANGS = (
   "sr",
   "sv",
   "uk",
-  "zh_CN"
+  "zh_CN",
+  "zh_TW"
 )
 
 #-o %s.new.po
index 640b3a5f2d27e81237ecedc92df833023c72b7f6..c01c4bdc32d98387127c85888ef1f1a57322bfba 100755 (executable)
@@ -28,7 +28,8 @@ LANGS = (
   "sr",
   "sv",
   "uk",
-  "zh_CN"
+  "zh_CN",
+  "zh_TW"
 )
 #-o %s.new.po
 for lang in LANGS:
index 5f47ca7bc87fe5fa07c5db9b7680ca5b17eb1ee8..900d38d169373022a27f75dcea99753c083d47a8 100644 (file)
@@ -480,15 +480,14 @@ class USERPREF_PT_system(bpy.types.Panel):
         lamp = system.solid_lights[2]
         opengl_lamp_buttons(column, lamp)
 
-        column.separator()
-        column.separator()
         column.separator()
 
         column.label(text=_("Color Picker Type:"))
         column.row().prop(system, "color_picker_type", text="")
 
-        column.separator()
-        column.separator()
+        column.label(text=_("Select Language:"))
+        column.row().prop(system, "language", text="")
+
         column.separator()
 
         column.prop(system, "use_weight_color_range", text=_("Custom Weight Paint Range"))
index 88c29d43d25026dc08059e57b676cedba4b3e2a4..837ca814fbfa24ecf812b9cdc06f98bc1fa806f0 100644 (file)
@@ -218,8 +218,6 @@ void BLF_dir_free(char **dirs, int count);
 extern int blf_mono_font;
 extern int blf_mono_font_render; // dont mess drawing with render threads.
 
-// XXX, me, too
-extern int blf_unifont;
 #define _(msgid) BLF_gettext(msgid)
 #define N_(msgid) msgid
 
index 87d380c1b2a244d973ceba96119791ba4b042a37..c0e62b1c0c70340d72bcf2b58efbebc2ecc8c33d 100644 (file)
@@ -75,9 +75,6 @@ static int global_font_dpi= 72;
 int blf_mono_font= -1;
 int blf_mono_font_render= -1;
 
-// XXX, should these be made into global_font_'s too?
-int blf_unifont= -1;
-
 static FontBLF *BLF_get(int fontid)
 {
        if (fontid >= 0 && fontid < BLF_MAX_FONT)
index 6ea9a25928696e17e018aebae5fc727c7259a191..c40c98a3699dba500e40b990abe51f9bf6c1af8e 100644 (file)
@@ -41,6 +41,7 @@
 #include <locale.h>
 #include "libintl.h"
 
+#include "DNA_userdef_types.h"
 
 #include "DNA_listBase.h"
 #include "DNA_vec_types.h"
@@ -65,6 +66,40 @@ static char global_messagepath[1024];
 static char global_language[32];
 static char global_encoding_name[32];
 
+/* map from the rna_userdef.c:rna_def_userdef_system(BlenderRNA *brna):language_items */
+static char locale_default[] = "";
+static char locale_english[] = "en_US";
+static char locale_japanese[] = "ja_JP";
+static char locale_sim_chinese[] = "zh_CN";
+static char locale_tra_chinese[] = "zh_TW";
+
+static char *lang_to_locale[] = {
+               locale_default,
+               locale_english, /* us english is the default language of blender */
+               locale_japanese,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_sim_chinese,
+               locale_tra_chinese,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+               locale_default,
+};
 
 void BLF_lang_init(void)
 {
@@ -82,16 +117,16 @@ void BLF_lang_init(void)
 /* XXX WARNING!!! IN osx somehow the previous function call jumps in this one??? (ton, ppc) */
 void BLF_lang_set(const char *str)
 {
+       char *locreturn;
        if(str==NULL) {
-               return;
+               if( U.language==1 )
+                       return;
+               str = lang_to_locale[U.language];
        }
-       else {
-       
 #if defined (_WIN32) || defined(__APPLE__)
                BLI_setenv("LANG", str);
-               BLI_strncpy(global_language, BLI_getenv("LANG"), sizeof(global_language));
 #else
-               char *locreturn= setlocale(LC_ALL, str);
+               locreturn= setlocale(LC_ALL, str);
                if (locreturn == NULL) {
                        char *lang= BLI_sprintfN("%s.UTF-8", str);
 
@@ -102,13 +137,15 @@ void BLF_lang_set(const char *str)
 
                        MEM_freeN(lang);
                }
-               BLI_strncpy(global_language, locreturn, sizeof(global_language));
+
                setlocale(LC_NUMERIC, "C");
 #endif
                textdomain(DOMAIN_NAME);
                bindtextdomain(DOMAIN_NAME, global_messagepath);
                /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */
-       }
+               BLI_strncpy(global_language, str, sizeof(global_language));
+               
+
 }
 
 void BLF_lang_encoding(const char *str)
index 8aab414a803f109346afbfea87ec5e3749665d85..dec4afa7894fc61ca699a353d41ff9ad43750cf7 100644 (file)
@@ -76,7 +76,7 @@
 
 /* ********************************************** */
 
-static uiStyle *ui_style_new(ListBase *styles, const char *name, short fontid)
+static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id)
 {
        uiStyle *style= MEM_callocN(sizeof(uiStyle), "new style");
        
@@ -85,7 +85,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short fontid)
        
        style->panelzoom= 1.0; /* unused */
 
-       style->paneltitle.uifont_id= fontid;
+       style->paneltitle.uifont_id= uifont_id;
        style->paneltitle.points= 12;
        style->paneltitle.kerning= 1;
        style->paneltitle.shadow= 1;
@@ -94,7 +94,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short fontid)
        style->paneltitle.shadowalpha= 0.15f;
        style->paneltitle.shadowcolor= 1.0f;
        
-       style->grouplabel.uifont_id= fontid;
+       style->grouplabel.uifont_id= uifont_id;
        style->grouplabel.points= 12;
        style->grouplabel.kerning= 1;
        style->grouplabel.shadow= 3;
@@ -102,7 +102,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short fontid)
        style->grouplabel.shady= -1;
        style->grouplabel.shadowalpha= 0.25f;
        
-       style->widgetlabel.uifont_id= fontid;
+       style->widgetlabel.uifont_id= uifont_id;
        style->widgetlabel.points= 11;
        style->widgetlabel.kerning= 1;
        style->widgetlabel.shadow= 3;
@@ -111,7 +111,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short fontid)
        style->widgetlabel.shadowalpha= 0.15f;
        style->widgetlabel.shadowcolor= 1.0f;
        
-       style->widget.uifont_id= fontid;
+       style->widget.uifont_id= uifont_id;
        style->widget.points= 11;
        style->widget.kerning= 1;
        style->widget.shadowalpha= 0.25f;
@@ -254,8 +254,10 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str)
 
 uiStyle* UI_GetStyle(void)
 {
-       uiStyle *style = BLI_findstring( &U.uistyles, U.myuistyle, sizeof(style)*2 );
-       return (style != NULL) ? style : U.uifonts.first;
+       uiStyle *style = NULL;
+       /* offset is two struct uiStyle pointers */
+       /* style = BLI_findstring( &U.uistyles, "Unifont Style", sizeof(style)*2 ) */;
+       return (style != NULL) ? style : U.uistyles.first;
 }
 
 /* temporarily, does widget font */
@@ -319,7 +321,7 @@ void uiStyleInit(void)
        for(font= U.uifonts.first; font; font= font->next) {
                
                if(font->uifont_id==UIFONT_DEFAULT) {
-                       font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
+                       font->blf_id= BLF_load_mem_unique("default", (unsigned char *)get_datatoc_bunifont_ttf(), datatoc_bunifont_ttf_size);
                }               
                else {
                        font->blf_id= BLF_load(font->filename);
@@ -357,21 +359,6 @@ void uiStyleInit(void)
                blf_mono_font_render= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
 
        BLF_size(blf_mono_font_render, 12, 72);
-
-       /* offset is two struct uiStyle pointers */
-       if( BLI_findstring( &U.uistyles, "Unifont Style", sizeof(style)*2 )==NULL )
-       {
-               if( blf_unifont == -1 )
-                       blf_unifont= BLF_load_mem_unique("unifont", (unsigned char *)get_datatoc_bunifont_ttf(), datatoc_bunifont_ttf_size);
-               if( blf_unifont != -1 )
-               {
-                       BLF_size(blf_unifont, 12, 72);
-                       ui_style_new(&U.uistyles, "Unifont Style", blf_unifont );
-               }
-       }
-       /* init style setting */
-       if( U.myuistyle[0]==0 )
-               strcpy( U.myuistyle, "Unifont Style" );
 }
 
 void uiStyleFontSet(uiFontStyle *fs)
index 7fd58ffaeec6c163216ebb4853fa4c2e009aa3f0..ae57cf3f80b03ec5a80e4798803a76fc108b5b9e 100644 (file)
@@ -344,7 +344,6 @@ typedef struct UserDef {
        struct ListBase keymaps;
        struct ListBase addons;
        char keyconfigstr[64];
-       char myuistyle[24];
        
        short undosteps;
        short undomemory;
index f6ed440a10c4ef9a5f51d4f86708bba543751a24..5a29b4a82113f9c39d1c43fff223e0de49b24ff7 100644 (file)
@@ -2436,29 +2436,31 @@ static void rna_def_userdef_system(BlenderRNA *brna)
        
                /* hardcoded here, could become dynamic somehow */
        static EnumPropertyItem language_items[] = {
-               {0, "ENGLISH", 0, "English", ""},
-               {1, "JAPANESE", 0, "Japanese", ""},
-               {2, "DUTCH", 0, "Dutch", ""},
-               {3, "ITALIAN", 0, "Italian", ""},
-               {4, "GERMAN", 0, "German", ""},
-               {5, "FINNISH", 0, "Finnish", ""},
-               {6, "SWEDISH", 0, "Swedish", ""},
-               {7, "FRENCH", 0, "French", ""},
-               {8, "SPANISH", 0, "Spanish", ""},
-               {9, "CATALAN", 0, "Catalan", ""},
-               {10, "CZECH", 0, "Czech", ""},
-               {11, "BRAZILIAN_PORTUGUESE", 0, "Brazilian Portuguese", ""},
-               {12, "SIMPLIFIED_CHINESE", 0, "Simplified Chinese", ""},
-               {13, "RUSSIAN", 0, "Russian", ""},
-               {14, "CROATIAN", 0, "Croatian", ""},
-               {15, "SERBIAN", 0, "Serbian", ""},
-               {16, "UKRAINIAN", 0, "Ukrainian", ""},
-               {17, "POLISH", 0, "Polish", ""},
-               {18, "ROMANIAN", 0, "Romanian", ""},
-               {19, "ARABIC", 0, "Arabic", ""},
-               {20, "BULGARIAN", 0, "Bulgarian", ""},
-               {21, "GREEK", 0, "Greek", ""},
-               {22, "KOREAN", 0, "Korean", ""},
+               {0, "DEFAULT", 0, N_("Default"), ""},
+               {1, "ENGLISH", 0, "English (English)", ""},
+               {2, "JAPANESE", 0, "Japanese (日本語)", ""},
+               {3, "DUTCH", 0, "Dutch (Nederlandse taal)", ""},
+               {4, "ITALIAN", 0, "Italian (Italian)", ""},
+               {5, "GERMAN", 0, "German (German)", ""},
+               {6, "FINNISH", 0, "Finnish (Finnish)", ""},
+               {7, "SWEDISH", 0, "Swedish (Swedish)", ""},
+               {8, "FRENCH", 0, "French (French)", ""},
+               {9, "SPANISH", 0, "Spanish (Spanish)", ""},
+               {10, "CATALAN", 0, "Catalan (Catalan)", ""},
+               {11, "CZECH", 0, "Czech (Czech)", ""},
+               {12, "BRAZILIAN_PORTUGUESE", 0, "Brazilian Portuguese (Brazilian Portuguese)", ""},
+               {13, "SIMPLIFIED_CHINESE", 0, "Simplified Chinese (简体中文)", ""},
+               {14, "TRADITIONAL_CHINESE", 0, "Traditional Chinese (繁體中文)", ""},
+               {15, "RUSSIAN", 0, "Russian (Russian)", ""},
+               {16, "CROATIAN", 0, "Croatian (Croatian)", ""},
+               {17, "SERBIAN", 0, "Serbian (Serbian)", ""},
+               {18, "UKRAINIAN", 0, "Ukrainian (Ukrainian)", ""},
+               {19, "POLISH", 0, "Polish (Polish)", ""},
+               {20, "ROMANIAN", 0, "Romanian (Român)", ""},
+               {21, "ARABIC", 0, "Arabic (العربية)", ""},
+               {22, "BULGARIAN", 0, "Bulgarian (Bulgarian)", ""},
+               {23, "GREEK", 0, "Greek (Greek)", ""},
+               {24, "KOREAN", 0, "Korean (한국 언어)", ""},
                {0, NULL, 0, NULL, NULL}};
 
        srna= RNA_def_struct(brna, "UserPreferencesSystem", NULL);
index 67294a8eb53a6ed2b52514b8e1cec9ae7f5a50c7..98ffaac004e4c55ba96220ceb691a81411520987 100644 (file)
@@ -93,7 +93,8 @@ void          WM_window_open_temp     (struct bContext *C, struct rcti *position, int type);
 
                        /* files */
 int                    WM_read_homefile_exec(struct bContext *C, struct wmOperator *op);
-int                    WM_read_homefile        (struct bContext *C, struct ReportList *reports, short from_memory);
+int                    WM_read_homefile        (struct bContext *C, struct ReportList *reports, short from_memory, ListBase *wmbase);
+int                    WM_read_homefile_proc(struct bContext *C, ListBase *wmbase);
 int                    WM_write_homefile       (struct bContext *C, struct wmOperator *op);
 void           WM_read_file            (struct bContext *C, const char *filepath, struct ReportList *reports);
 int                    WM_write_file           (struct bContext *C, const char *target, int fileflags, struct ReportList *reports, int copy);
index df00c2b83cbc1cba57ef3d3e86825e065cff26dc..d69aa8c1c4c26bf530e32266dc28526419c33a3f 100644 (file)
@@ -444,9 +444,8 @@ void WM_read_file(bContext *C, const char *filepath, ReportList *reports)
 /* called on startup,  (context entirely filled with NULLs) */
 /* or called for 'New File' */
 /* op can be NULL */
-int WM_read_homefile(bContext *C, ReportList *reports, short from_memory)
+int WM_read_homefile(bContext *C, ReportList *reports, short from_memory, ListBase *wmbase)
 {
-       ListBase wmbase;
        char tstr[FILE_MAXDIR+FILE_MAXFILE];
        int success= 0;
        
@@ -468,7 +467,7 @@ int WM_read_homefile(bContext *C, ReportList *reports, short from_memory)
        G.fileflags &= ~G_FILE_NO_UI;
        
        /* put aside screens to match with persistant windows later */
-       wm_window_match_init(C, &wmbase); 
+       wm_window_match_init(C, wmbase);
        
        if (!from_memory && BLI_exists(tstr)) {
                success = (BKE_read_file(C, tstr, NULL) != BKE_READ_FILE_FAIL);
@@ -480,7 +479,7 @@ int WM_read_homefile(bContext *C, ReportList *reports, short from_memory)
        }
        if(success==0) {
                success = BKE_read_file_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL);
-               if (wmbase.first == NULL) wm_clear_default_size(C);
+               if (wmbase->first == NULL) wm_clear_default_size(C);
 
 #ifdef WITH_PYTHON_SECURITY /* not default */
                /* use alternative setting for security nuts
@@ -488,7 +487,12 @@ int WM_read_homefile(bContext *C, ReportList *reports, short from_memory)
                U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
 #endif
        }
-       
+       return TRUE;
+}
+
+/* split from the old WM_read_homefile */
+int WM_read_homefile_proc(bContext *C, ListBase *wmbase)
+{
        /* prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake. Screws up autosaves otherwise
         * can remove this eventually, only in a 2.53 and older, now its not written */
        G.fileflags &= ~G_FILE_RELATIVE_REMAP;
@@ -497,7 +501,7 @@ int WM_read_homefile(bContext *C, ReportList *reports, short from_memory)
        wm_init_userdef(C);
        
        /* match the read WM with current WM */
-       wm_window_match_do(C, &wmbase); 
+       wm_window_match_do(C, wmbase);
        WM_check(C); /* opens window(s), checks keymaps */
 
        G.main->name[0]= '\0';
@@ -542,8 +546,9 @@ int WM_read_homefile(bContext *C, ReportList *reports, short from_memory)
 
 int WM_read_homefile_exec(bContext *C, wmOperator *op)
 {
+       ListBase wmbase;
        int from_memory= strcmp(op->type->idname, "WM_OT_read_factory_settings") == 0;
-       return WM_read_homefile(C, op->reports, from_memory) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+       return WM_read_homefile(C, op->reports, from_memory, &wmbase) && WM_read_homefile_proc(C, &wmbase) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 }
 
 void WM_read_history(void)
index dfa3a0f80f176ed7aba26673dcc3ead807c8439b..26d1b4454bd43e838915067a17cb37bad434ce90 100644 (file)
@@ -122,6 +122,7 @@ int wm_start_with_console = 0;
 /* only called once, for startup */
 void WM_init(bContext *C, int argc, const char **argv)
 {
+       ListBase wmbase;
        if (!G.background) {
                wm_ghost_init(C);       /* note: it assigns C to ghost! */
                wm_init_cursor_data();
@@ -131,24 +132,24 @@ void WM_init(bContext *C, int argc, const char **argv)
        BLF_lang_init();
        // use default settings
        BLF_lang_encoding("");
-       BLF_lang_set("");
+       /* get the default database, plus a wm */
+       WM_read_homefile(C, NULL, G.factory_startup, &wmbase);
+       BLF_lang_set(NULL);
 
        RNA_types_init_gettext();
 
        wm_operatortype_init();
-       
+
        set_free_windowmanager_cb(wm_close_and_free);   /* library.c */
        set_blender_test_break_cb(wm_window_testbreak); /* blender.c */
        DAG_editors_update_cb(ED_render_id_flush_update); /* depsgraph.c */
-       
+
        ED_spacetypes_init();   /* editors/space_api/spacetype.c */
-       
-       ED_file_init();                 /* for fsmenu */
-       ED_init_node_butfuncs();        
 
-       /* get the default database, plus a wm */
-       WM_read_homefile(C, NULL, G.factory_startup);
+       ED_file_init();                 /* for fsmenu */
+       ED_init_node_butfuncs();
 
+       WM_read_homefile_proc(C, &wmbase);
        /* note: there is a bug where python needs initializing before loading the
         * startup.blend because it may contain PyDrivers. It also needs to be after
         * initializing space types and other internal data.