00001 //----------------------------------------------------------------------------------- 00002 // 00003 // Pro-Vocation Light Engine (PVLE) 00004 // Copyright (C) 2007-2009 Sukender, KinoX & Buzib 00005 // For more information, contact us : sukender@free.fr 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 as published by 00009 // the Free Software Foundation; either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // For any use that is not compatible with the terms of the GNU 00013 // General Public License, please contact the authors for alternative 00014 // licensing options. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with this program; if not, write to the Free Software Foundation, Inc., 00023 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 // 00025 //----------------------------------------------------------------------------------- 00026 00027 #include <PVLE/Util/I18N.h> 00028 #include <PVLE/Util/Util.h> 00029 00030 const osgText::String::Encoding PVLE_DEFAULT_ENCODING = osgText::String::ENCODING_UTF8; 00031 const char * const PVLE_DEFAULT_ENCODING_STRING = "UTF-8"; // Same as toGettextEncoding(PVLE_DEFAULT_ENCODING) 00032 00033 #ifdef PVLE_I18N 00034 00035 namespace I18N { 00036 00037 void init(const std::string & domainName, const boost::filesystem::path & dirName) { 00038 setlocale(LC_ALL, ""); 00039 //setlocale(LC_CTYPE, ""); 00040 //setlocale(LC_MESSAGES, ""); 00041 //setlocale(LC_COLLATE, ""); 00042 //setlocale(LC_MONETARY, ""); 00043 //setlocale(LC_NUMERIC, ""); 00044 //setlocale(LC_TIME, ""); 00045 bindtextdomain(domainName.c_str(), dirName.native_directory_string().c_str()); 00046 bind_textdomain_codeset(domainName.c_str(), PVLE_DEFAULT_ENCODING_STRING); 00047 changeDomain(domainName); 00048 } 00049 00050 const char * toGettextEncoding(const osgText::String::Encoding encoding) { 00051 switch(encoding) { 00052 //case ENCODING_ASCII: return "ASCII"; 00053 case osgText::String::ENCODING_UTF8: return "UTF-8"; 00054 // TODO: Find all text represnentations for other cases before adding support into PVLE I18N! :) 00055 //case ENCODING_: return ""; 00056 default: 00057 THROW_TRACED_EXCEPTION("I18N: Unsuported ecoding (Not implemented)"); 00058 } 00059 } 00060 osgText::String::Encoding toOSGEncoding(const char * const encoding) { 00061 if (!encoding) { 00062 // This is the locale default 00063 THROW_TRACED_EXCEPTION("I18N: Unsuported ecoding (Locale default not implemented)"); 00064 } 00065 00066 const std::string str(encoding); 00067 if (str != "UTF-8") 00068 THROW_TRACED_EXCEPTION("I18N: Unsuported ecoding (Not implemented)"); 00069 return osgText::String::ENCODING_UTF8; 00070 } 00071 00072 void setEncoding(const std::string & domainName, const osgText::String::Encoding encoding) { 00073 bind_textdomain_codeset(domainName.c_str(), toGettextEncoding(encoding)); 00074 } 00075 00076 osgText::String::Encoding getEncoding(const std::string & domainName) { 00077 return toOSGEncoding(bind_textdomain_codeset(domainName.c_str(), NULL)); 00078 } 00079 00080 00081 //void setLocale(const std::string & locale) { 00082 // THROW_TRACED_EXCEPTION("Implementation is buggy"); // Does nothing since it appears that the lib reads the env. variables at DLL/so loading. 00083 00084 // // By decreasing priority, this environment variables are used: 00085 // // 1. LANGUAGE 00086 // // 2. LC_ALL 00087 // // 3. LC_xxx, according to selected locale 00088 // // 4. LANG 00089 // //setenv("LANGUAGE", locale.c_str()); 00090 // //const char * DEBUG_aaa = getenv("LANGUAGE"); 00091 // //const char * DEBUG_bbb = setlocale(LC_ALL, NULL); 00092 // //const char * DEBUG_ccc = getenv("LANG"); 00093 // //setenv("LANGUAGE", locale.c_str()); 00094 // setlocale(LC_ALL, locale.c_str()); 00095 00096 // // Make change known 00097 // // (See gettext doc: "10.5 Being a gettext grok") 00098 // //extern int _nl_msg_cat_cntr; 00099 // //extern "C" int _nl_msg_cat_cntr; 00100 // //++_nl_msg_cat_cntr; 00101 // // Need to FreeLibrary/LoadLibrary under Windows ? 00102 //} 00103 00104 } // namespace I18N 00105 00106 #endif // PVLE_I18N