|
Blender
V2.59
|
00001 /* 00002 * $Id: blf_lang.c 35248 2011-02-27 20:42:42Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2008 Blender Foundation. 00021 * All rights reserved. 00022 * 00023 * Contributor(s): Blender Foundation. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include <stdio.h> 00034 #include <stdlib.h> 00035 #include <string.h> 00036 00037 #include "BLF_api.h" 00038 00039 #ifdef INTERNATIONAL 00040 00041 #include <locale.h> 00042 #include "libintl.h" 00043 00044 00045 #include "DNA_listBase.h" 00046 #include "DNA_vec_types.h" 00047 00048 #include "MEM_guardedalloc.h" 00049 00050 #include "BLI_linklist.h" /* linknode */ 00051 #include "BLI_string.h" 00052 #include "BLI_path_util.h" 00053 00054 00055 #ifdef __APPLE__ 00056 00057 #endif 00058 00059 #define DOMAIN_NAME "blender" 00060 #define SYSTEM_ENCODING_DEFAULT "UTF-8" 00061 #define FONT_SIZE_DEFAULT 12 00062 00063 /* locale options. */ 00064 static char global_messagepath[1024]; 00065 static char global_language[32]; 00066 static char global_encoding_name[32]; 00067 00068 00069 void BLF_lang_init(void) 00070 { 00071 char *messagepath= BLI_get_folder(BLENDER_DATAFILES, "locale"); 00072 00073 BLI_strncpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT, sizeof(global_encoding_name)); 00074 00075 if (messagepath) 00076 BLI_strncpy(global_messagepath, messagepath, sizeof(global_messagepath)); 00077 else 00078 global_messagepath[0]= '\0'; 00079 00080 } 00081 00082 /* XXX WARNING!!! IN osx somehow the previous function call jumps in this one??? (ton, ppc) */ 00083 void BLF_lang_set(const char *str) 00084 { 00085 if(str==NULL) { 00086 return; 00087 } 00088 else { 00089 00090 #if defined (_WIN32) || defined(__APPLE__) 00091 BLI_setenv("LANG", str); 00092 #else 00093 char *locreturn= setlocale(LC_ALL, str); 00094 if (locreturn == NULL) { 00095 char *lang= BLI_sprintfN("%s.UTF-8", str); 00096 00097 locreturn= setlocale(LC_ALL, lang); 00098 if (locreturn == NULL) { 00099 printf("could not change language to %s nor %s\n", str, lang); 00100 } 00101 00102 MEM_freeN(lang); 00103 } 00104 00105 setlocale(LC_NUMERIC, "C"); 00106 #endif 00107 textdomain(DOMAIN_NAME); 00108 bindtextdomain(DOMAIN_NAME, global_messagepath); 00109 /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */ 00110 BLI_strncpy(global_language, str, sizeof(global_language)); 00111 00112 } 00113 } 00114 00115 void BLF_lang_encoding(const char *str) 00116 { 00117 BLI_strncpy(global_encoding_name, str, sizeof(global_encoding_name)); 00118 /* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */ 00119 } 00120 00121 #else /* ! INTERNATIONAL */ 00122 00123 void BLF_lang_init(void) 00124 { 00125 return; 00126 } 00127 00128 void BLF_lang_encoding(const char *str) 00129 { 00130 (void)str; 00131 return; 00132 } 00133 00134 void BLF_lang_set(const char *str) 00135 { 00136 (void)str; 00137 return; 00138 } 00139 00140 #endif /* INTERNATIONAL */