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 *****
32 #include "MEM_guardedalloc.h"
34 #include "DNA_listBase.h"
36 #include "BKE_utildefines.h"
38 #include "BLI_blenlib.h"
39 #include "BLI_linklist.h" /* linknode */
40 #include "BLI_string.h"
42 #include "blf_internal_types.h"
44 // XXX 2.50 Remove this later.
49 static ListBase global_lang= { NULL, NULL };
50 static int global_tot_lang= 0;
51 static int global_err_lang= 0;
53 int BLF_lang_error(void)
55 return(global_err_lang);
58 char *BLF_lang_pup(void)
61 static char string[1024];
62 static char tmp[1024];
64 if(global_tot_lang == 0)
65 sprintf(string, "Choose Language: %%t|Language: English %%x0");
67 lme= global_lang.first;
68 sprintf(string, "Choose Language: %%t");
70 sprintf(tmp, "|Language: %s %%x%d", lme->language, lme->id);
79 LangBLF *blf_lang_find_by_id(short langid)
92 char *BLF_lang_find_code(short langid)
96 p= blf_lang_find_by_id(langid);
102 void BLF_lang_set(int id)
104 #ifdef WITH_FREETYPE2
107 // XXX 2.50 Remove this later, with ftfont
108 lme= blf_lang_find_by_id(id);
109 if(lme) FTF_SetLanguage(lme->code);
110 else FTF_SetLanguage("en_US");
114 static void blf_lang_split(char *line, LangBLF* lme)
116 char *dpointchar= strchr(line, ':');
119 lme->code= BLI_strdup(dpointchar+1);
121 lme->language= BLI_strdup(line);
125 /* XXX 2.50 bad call error("Invalid language file");
126 * If we set this to NULL, the function blf_lang_new
127 * drop the line and increment the error lang value
128 * so the init code can call BLF_lang_error to get
129 * the number of invalid lines and show the error.
134 LangBLF *blf_lang_find(char *s, int find_by)
138 p= global_lang.first;
140 if (find_by == BLF_LANG_FIND_BY_LINE) {
141 if (BLI_streq(s, p->line))
144 else if (find_by == BLF_LANG_FIND_BY_CODE) {
145 if (BLI_streq(s, p->code))
148 else if (find_by == BLF_LANG_FIND_BY_LANGUAGE) {
149 if (BLI_streq(s, p->language))
157 static void blf_lang_new(char *line)
161 lme= blf_lang_find(line, BLF_LANG_FIND_BY_LINE);
163 lme= MEM_mallocN(sizeof(LangBLF), "blf_lang_new");
166 lme->line = BLI_strdup(line);
167 blf_lang_split(line, lme);
169 if (lme->code && lme->language) {
170 lme->id = global_tot_lang;
172 BLI_addhead(&global_lang, lme);
176 MEM_freeN(lme->line);
182 int BLF_lang_init(void)
184 char name[FILE_MAXDIR+FILE_MAXFILE];
187 /* .Blanguages, http://www.blender3d.org/cms/Installation_Policy.352.0.html*/
188 #if defined (__APPLE__) || (WIN32)
189 BLI_make_file_string("/", name, BLI_gethome(), ".Blanguages");
191 BLI_make_file_string("/", name, BLI_gethome(), ".blender/.Blanguages");
194 lines= BLI_read_file_as_lines(name);
197 /* If not found in home, try current dir
198 * (Resources folder of app bundle on OS X) */
199 #if defined (__APPLE__)
200 char *bundlePath = BLI_getbundle();
201 strcpy(name, bundlePath);
202 strcat(name, "/Contents/Resources/.Blanguages");
204 /* Check the CWD. Takes care of the case where users
205 * unpack blender tarball; cd blender-dir; ./blender */
206 strcpy(name, ".blender/.Blanguages");
208 lines= BLI_read_file_as_lines(name);
211 /* If not found in .blender, try current dir */
212 strcpy(name, ".Blanguages");
213 lines= BLI_read_file_as_lines(name);
215 // XXX 2.50 if(G.f & G_DEBUG)
216 printf("File .Blanguages not found\n");
222 for (l= lines; l; l= l->next) {
225 if (!BLI_streq(line, "")) {
230 BLI_free_file_lines(lines);
234 void BLF_lang_exit(void)
238 while (global_lang.first) {
239 p= global_lang.first;
240 BLI_remlink(&global_lang, p);
242 MEM_freeN(p->language);