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 *****
35 #include FT_FREETYPE_H
39 #include "MEM_guardedalloc.h"
41 #include "DNA_listBase.h"
42 #include "DNA_vec_types.h"
44 #include "BKE_utildefines.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_linklist.h" /* linknode */
48 #include "BLI_string.h"
52 #include "blf_internal_types.h"
54 // XXX 2.50 Remove this later.
59 static ListBase global_lang= { NULL, NULL };
60 static int global_tot_lang= 0;
61 static int global_err_lang= 0;
63 int BLF_lang_error(void)
65 return(global_err_lang);
68 char *BLF_lang_pup(void)
71 static char string[1024];
72 static char tmp[1024];
74 if(global_tot_lang == 0)
75 sprintf(string, "Choose Language: %%t|Language: English %%x0");
77 lme= global_lang.first;
78 sprintf(string, "Choose Language: %%t");
80 sprintf(tmp, "|Language: %s %%x%d", lme->language, lme->id);
89 LangBLF *blf_lang_find_by_id(short langid)
102 char *BLF_lang_find_code(short langid)
106 p= blf_lang_find_by_id(langid);
112 void BLF_lang_set(int id)
114 #ifdef WITH_FREETYPE2
117 // XXX 2.50 Remove this later, with ftfont
118 lme= blf_lang_find_by_id(id);
119 if(lme) FTF_SetLanguage(lme->code);
120 else FTF_SetLanguage("en_US");
124 static void blf_lang_split(char *line, LangBLF* lme)
126 char *dpointchar= strchr(line, ':');
129 lme->code= BLI_strdup(dpointchar+1);
131 lme->language= BLI_strdup(line);
135 /* XXX 2.50 bad call error("Invalid language file");
136 * If we set this to NULL, the function blf_lang_new
137 * drop the line and increment the error lang value
138 * so the init code can call BLF_lang_error to get
139 * the number of invalid lines and show the error.
144 LangBLF *blf_lang_find(char *s, int find_by)
148 p= global_lang.first;
150 if (find_by == BLF_LANG_FIND_BY_LINE) {
151 if (BLI_streq(s, p->line))
154 else if (find_by == BLF_LANG_FIND_BY_CODE) {
155 if (BLI_streq(s, p->code))
158 else if (find_by == BLF_LANG_FIND_BY_LANGUAGE) {
159 if (BLI_streq(s, p->language))
167 static void blf_lang_new(char *line)
171 lme= blf_lang_find(line, BLF_LANG_FIND_BY_LINE);
173 lme= MEM_mallocN(sizeof(LangBLF), "blf_lang_new");
176 lme->line = BLI_strdup(line);
177 blf_lang_split(line, lme);
179 if (lme->code && lme->language) {
180 lme->id = global_tot_lang;
182 BLI_addhead(&global_lang, lme);
186 MEM_freeN(lme->line);
192 int BLF_lang_init(void)
194 char name[FILE_MAXDIR+FILE_MAXFILE];
197 /* .Blanguages, http://www.blender3d.org/cms/Installation_Policy.352.0.html*/
198 #if defined (__APPLE__) || (WIN32)
199 BLI_make_file_string("/", name, BLI_gethome(), ".Blanguages");
201 BLI_make_file_string("/", name, BLI_gethome(), ".blender/.Blanguages");
204 lines= BLI_read_file_as_lines(name);
207 /* If not found in home, try current dir
208 * (Resources folder of app bundle on OS X) */
209 #if defined (__APPLE__)
210 char *bundlePath = BLI_getbundle();
211 strcpy(name, bundlePath);
212 strcat(name, "/Contents/Resources/.Blanguages");
214 /* Check the CWD. Takes care of the case where users
215 * unpack blender tarball; cd blender-dir; ./blender */
216 strcpy(name, ".blender/.Blanguages");
218 lines= BLI_read_file_as_lines(name);
221 /* If not found in .blender, try current dir */
222 strcpy(name, ".Blanguages");
223 lines= BLI_read_file_as_lines(name);
225 // XXX 2.50 if(G.f & G_DEBUG)
226 printf("File .Blanguages not found\n");
232 for (l= lines; l; l= l->next) {
235 if (!BLI_streq(line, "")) {
240 BLI_free_file_lines(lines);
244 void BLF_lang_exit(void)
248 while (global_lang.first) {
249 p= global_lang.first;
250 BLI_remlink(&global_lang, p);
252 MEM_freeN(p->language);