2009-01-29 05:19:27 +00:00
|
|
|
/**
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** 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,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
#ifdef INTERNATIONAL
|
2009-02-17 16:56:29 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
#include <locale.h>
|
|
|
|
|
#include "libintl.h"
|
2009-02-17 16:56:29 +00:00
|
|
|
|
2009-01-29 05:19:27 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_linklist.h" /* linknode */
|
|
|
|
|
#include "BLI_string.h"
|
|
|
|
|
|
2009-02-17 16:56:29 +00:00
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
#include "BKE_utildefines.h"
|
2009-01-29 21:41:43 +00:00
|
|
|
#endif
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
#define DOMAIN_NAME "blender"
|
|
|
|
|
#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. */
|
|
|
|
|
char global_messagepath[1024];
|
|
|
|
|
char global_language[32];
|
|
|
|
|
char global_encoding_name[32];
|
2009-01-29 05:19:27 +00:00
|
|
|
|
|
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
void BLF_lang_init(void)
|
2009-01-29 05:19:27 +00:00
|
|
|
{
|
2009-03-31 21:19:23 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
char *bundlepath;
|
|
|
|
|
#endif
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
strcpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT);
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
/* set messagepath directory */
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
#ifndef LOCALEDIR
|
|
|
|
|
#define LOCALEDIR "/usr/share/locale"
|
2009-01-29 21:41:43 +00:00
|
|
|
#endif
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
strcpy(global_messagepath, ".blender/locale");
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
if (!BLI_exist(global_messagepath)) { /* locale not in current dir */
|
|
|
|
|
BLI_make_file_string("/", global_messagepath, BLI_gethome(), ".blender/locale");
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
if (!BLI_exist(global_messagepath)) { /* locale not in home dir */
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
BLI_make_file_string("/", global_messagepath, BLI_gethome(), "/locale");
|
|
|
|
|
if (!BLI_exist(global_messagepath)) {
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
/* message catalogs are stored inside the application bundle */
|
|
|
|
|
bundlepath= BLI_getbundle();
|
|
|
|
|
strcpy(global_messagepath, bundlepath);
|
|
|
|
|
strcat(global_messagepath, "/Contents/Resources/locale");
|
|
|
|
|
if (!BLI_exist(global_messagepath)) { /* locale not in bundle (now that's odd..) */
|
|
|
|
|
#endif
|
|
|
|
|
strcpy(global_messagepath, LOCALEDIR);
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
if (!BLI_exist(global_messagepath)) { /* locale not in LOCALEDIR */
|
|
|
|
|
strcpy(global_messagepath, "message"); /* old compatibility as last */
|
|
|
|
|
}
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2009-01-29 05:19:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-23 21:57:41 +00:00
|
|
|
void BLF_lang_set(const char *str)
|
2009-01-29 05:19:27 +00:00
|
|
|
{
|
2009-03-31 21:19:23 +00:00
|
|
|
#if defined (_WIN32) || defined(__APPLE__)
|
|
|
|
|
char envstr[12];
|
|
|
|
|
|
|
|
|
|
sprintf(envstr, "LANG=%s", str);
|
|
|
|
|
envstr[strlen(envstr)]= '\0';
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
gettext_putenv(envstr);
|
2009-01-29 05:19:27 +00:00
|
|
|
#else
|
2009-03-31 21:19:23 +00:00
|
|
|
putenv(envstr);
|
2009-01-29 05:19:27 +00:00
|
|
|
#endif
|
2009-03-31 21:19:23 +00:00
|
|
|
#else
|
|
|
|
|
char *locreturn= setlocale(LC_ALL, str);
|
|
|
|
|
if (locreturn == NULL) {
|
|
|
|
|
char *lang;
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
lang= (char*)malloc(sizeof(char)*(strlen(str)+7));
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
lang[0]= '\0';
|
|
|
|
|
strcat(lang, str);
|
|
|
|
|
strcat(lang, ".UTF-8");
|
2009-01-29 05:19:27 +00:00
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
locreturn= setlocale(LC_ALL, lang);
|
|
|
|
|
if (locreturn == NULL) {
|
|
|
|
|
printf("could not change language to %s nor %s\n", str, lang);
|
2009-01-29 05:19:27 +00:00
|
|
|
}
|
2009-03-31 21:19:23 +00:00
|
|
|
|
|
|
|
|
free(lang);
|
2009-01-29 05:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-31 21:19:23 +00:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
|
#endif
|
2009-04-23 21:57:41 +00:00
|
|
|
textdomain(DOMAIN_NAME);
|
2009-03-31 21:19:23 +00:00
|
|
|
bindtextdomain(DOMAIN_NAME, global_messagepath);
|
|
|
|
|
/* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */
|
|
|
|
|
strcpy(global_language, str);
|
2009-01-29 05:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
2009-04-23 21:57:41 +00:00
|
|
|
void BLF_lang_encoding(const char *str)
|
2009-01-29 05:19:27 +00:00
|
|
|
{
|
2009-03-31 21:19:23 +00:00
|
|
|
strcpy(global_encoding_name, str);
|
|
|
|
|
/* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else /* ! INTERNATIONAL */
|
|
|
|
|
|
|
|
|
|
void BLF_lang_init(void)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2009-01-29 05:19:27 +00:00
|
|
|
}
|
2009-03-31 21:19:23 +00:00
|
|
|
|
|
|
|
|
void BLF_lang_encoding(char *str)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BLF_lang_set(char *str)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* INTERNATIONAL */
|