4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation.
25 * ***** END GPL LICENSE BLOCK *****
37 #include "MEM_guardedalloc.h"
39 #include "DNA_listBase.h"
40 #include "DNA_vec_types.h"
42 #include "BKE_utildefines.h"
44 #include "BLI_blenlib.h"
45 #include "BLI_linklist.h" /* linknode */
46 #include "BLI_string.h"
51 #include "BKE_utildefines.h"
54 #define DOMAIN_NAME "blender"
55 #define SYSTEM_ENCODING_DEFAULT "UTF-8"
56 #define FONT_SIZE_DEFAULT 12
59 char global_messagepath[1024];
60 char global_language[32];
61 char global_encoding_name[32];
64 void BLF_lang_init(void)
70 strcpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT);
72 /* set messagepath directory */
75 #define LOCALEDIR "/usr/share/locale"
78 strcpy(global_messagepath, ".blender/locale");
80 if (!BLI_exist(global_messagepath)) { /* locale not in current dir */
81 BLI_make_file_string("/", global_messagepath, BLI_gethome(), ".blender/locale");
83 if (!BLI_exist(global_messagepath)) { /* locale not in home dir */
85 BLI_make_file_string("/", global_messagepath, BLI_gethome(), "/locale");
86 if (!BLI_exist(global_messagepath)) {
89 /* message catalogs are stored inside the application bundle */
90 bundlepath= BLI_getbundle();
91 strcpy(global_messagepath, bundlepath);
92 strcat(global_messagepath, "/Contents/Resources/locale");
93 if (!BLI_exist(global_messagepath)) { /* locale not in bundle (now that's odd..) */
95 strcpy(global_messagepath, LOCALEDIR);
97 if (!BLI_exist(global_messagepath)) { /* locale not in LOCALEDIR */
98 strcpy(global_messagepath, "message"); /* old compatibility as last */
110 void BLF_lang_set(char *str)
112 #if defined (_WIN32) || defined(__APPLE__)
115 sprintf(envstr, "LANG=%s", str);
116 envstr[strlen(envstr)]= '\0';
118 gettext_putenv(envstr);
123 char *locreturn= setlocale(LC_ALL, str);
124 if (locreturn == NULL) {
127 lang= (char*)malloc(sizeof(char)*(strlen(str)+7));
131 strcat(lang, ".UTF-8");
133 locreturn= setlocale(LC_ALL, lang);
134 if (locreturn == NULL) {
135 printf("could not change language to %s nor %s\n", str, lang);
141 setlocale(LC_NUMERIC, "C");
144 bindtextdomain(DOMAIN_NAME, global_messagepath);
145 /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */
146 textdomain(DOMAIN_NAME);
147 strcpy(global_language, str);
150 void BLF_lang_encoding(char *str)
152 strcpy(global_encoding_name, str);
153 /* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */
156 #else /* ! INTERNATIONAL */
158 void BLF_lang_init(void)
163 void BLF_lang_encoding(char *str)
168 void BLF_lang_set(char *str)
173 #endif /* INTERNATIONAL */