store locales, .Blanguage, and .bfont.ttf inside of Resources folder of
[blender.git] / source / blender / src / language.c
index 9bd92cc67746a0532e781a61d26e904f2553e1c4..416b87f8a289fff2d7d4824ff56b986a95a80492 100644 (file)
@@ -128,7 +128,7 @@ void lang_setlanguage(void) {
        LANGMenuEntry *lme;
 
        lme = find_language(U.language);
-       if(lme) FTF_SetLanguage(lme->code);
+       if(lme) FTF_SetLanguage(lme->code);
        else FTF_SetLanguage("en_US");
 }
 
@@ -137,11 +137,11 @@ void set_interface_font(char *str) {
        char di[FILE_MAXDIR];
 
        if(FTF_SetFont(str, U.fontsize)) {
-
                lang_setlanguage();
-
                BLI_split_dirfile(str, di, U.fontname);
 
+               if(strlen(di) < FILE_MAXDIR) strcpy(U.fontdir, di);
+
                G.ui_international = TRUE;
        } else {
                sprintf(U.fontname, "Invalid font.");
@@ -151,35 +151,53 @@ void set_interface_font(char *str) {
 }
 
 
-void set_ML_interface_font(void) {
+void start_interface_font(void) {
        char tstr[FILE_MAXDIR+FILE_MAXFILE];
        int result = 0;
-
-       /* dirty hack to find out if we have saved language/font settings,
-          if not, try default font --phase */
+#ifdef __APPLE__
+       char *bundlepath;
+#endif
+       
+       /* hack to find out if we have saved language/font settings.
+          if not, set defaults and try .bfont.tff --phase */
        
-       if(U.fontsize != 0) {
+       if(U.fontsize != 0) { // we have saved user settings
+               // try load the font from the font dir
                BLI_make_file_string("/", tstr, U.fontdir, U.fontname);
-
                result = FTF_SetFont(tstr, U.fontsize);
+
+               if(!result) {   // else try loading font from current dir
+                       result = FTF_SetFont(U.fontname, U.fontsize);
+               }
        } else {
                U.language= 0;
-               U.fontsize= 12;
+               U.fontsize= 11;
                U.encoding= 0;
-               sprintf(U.fontname, ".bfont.ttf\0");
+
+#ifdef __APPLE__
+               bundlepath = BLI_getbundle();
+               strcpy(tstr, bundlepath);
+               strcat(tstr, "/Contents/Resources/");
+               strcat(tstr, ".bfont.ttf");
+               result = FTF_SetFont(tstr, U.fontsize);
+
+               sprintf(U.fontname, ".blender/.bfont.ttf\0");
+#else
+               sprintf(U.fontname, ".blender/.bfont.ttf\0");
 
                result = FTF_SetFont(U.fontname, U.fontsize);
+#endif
        }
 
-       if(!result) result = FTF_SetFont(".bfont.ttf", U.fontsize);
-//     printf(" res = %d\n ", result);
        if(result) {
                lang_setlanguage();
 
                G.ui_international = TRUE;
        } else {
-               printf("no way ftf\n");
+               printf("no font found for international support\n");
                G.ui_international = FALSE;
+               U.transopts &= ~TR_ALL;
+               U.fontsize = 0;
        }
 
        allqueue(REDRAWALL, 0);
@@ -243,22 +261,35 @@ void puplang_insert_entry(char *line)
 }
 
 
-int readMultiLingualFiles(void) {
+int read_languagefile(void) {
        char name[FILE_MAXDIR+FILE_MAXFILE];
        LinkNode *l, *lines;
-
+       
        /* .Blanguages */
-
        BLI_make_file_string("/", name, BLI_gethome(), ".Blanguages");
+
        lines= BLI_read_file_as_lines(name);
 
        if(lines == NULL) {
-               /* If not found in home, try current dir */
-               strcpy(name, ".Blanguages");
+               /* If not found in home, try current dir 
+                * (Resources folder of app bundle on OS X) */
+#ifdef __APPLE__
+               char *bundlePath = BLI_getbundle();
+               strcpy(name, bundlePath);
+               strcat(name, "/Contents/Resources/.Blanguages");
+#else
+               strcpy(name, ".blender/.Blanguages");
+#endif
                lines= BLI_read_file_as_lines(name);
+
                if(lines == NULL) {
-                       error("File \".Blanguages\" not found");
-                       return 0;
+                       /* If not found in .blender, try current dir */
+                       strcpy(name, ".Blanguages");
+                       lines= BLI_read_file_as_lines(name);
+                       if(lines == NULL) {
+                               error("File \".Blanguages\" not found");
+                               return 0;
+                       }
                }
        }
 
@@ -276,7 +307,7 @@ int readMultiLingualFiles(void) {
 }
 
 
-void languagesmenu_free(void)
+void free_languagemenu(void)
 {
        LANGMenuEntry *lme= langmenu;