Adonthell
0.4
|
00001 /* 00002 $Id: nls.cc,v 1.10 2006/09/12 06:44:38 ksterker Exp $ 00003 00004 Copyright (C) 2002/2003 Kai Sterker <kaisterker@linuxgames.com> 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 /** 00016 * @file nls.cc 00017 * 00018 * @author Kai Sterker 00019 * @brief National Language Support 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 // Initialize NLS 00031 void nls::init (config &myconfig) 00032 { 00033 #if ENABLE_NLS 00034 // if no language specified in the config file, determine 00035 // the locale from the environment variables 00036 if (myconfig.language == "") 00037 setlocale (LC_MESSAGES, ""); 00038 // otherwise overwrite any environment variables 00039 else 00040 set_language (myconfig.language); 00041 00042 // open the message catalogue 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 // Set the language to use 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 // TODO: no putenv on BEOS, but there should be setenv 00061 #endif 00062 { 00063 // tell gettext that the language has changed 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 // Translate some text 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 }