Small cleanup, all this options are now in the User Preferences, RNA.
authorDiego Borghetti <bdiego@gmail.com>
Tue, 31 Mar 2009 21:19:23 +0000 (21:19 +0000)
committerDiego Borghetti <bdiego@gmail.com>
Tue, 31 Mar 2009 21:19:23 +0000 (21:19 +0000)
source/blender/blenfont/intern/blf_internal_types.h
source/blender/blenfont/intern/blf_lang.c
source/blender/windowmanager/intern/wm_init_exit.c

index 9df04522b1fbfad57ff51b4284c027e4121313c4..49d8cc2e69275f37616603e7f4031316f1403350 100644 (file)
@@ -197,20 +197,6 @@ typedef struct DirBLF {
        char *path;
 } DirBLF;
 
-typedef struct LangBLF {
-       struct LangBLF *next;
-       struct LangBLF *prev;
-
-       char *line;
-       char *language;
-       char *code;
-       int id;
-} LangBLF;
-
-#define BLF_LANG_FIND_BY_LINE 0
-#define BLF_LANG_FIND_BY_LANGUAGE 1
-#define BLF_LANG_FIND_BY_CODE 2
-
 /* font->clip_mode */
 #define BLF_CLIP_DISABLE 0
 #define BLF_CLIP_OUT 1
index 730440a5ae5c8444613a758519d0ee9a88c6eec7..c871435ff0f8c7160a7344a4bcf6d4a633c407c7 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#ifdef WITH_FREETYPE2
-#include <ft2build.h>
+#ifdef INTERNATIONAL
 
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-#endif
+#include <locale.h>
+#include "libintl.h"
 
 #include "MEM_guardedalloc.h"
 
 
 #include "BIF_gl.h"
 
-#include "blf_internal_types.h"
-
-// XXX 2.50 Remove this later.
-#ifdef WITH_FREETYPE2
-#include "FTF_Api.h"
+#ifdef __APPLE__
+#include "BKE_utildefines.h"
 #endif
 
-static ListBase global_lang= { NULL, NULL };
-static int global_tot_lang= 0;
-static int global_err_lang= 0;
+#define DOMAIN_NAME "blender"
+#define SYSTEM_ENCODING_DEFAULT "UTF-8"
+#define FONT_SIZE_DEFAULT 12
 
-int BLF_lang_error(void)
-{
-       return(global_err_lang);
-}
+/* locale options. */
+char global_messagepath[1024];
+char global_language[32];
+char global_encoding_name[32];
 
-char *BLF_lang_pup(void)
-{
-       LangBLF *lme;
-       static char string[1024];
-       static char tmp[1024];
-
-       if(global_tot_lang == 0)
-               sprintf(string, "Choose Language: %%t|Language:  English %%x0");
-       else {
-               lme= global_lang.first;
-               sprintf(string, "Choose Language: %%t");
-               while (lme) {
-                       sprintf(tmp, "|Language:  %s %%x%d", lme->language, lme->id);
-                       strcat(string, tmp);
-                       lme= lme->next;
-               }
-       }
-
-       return(string);
-}
-
-LangBLF *blf_lang_find_by_id(short langid)
-{
-       LangBLF *p;
-
-       p= global_lang.first;
-       while (p) {
-               if (p->id == langid)
-                       return(p);
-               p= p->next;
-       }
-       return(NULL);
-}
 
-char *BLF_lang_find_code(short langid)
+void BLF_lang_init(void)
 {
-       LangBLF *p;
+#ifdef __APPLE__
+       char *bundlepath;
+#endif
 
-       p= blf_lang_find_by_id(langid);
-       if (p)
-               return(p->code);
-       return(NULL);
-}
+       strcpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT);
 
-void BLF_lang_set(int id)
-{
-#ifdef WITH_FREETYPE2
-       LangBLF *lme;
+       /* set messagepath directory */
 
-       // XXX 2.50 Remove this later, with ftfont
-       lme= blf_lang_find_by_id(id);
-       if(lme) FTF_SetLanguage(lme->code);
-       else FTF_SetLanguage("en_US");
+#ifndef LOCALEDIR
+#define LOCALEDIR "/usr/share/locale"
 #endif
-}
 
-static void blf_lang_split(char *line, LangBLF* lme)
-{
-       char *dpointchar= strchr(line, ':');
-
-       if (dpointchar) {
-               lme->code= BLI_strdup(dpointchar+1);
-               *(dpointchar)=0;
-               lme->language= BLI_strdup(line);
-       } else {
-               lme->code= NULL;
-               lme->language= NULL;
-               /* XXX 2.50 bad call error("Invalid language file");
-                * If we set this to NULL, the function blf_lang_new
-                * drop the line and increment the error lang value
-                * so the init code can call BLF_lang_error to get
-                * the number of invalid lines and show the error.
-                */
-       }
-}
+       strcpy(global_messagepath, ".blender/locale");
 
-LangBLF *blf_lang_find(char *s, int find_by)
-{
-       LangBLF *p;
+       if (!BLI_exist(global_messagepath)) { /* locale not in current dir */
+               BLI_make_file_string("/", global_messagepath, BLI_gethome(), ".blender/locale");
 
-       p= global_lang.first;
-       while (p) {
-               if (find_by == BLF_LANG_FIND_BY_LINE) {
-                       if (BLI_streq(s, p->line))
-                               return(p);
-               }
-               else if (find_by == BLF_LANG_FIND_BY_CODE) {
-                       if (BLI_streq(s, p->code))
-                               return(p);
-               }
-               else if (find_by == BLF_LANG_FIND_BY_LANGUAGE) {
-                       if (BLI_streq(s, p->language))
-                               return(p);
-               }
-               p= p->next;
-       }
-       return(NULL);
-}
+               if (!BLI_exist(global_messagepath)) { /* locale not in home dir */
+#ifdef WIN32 
+                       BLI_make_file_string("/", global_messagepath, BLI_gethome(), "/locale");
+                       if (!BLI_exist(global_messagepath)) {
+#endif
+#ifdef __APPLE__
+                       /* message catalogs are stored inside the application bundle */
+                       bundlepath= BLI_getbundle();
+                       strcpy(global_messagepath, bundlepath);
+                       strcat(global_messagepath, "/Contents/Resources/locale");
+                       if (!BLI_exist(global_messagepath)) { /* locale not in bundle (now that's odd..) */
+#endif
+                               strcpy(global_messagepath, LOCALEDIR);
 
-static void blf_lang_new(char *line)
-{
-       LangBLF *lme;
-
-       lme= blf_lang_find(line, BLF_LANG_FIND_BY_LINE);
-       if (!lme) {
-               lme= MEM_mallocN(sizeof(LangBLF), "blf_lang_new");
-               lme->next= NULL;
-               lme->prev= NULL;
-               lme->line = BLI_strdup(line);
-               blf_lang_split(line, lme);
-               
-               if (lme->code && lme->language) {
-                       lme->id = global_tot_lang;
-                       global_tot_lang++;
-                       BLI_addhead(&global_lang, lme);
-               }
-               else {
-                       global_err_lang++;
-                       MEM_freeN(lme->line);
-                       MEM_freeN(lme);
+                               if (!BLI_exist(global_messagepath)) { /* locale not in LOCALEDIR */
+                                       strcpy(global_messagepath, "message"); /* old compatibility as last */
+                               }
+#ifdef WIN32
+                       }
+#endif
+#ifdef __APPLE__
+                       }
+#endif
                }
        }
 }
 
-int BLF_lang_init(void) 
+void BLF_lang_set(char *str)
 {
-       char name[FILE_MAXDIR+FILE_MAXFILE];
-       LinkNode *l, *lines;
-       
-       /* .Blanguages, http://www.blender3d.org/cms/Installation_Policy.352.0.html*/
-#if defined (__APPLE__) || (WIN32)
-       BLI_make_file_string("/", name, BLI_gethome(), ".Blanguages");
+#if defined (_WIN32) || defined(__APPLE__)
+       char envstr[12];
+
+       sprintf(envstr, "LANG=%s", str);
+       envstr[strlen(envstr)]= '\0';
+#ifdef _WIN32
+       gettext_putenv(envstr);
 #else
-       BLI_make_file_string("/", name, BLI_gethome(), ".blender/.Blanguages");
+       putenv(envstr);
 #endif
+#else
+       char *locreturn= setlocale(LC_ALL, str);
+       if (locreturn == NULL) {
+               char *lang;
 
-       lines= BLI_read_file_as_lines(name);
+               lang= (char*)malloc(sizeof(char)*(strlen(str)+7));
 
-       if(lines == NULL) {
-               /* If not found in home, try current dir 
-                * (Resources folder of app bundle on OS X) */
-#if defined (__APPLE__)
-               char *bundlePath = BLI_getbundle();
-               strcpy(name, bundlePath);
-               strcat(name, "/Contents/Resources/.Blanguages");
-#else
-               /* Check the CWD. Takes care of the case where users
-                * unpack blender tarball; cd blender-dir; ./blender */
-               strcpy(name, ".blender/.Blanguages");
-#endif
-               lines= BLI_read_file_as_lines(name);
-
-               if(lines == NULL) {
-                       /* If not found in .blender, try current dir */
-                       strcpy(name, ".Blanguages");
-                       lines= BLI_read_file_as_lines(name);
-                       if(lines == NULL) {
-// XXX 2.50                            if(G.f & G_DEBUG)
-                               printf("File .Blanguages not found\n");
-                               return(0);
-                       }
-               }
-       }
+               lang[0]= '\0';
+               strcat(lang, str);
+               strcat(lang, ".UTF-8");
 
-       for (l= lines; l; l= l->next) {
-               char *line= l->link;
-                       
-               if (!BLI_streq(line, "")) {
-                       blf_lang_new(line);
+               locreturn= setlocale(LC_ALL, lang);
+               if (locreturn == NULL) {
+                       printf("could not change language to %s nor %s\n", str, lang);
                }
+
+               free(lang);
        }
 
-       BLI_free_file_lines(lines);
-       return(1);
+       setlocale(LC_NUMERIC, "C");
+#endif
+
+       bindtextdomain(DOMAIN_NAME, global_messagepath);
+       /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */
+       textdomain(DOMAIN_NAME);
+       strcpy(global_language, str);
 }
 
-void BLF_lang_exit(void)
+void BLF_lang_encoding(char *str)
 {
-       LangBLF *p;
-
-       while (global_lang.first) {
-               p= global_lang.first;
-               BLI_remlink(&global_lang, p);
-               MEM_freeN(p->line);
-               MEM_freeN(p->language);
-               MEM_freeN(p->code);
-               MEM_freeN(p);
-       }
+       strcpy(global_encoding_name, str);
+       /* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */
+}
+
+#else /* ! INTERNATIONAL */
+
+void BLF_lang_init(void)
+{
+       return;
 }
+
+void BLF_lang_encoding(char *str)
+{
+       return;
+}
+
+void BLF_lang_set(char *str)
+{
+       return;
+}
+
+#endif /* INTERNATIONAL */
index a0d170cc0f04ccbad0dd3e01297f37da5656c59f..990a862a1023c58c387499a61dc8afa9444b4a0f 100644 (file)
@@ -234,7 +234,6 @@ void WM_exit(bContext *C)
 //     fsmenu_free();
 
        BLF_exit();
-       BLF_lang_exit();
 
        RE_FreeAllRender();