Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025
00026 #include <locale.h>
00027 #include "gettext.h"
00028 #include "nls.h"
00029
00030
00031 void nls::init (config &myconfig)
00032 {
00033 #if ENABLE_NLS
00034
00035
00036 if (myconfig.language == "")
00037 setlocale (LC_MESSAGES, "");
00038
00039 else
00040 set_language (myconfig.language);
00041
00042
00043 std::string location = "/usr/share/locale";
00044 const char *domain = myconfig.game_name.c_str ();
00045
00046 bindtextdomain (domain, location.c_str ());
00047 textdomain (domain);
00048 bind_textdomain_codeset(domain, "UTF-8");
00049 #endif
00050 }
00051
00052
00053 void nls::set_language (const string &language)
00054 {
00055 #if ENABLE_NLS
00056 #ifndef __BEOS__
00057 string lang = "LANGUAGE=" + language;
00058 putenv ((char *) lang.c_str ());
00059 #else
00060
00061 #endif
00062 {
00063
00064 extern int _nl_msg_cat_cntr;
00065 ++_nl_msg_cat_cntr;
00066 }
00067
00068 setlocale (LC_MESSAGES, language.c_str ());
00069 #endif
00070 }
00071
00072
00073 const char* nls::translate (const string &text)
00074 {
00075 #if ENABLE_NLS
00076 return gettext (text.c_str ());
00077 #else
00078 return text.c_str ();
00079 #endif
00080 }