2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-01-29 05:19:27 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-01-29 05:19:27 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:42:42 +00:00
|
|
|
/** \file blender/blenfont/intern/blf_lang.c
|
|
|
|
|
* \ingroup blf
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2009-01-29 05:19:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
#include "BLF_api.h"
|
|
|
|
|
|
2011-11-14 16:05:44 +00:00
|
|
|
#include "BLF_translation.h" /* own include */
|
|
|
|
|
|
2011-09-26 10:35:47 +00:00
|
|
|
#ifdef WITH_INTERNATIONAL
|
2009-02-17 16:56:29 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
#include <locale.h>
|
2011-09-15 13:20:18 +00:00
|
|
|
|
|
|
|
|
#if defined (_WIN32)
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-06-24 03:30:50 +00:00
|
|
|
#include "libintl.h"
|
2009-02-17 16:56:29 +00:00
|
|
|
|
2011-07-22 14:14:28 +00:00
|
|
|
#include "DNA_userdef_types.h"
|
2009-01-29 05:19:27 +00:00
|
|
|
|
|
|
|
|
#include "DNA_listBase.h"
|
2009-02-17 16:56:29 +00:00
|
|
|
#include "DNA_vec_types.h"
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2011-02-13 03:21:27 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2009-01-29 05:19:27 +00:00
|
|
|
#include "BLI_linklist.h" /* linknode */
|
|
|
|
|
#include "BLI_string.h"
|
2011-10-21 11:33:18 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-02-13 03:21:27 +00:00
|
|
|
#include "BLI_path_util.h"
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
#define SYSTEM_ENCODING_DEFAULT "UTF-8"
|
|
|
|
|
#define FONT_SIZE_DEFAULT 12
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
/* locale options. */
|
2011-02-13 10:52:18 +00:00
|
|
|
static char global_messagepath[1024];
|
|
|
|
|
static char global_language[32];
|
|
|
|
|
static char global_encoding_name[32];
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2011-07-22 14:14:28 +00:00
|
|
|
/* map from the rna_userdef.c:rna_def_userdef_system(BlenderRNA *brna):language_items */
|
2011-09-15 13:02:37 +00:00
|
|
|
static const char *locales[] = {
|
2011-09-06 05:18:02 +00:00
|
|
|
"", "",
|
|
|
|
|
"english", "en_US",
|
|
|
|
|
"japanese", "ja_JP",
|
|
|
|
|
"dutch", "nl_NL",
|
|
|
|
|
"italian", "it_IT",
|
|
|
|
|
"german", "de_DE",
|
|
|
|
|
"finnish", "fi_FI",
|
|
|
|
|
"swedish", "sv_SE",
|
|
|
|
|
"french", "fr_FR",
|
2011-11-18 09:16:29 +00:00
|
|
|
"spanish", "es",
|
2011-09-06 05:18:02 +00:00
|
|
|
"catalan", "ca_AD",
|
|
|
|
|
"czech", "cs_CZ",
|
|
|
|
|
"ptb", "pt_BR",
|
2011-12-26 14:52:36 +00:00
|
|
|
#if defined (_WIN32) && !defined(FREE_WINDOWS)
|
2011-09-21 15:07:19 +00:00
|
|
|
"Chinese (Simplified)_China.1252", "zh_CN",
|
|
|
|
|
"Chinese (Traditional)_China.1252", "zh_TW",
|
2011-12-26 14:52:36 +00:00
|
|
|
#else
|
|
|
|
|
"chs", "zh_CN",
|
|
|
|
|
"cht", "zh_TW",
|
|
|
|
|
#endif
|
2011-09-06 05:18:02 +00:00
|
|
|
"russian", "ru_RU",
|
|
|
|
|
"croatian", "hr_HR",
|
2011-12-23 13:36:07 +00:00
|
|
|
"serbian", "sr_RS",
|
2011-09-06 05:18:02 +00:00
|
|
|
"ukrainian", "uk_UA",
|
|
|
|
|
"polish", "pl_PL",
|
|
|
|
|
"romanian", "ro_RO",
|
|
|
|
|
"arabic", "ar_EG",
|
|
|
|
|
"bulgarian", "bg_BG",
|
|
|
|
|
"greek", "el_GR",
|
2011-09-17 20:50:22 +00:00
|
|
|
"korean", "ko_KR",
|
|
|
|
|
"nepali", "ne_NP",
|
2011-10-11 05:52:58 +00:00
|
|
|
"persian", "fa_PE",
|
2011-12-21 11:56:42 +00:00
|
|
|
"indonesian", "id_ID",
|
2011-12-23 13:36:07 +00:00
|
|
|
"serbian (latin)", "sr_RS@latin",
|
2012-01-10 14:02:27 +00:00
|
|
|
"kyrgyz", "ky",
|
2011-07-22 14:14:28 +00:00
|
|
|
};
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2010-07-04 15:35:23 +00:00
|
|
|
void BLF_lang_init(void)
|
2009-01-29 05:19:27 +00:00
|
|
|
{
|
2010-07-04 15:35:23 +00:00
|
|
|
char *messagepath= BLI_get_folder(BLENDER_DATAFILES, "locale");
|
2009-09-24 07:03:18 +00:00
|
|
|
|
2010-07-04 15:35:23 +00:00
|
|
|
BLI_strncpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT, sizeof(global_encoding_name));
|
2009-09-24 07:03:18 +00:00
|
|
|
|
2011-10-21 08:16:15 +00:00
|
|
|
if (messagepath) {
|
2010-07-04 15:35:23 +00:00
|
|
|
BLI_strncpy(global_messagepath, messagepath, sizeof(global_messagepath));
|
2011-10-21 08:16:15 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("%s: 'locale' data path for translations not found, continuing\n", __func__);
|
2009-09-24 07:03:18 +00:00
|
|
|
global_messagepath[0]= '\0';
|
2011-10-21 08:16:15 +00:00
|
|
|
}
|
2011-02-22 12:01:57 +00:00
|
|
|
|
2009-09-24 07:03:18 +00:00
|
|
|
}
|
2010-07-04 15:35:23 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
/* get LANG/LANGUAGE environment variable */
|
|
|
|
|
static void get_language_variable(const char *varname, char *var, int maxlen)
|
|
|
|
|
{
|
|
|
|
|
char *env= getenv(varname);
|
|
|
|
|
|
|
|
|
|
if(env) {
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
/* store defaul locale */
|
|
|
|
|
BLI_strncpy(var, env, maxlen);
|
|
|
|
|
|
|
|
|
|
/* use first language as default */
|
|
|
|
|
s= strchr(var, ':');
|
|
|
|
|
if(s)
|
|
|
|
|
s[0]= 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get language to be used based on locale(which might be empty when using default language) and
|
|
|
|
|
* LANG environment variable
|
|
|
|
|
*/
|
|
|
|
|
static void get_language(const char *locale, const char *lang, char *language, int maxlen)
|
|
|
|
|
{
|
|
|
|
|
if(locale[0]) {
|
|
|
|
|
BLI_strncpy(language, locale, maxlen);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
BLI_strncpy(language, lang, maxlen);
|
|
|
|
|
|
|
|
|
|
s= strchr(language, '.');
|
|
|
|
|
if(s)
|
|
|
|
|
s[0]= 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 12:01:57 +00:00
|
|
|
/* XXX WARNING!!! IN osx somehow the previous function call jumps in this one??? (ton, ppc) */
|
2009-09-24 07:03:18 +00:00
|
|
|
void BLF_lang_set(const char *str)
|
|
|
|
|
{
|
2011-07-22 14:14:28 +00:00
|
|
|
char *locreturn;
|
2011-09-15 13:02:37 +00:00
|
|
|
const char *short_locale;
|
2011-09-15 13:20:18 +00:00
|
|
|
int ok= 1;
|
2011-12-26 14:52:36 +00:00
|
|
|
const char *long_locale = locales[2 * U.language];
|
2011-08-31 07:31:02 +00:00
|
|
|
|
2011-09-15 13:20:18 +00:00
|
|
|
if((U.transopts&USER_DOTRANSLATE)==0)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-08-31 07:31:02 +00:00
|
|
|
if(str)
|
|
|
|
|
short_locale = str;
|
|
|
|
|
else
|
2011-09-06 05:18:02 +00:00
|
|
|
short_locale = locales[ 2 * U.language + 1];
|
2011-08-31 07:31:02 +00:00
|
|
|
|
2011-09-21 13:30:52 +00:00
|
|
|
#if defined (_WIN32) && !defined(FREE_WINDOWS)
|
2011-09-15 13:20:18 +00:00
|
|
|
if(short_locale) {
|
2011-09-06 05:18:02 +00:00
|
|
|
char *envStr;
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2011-09-06 05:18:02 +00:00
|
|
|
if( U.language==0 )/* use system setting */
|
|
|
|
|
envStr = BLI_sprintfN( "LANG=%s", getenv("LANG") );
|
|
|
|
|
else
|
|
|
|
|
envStr = BLI_sprintfN( "LANG=%s", short_locale );
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2011-09-06 05:18:02 +00:00
|
|
|
gettext_putenv(envStr);
|
|
|
|
|
MEM_freeN(envStr);
|
2011-08-12 13:43:21 +00:00
|
|
|
}
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2011-08-31 07:31:02 +00:00
|
|
|
locreturn= setlocale(LC_ALL, long_locale);
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2011-07-25 17:05:43 +00:00
|
|
|
if (locreturn == NULL) {
|
2011-12-27 01:35:39 +00:00
|
|
|
if(G.f & G_DEBUG)
|
2011-12-26 14:52:36 +00:00
|
|
|
printf("Could not change locale to %s\n", long_locale);
|
|
|
|
|
|
2011-09-15 13:20:18 +00:00
|
|
|
ok= 0;
|
2011-08-31 07:31:02 +00:00
|
|
|
}
|
|
|
|
|
#else
|
2011-09-06 05:18:02 +00:00
|
|
|
{
|
2011-12-26 14:52:36 +00:00
|
|
|
static char default_lang[64]="\0";
|
|
|
|
|
static char default_language[64]="\0";
|
2011-09-06 05:18:02 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
if(default_lang[0]==0)
|
|
|
|
|
get_language_variable("LANG", default_lang, sizeof(default_lang));
|
2011-09-17 20:50:22 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
if(default_language[0]==0)
|
|
|
|
|
get_language_variable("LANGUAGE", default_language, sizeof(default_language));
|
2011-09-17 20:50:22 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
if(short_locale[0]) {
|
|
|
|
|
if(G.f & G_DEBUG)
|
|
|
|
|
printf("Setting LANG= and LANGUAGE to %s\n", short_locale);
|
2011-09-17 20:50:22 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
BLI_setenv("LANG", short_locale);
|
|
|
|
|
BLI_setenv("LANGUAGE", short_locale);
|
2011-09-17 20:50:22 +00:00
|
|
|
}
|
2011-12-26 14:52:36 +00:00
|
|
|
else {
|
|
|
|
|
if(G.f & G_DEBUG)
|
|
|
|
|
printf("Setting LANG=%s and LANGUAGE=%s\n", default_lang, default_language);
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
BLI_setenv("LANG", default_lang);
|
|
|
|
|
BLI_setenv("LANGUAGE", default_language);
|
|
|
|
|
}
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
locreturn= setlocale(LC_ALL, short_locale);
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
if(locreturn == NULL) {
|
|
|
|
|
char *short_locale_utf8= NULL;
|
2011-07-22 14:14:28 +00:00
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
if(short_locale[0]) {
|
|
|
|
|
short_locale_utf8= BLI_sprintfN("%s.UTF-8", short_locale);
|
|
|
|
|
locreturn= setlocale(LC_ALL, short_locale_utf8);
|
|
|
|
|
}
|
2011-09-15 13:20:18 +00:00
|
|
|
|
|
|
|
|
if (locreturn == NULL) {
|
2011-12-26 14:52:36 +00:00
|
|
|
char language[65];
|
|
|
|
|
|
|
|
|
|
get_language(long_locale, default_lang, language, sizeof(language));
|
|
|
|
|
|
|
|
|
|
if(G.f & G_DEBUG) {
|
|
|
|
|
if(short_locale[0])
|
|
|
|
|
printf("Could not change locale to %s nor %s\n", short_locale, short_locale_utf8);
|
|
|
|
|
else
|
|
|
|
|
printf("Could not reset locale\n");
|
|
|
|
|
|
|
|
|
|
printf("Fallback to LANG=%s and LANGUAGE=%s\n", default_lang, language);
|
|
|
|
|
}
|
2011-12-22 19:09:21 +00:00
|
|
|
|
|
|
|
|
/* fallback to default settings */
|
2011-12-26 14:52:36 +00:00
|
|
|
BLI_setenv("LANG", default_lang);
|
|
|
|
|
BLI_setenv("LANGUAGE", language);
|
|
|
|
|
|
2011-12-22 19:09:21 +00:00
|
|
|
locreturn= setlocale(LC_ALL, "");
|
|
|
|
|
|
2011-09-15 13:20:18 +00:00
|
|
|
ok= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-26 14:52:36 +00:00
|
|
|
if(short_locale_utf8)
|
|
|
|
|
MEM_freeN(short_locale_utf8);
|
2011-09-15 13:20:18 +00:00
|
|
|
}
|
2011-08-31 07:31:02 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2011-09-15 13:20:18 +00:00
|
|
|
|
|
|
|
|
if(ok) {
|
|
|
|
|
//printf("Change locale to %s\n", locreturn );
|
2011-08-31 07:31:02 +00:00
|
|
|
BLI_strncpy(global_language, locreturn, sizeof(global_language));
|
2011-07-25 17:05:43 +00:00
|
|
|
}
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2011-07-25 17:05:43 +00:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
|
|
2011-12-22 18:25:59 +00:00
|
|
|
textdomain(TEXT_DOMAIN_NAME);
|
|
|
|
|
bindtextdomain(TEXT_DOMAIN_NAME, global_messagepath);
|
|
|
|
|
bind_textdomain_codeset(TEXT_DOMAIN_NAME, global_encoding_name);
|
2009-01-29 05:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-17 12:05:09 +00:00
|
|
|
void BLF_lang_encoding(const char *str)
|
2009-01-29 05:19:27 +00:00
|
|
|
{
|
2011-02-13 03:21:27 +00:00
|
|
|
BLI_strncpy(global_encoding_name, str, sizeof(global_encoding_name));
|
2011-12-22 18:25:59 +00:00
|
|
|
/* bind_textdomain_codeset(TEXT_DOMAIN_NAME, encoding_name); */
|
2009-03-31 21:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-26 10:35:47 +00:00
|
|
|
#else /* ! WITH_INTERNATIONAL */
|
2009-03-31 21:19:23 +00:00
|
|
|
|
|
|
|
|
void BLF_lang_init(void)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2009-01-29 05:19:27 +00:00
|
|
|
}
|
2009-03-31 21:19:23 +00:00
|
|
|
|
2011-02-17 12:05:09 +00:00
|
|
|
void BLF_lang_encoding(const char *str)
|
2009-03-31 21:19:23 +00:00
|
|
|
{
|
2010-10-16 14:32:17 +00:00
|
|
|
(void)str;
|
2009-03-31 21:19:23 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-13 12:50:40 +00:00
|
|
|
void BLF_lang_set(const char *str)
|
2009-03-31 21:19:23 +00:00
|
|
|
{
|
2010-10-16 14:32:17 +00:00
|
|
|
(void)str;
|
2009-03-31 21:19:23 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-26 10:35:47 +00:00
|
|
|
#endif /* WITH_INTERNATIONAL */
|