diff options
Diffstat (limited to 'source/blender/blenfont/intern/blf_lang.c')
-rw-r--r-- | source/blender/blenfont/intern/blf_lang.c | 143 |
1 files changed, 122 insertions, 21 deletions
diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index e7f9d1746ad..bff0db8f4f9 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -41,6 +41,7 @@ #include <locale.h> #include "libintl.h" +#include "DNA_userdef_types.h" #include "DNA_listBase.h" #include "DNA_vec_types.h" @@ -65,6 +66,89 @@ static char global_messagepath[1024]; static char global_language[32]; static char global_encoding_name[32]; +/* map from the rna_userdef.c:rna_def_userdef_system(BlenderRNA *brna):language_items */ + +static char *long_locales[] = { + "", + "english", + "japanese", + "dutch", + "italian", + "german", + "finnish", + "swedish", + "french", + "spanish", + "catalan", + "czech", + "ptb", + "chs", + "cht", + "russian", + "croatian", + "serbian", + "ukrainian", + "polish", + "romanian", + "arabic", + "bulgarian", + "greek", + "korean" +}; + +static char short_locale_default[] = ""; +static char short_locale_english[] = "en_US"; +static char short_locale_japanese[] = "ja_JP"; +static char short_locale_dutch[] = "nl_NL"; +static char short_locale_italian[] = "it_IT"; +static char short_locale_german[] = "de_DE"; +static char short_locale_finnish[] = "fi_FI"; +static char short_locale_swedish[] = "sv_SE"; +static char short_locale_french[] = "fr_FR"; +static char short_locale_spanish[] = "es_ES"; +static char short_locale_catalan[] = "ca_AD"; +static char short_locale_czech[] = "cs_CZ"; +static char short_locale_bra_portuguese[] = "pt_BR"; +static char short_locale_sim_chinese[] = "zh_CN"; +static char short_locale_tra_chinese[] = "zh_TW"; +static char short_locale_russian[] = "ru_RU"; +static char short_locale_croatian[] = "hr_HR"; +static char short_locale_serbian[] = "sr_RS"; +static char short_locale_ukrainian[] = "uk_UA"; +static char short_locale_polish[] = "pl_PL"; +static char short_locale_romanian[] = "ro_RO"; +static char short_locale_arabic[] = "ar_EG"; +static char short_locale_bulgarian[] = "bg_BG"; +static char short_locale_greek[] = "el_GR"; +static char short_locale_korean[] = "ko_KR"; + +static char *short_locales[] = { + short_locale_default, + short_locale_english, /* us english is the default language of blender */ + short_locale_japanese, + short_locale_dutch, + short_locale_italian, + short_locale_german, + short_locale_finnish, + short_locale_swedish, + short_locale_french, + short_locale_spanish, + short_locale_catalan, + short_locale_czech, + short_locale_bra_portuguese, + short_locale_sim_chinese, + short_locale_tra_chinese, + short_locale_russian, + short_locale_croatian, + short_locale_serbian, + short_locale_ukrainian, + short_locale_polish, + short_locale_romanian, + short_locale_arabic, + short_locale_bulgarian, + short_locale_greek, + short_locale_korean, +}; void BLF_lang_init(void) { @@ -82,34 +166,51 @@ void BLF_lang_init(void) /* XXX WARNING!!! IN osx somehow the previous function call jumps in this one??? (ton, ppc) */ void BLF_lang_set(const char *str) { - if(str==NULL) { - return; + char *locreturn; + char *short_locale; +#if defined (_WIN32) + char *long_locale = long_locales[U.language]; +#endif + + if(str) + short_locale = str; + else + short_locale = short_locales[U.language]; + + if(short_locale) + { + BLI_setenv("LANG", short_locale); + BLI_setenv("LANGUAGE", short_locale); } - else { - -#if defined (_WIN32) || defined(__APPLE__) - BLI_setenv("LANG", str); -#else - char *locreturn= setlocale(LC_ALL, str); - if (locreturn == NULL) { - char *lang= BLI_sprintfN("%s.UTF-8", str); - locreturn= setlocale(LC_ALL, lang); - if (locreturn == NULL) { - printf("could not change language to %s nor %s\n", str, lang); - } +#if defined (_WIN32) + locreturn= setlocale(LC_ALL, long_locale); + if (locreturn == NULL) { + printf("Could not change locale to %s\n", long_locale); + } +#else + locreturn= setlocale(LC_ALL, short_locale); + if (locreturn == NULL) { + char *short_locale_utf8 = BLI_sprintfN("%s.UTF-8", short_locale); - MEM_freeN(lang); + locreturn= setlocale(LC_ALL, short_locale_utf8); + if (locreturn == NULL) { + printf("Could not change locale to %s nor %s\n", short_locale, short_locale_utf8); } - setlocale(LC_NUMERIC, "C"); + MEM_freeN(short_locale_utf8); + } #endif - textdomain(DOMAIN_NAME); - bindtextdomain(DOMAIN_NAME, global_messagepath); - /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */ - BLI_strncpy(global_language, str, sizeof(global_language)); - + else + { + printf("Change locale to %s\n", locreturn ); + BLI_strncpy(global_language, locreturn, sizeof(global_language)); } + setlocale(LC_NUMERIC, "C"); + + textdomain(DOMAIN_NAME); + bindtextdomain(DOMAIN_NAME, global_messagepath); + /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */ } void BLF_lang_encoding(const char *str) |