diff options
Diffstat (limited to 'shared/localization.cpp')
-rw-r--r-- | shared/localization.cpp | 573 |
1 files changed, 349 insertions, 224 deletions
diff --git a/shared/localization.cpp b/shared/localization.cpp index 678767b9..a412df1e 100644 --- a/shared/localization.cpp +++ b/shared/localization.cpp @@ -13,6 +13,12 @@ #include <map> #include <wx/ffile.h> +#if wxCHECK_VERSION(2, 9, 1) +#include <boost/cstdint.hpp> +#include <wx/translation.h> +#include <cstdlib> +#endif + using ffs3::CustomLocale; using ffs3::LocalizationInfo; @@ -132,13 +138,6 @@ LocalizationInfo::LocalizationInfo() newEntry.languageFlag = wxT("holland.png"); locMapping.push_back(newEntry); - newEntry.languageID = wxLANGUAGE_RUSSIAN; - newEntry.languageName = wxT("Pусский"); - newEntry.languageFile = wxT("russian.lng"); - newEntry.translatorName = wxT("Fayzullin T.N. aka Svobodniy"); - newEntry.languageFlag = wxT("russia.png"); - locMapping.push_back(newEntry); - newEntry.languageID = wxLANGUAGE_POLISH; newEntry.languageName = wxT("Polski"); newEntry.languageFile = wxT("polish.lng"); @@ -160,6 +159,13 @@ LocalizationInfo::LocalizationInfo() newEntry.languageFlag = wxT("brazil.png"); locMapping.push_back(newEntry); + newEntry.languageID = wxLANGUAGE_RUSSIAN; + newEntry.languageName = wxT("Pусский"); + newEntry.languageFile = wxT("russian.lng"); + newEntry.translatorName = wxT("Fayzullin T.N. aka Svobodniy"); + newEntry.languageFlag = wxT("russia.png"); + locMapping.push_back(newEntry); + newEntry.languageID = wxLANGUAGE_ROMANIAN; newEntry.languageName = wxT("Română"); newEntry.languageFile = wxT("romanian.lng"); @@ -195,19 +201,19 @@ LocalizationInfo::LocalizationInfo() newEntry.languageFlag = wxT("turkey.png"); locMapping.push_back(newEntry); -// newEntry.languageID = wxLANGUAGE_HEBREW; -// newEntry.languageName = wxT("עִבְרִית"); -// newEntry.languageFile = wxT("hebrew.lng"); -// newEntry.translatorName = wxT("Moshe Olshevsky"); -// newEntry.languageFlag = wxT("isreal.png"); -// locMapping.push_back(newEntry); + // newEntry.languageID = wxLANGUAGE_HEBREW; + // newEntry.languageName = wxT("עִבְרִית"); + // newEntry.languageFile = wxT("hebrew.lng"); + // newEntry.translatorName = wxT("Moshe Olshevsky"); + // newEntry.languageFlag = wxT("isreal.png"); + // locMapping.push_back(newEntry); -// newEntry.languageID = wxLANGUAGE_ARABIC; -// newEntry.languageName = wxT("العربية"); -// newEntry.languageFile = wxT("arabic.lng"); -// newEntry.translatorName = wxT("Yousef Shamshoum"); -// newEntry.languageFlag = wxT("arabic-language.png"); -// locMapping.push_back(newEntry); + // newEntry.languageID = wxLANGUAGE_ARABIC; + // newEntry.languageName = wxT("العربية"); + // newEntry.languageFile = wxT("arabic.lng"); + // newEntry.translatorName = wxT("Yousef Shamshoum"); + // newEntry.languageFlag = wxT("arabic-language.png"); + // locMapping.push_back(newEntry); newEntry.languageID = wxLANGUAGE_JAPANESE; newEntry.languageName = wxT("日本語"); @@ -230,163 +236,140 @@ LocalizationInfo::LocalizationInfo() newEntry.languageFlag = wxT("china.png"); locMapping.push_back(newEntry); + newEntry.languageID = wxLANGUAGE_KOREAN; + newEntry.languageName = wxT("한국어"); + newEntry.languageFile = wxT("korean.lng"); + newEntry.translatorName = wxT("Simon Park"); + newEntry.languageFlag = wxT("south_korea.png"); + locMapping.push_back(newEntry); + //std::sort(locMapping.begin(), locMapping.end(), CompareByName()); } -int mapLanguageDialect(const int language) +namespace +{ +int mapLanguageDialect(int language) { switch (language) //map language dialects { - //variants of wxLANGUAGE_GERMAN - case wxLANGUAGE_GERMAN_AUSTRIAN: - case wxLANGUAGE_GERMAN_BELGIUM: - case wxLANGUAGE_GERMAN_LIECHTENSTEIN: - case wxLANGUAGE_GERMAN_LUXEMBOURG: - case wxLANGUAGE_GERMAN_SWISS: - return wxLANGUAGE_GERMAN; - - //variants of wxLANGUAGE_FRENCH - case wxLANGUAGE_FRENCH_BELGIAN: - case wxLANGUAGE_FRENCH_CANADIAN: - case wxLANGUAGE_FRENCH_LUXEMBOURG: - case wxLANGUAGE_FRENCH_MONACO: - case wxLANGUAGE_FRENCH_SWISS: - return wxLANGUAGE_FRENCH; - - //variants of wxLANGUAGE_DUTCH - case wxLANGUAGE_DUTCH_BELGIAN: - return wxLANGUAGE_DUTCH; - - //variants of wxLANGUAGE_ITALIAN - case wxLANGUAGE_ITALIAN_SWISS: - return wxLANGUAGE_ITALIAN; - - //variants of wxLANGUAGE_CHINESE_SIMPLIFIED - case wxLANGUAGE_CHINESE: - case wxLANGUAGE_CHINESE_SINGAPORE: - return wxLANGUAGE_CHINESE_SIMPLIFIED; - - //variants of wxLANGUAGE_CHINESE_TRADITIONAL - case wxLANGUAGE_CHINESE_TAIWAN: - case wxLANGUAGE_CHINESE_HONGKONG: - case wxLANGUAGE_CHINESE_MACAU: - return wxLANGUAGE_CHINESE_TRADITIONAL; - - //variants of wxLANGUAGE_RUSSIAN - case wxLANGUAGE_RUSSIAN_UKRAINE: - return wxLANGUAGE_RUSSIAN; - - //variants of wxLANGUAGE_SPANISH - case wxLANGUAGE_SPANISH_ARGENTINA: - case wxLANGUAGE_SPANISH_BOLIVIA: - case wxLANGUAGE_SPANISH_CHILE: - case wxLANGUAGE_SPANISH_COLOMBIA: - case wxLANGUAGE_SPANISH_COSTA_RICA: - case wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC: - case wxLANGUAGE_SPANISH_ECUADOR: - case wxLANGUAGE_SPANISH_EL_SALVADOR: - case wxLANGUAGE_SPANISH_GUATEMALA: - case wxLANGUAGE_SPANISH_HONDURAS: - case wxLANGUAGE_SPANISH_MEXICAN: - case wxLANGUAGE_SPANISH_MODERN: - case wxLANGUAGE_SPANISH_NICARAGUA: - case wxLANGUAGE_SPANISH_PANAMA: - case wxLANGUAGE_SPANISH_PARAGUAY: - case wxLANGUAGE_SPANISH_PERU: - case wxLANGUAGE_SPANISH_PUERTO_RICO: - case wxLANGUAGE_SPANISH_URUGUAY: - case wxLANGUAGE_SPANISH_US: - case wxLANGUAGE_SPANISH_VENEZUELA: - return wxLANGUAGE_SPANISH; - - //variants of wxLANGUAGE_SWEDISH - case wxLANGUAGE_SWEDISH_FINLAND: - return wxLANGUAGE_SWEDISH; - - //case wxLANGUAGE_CZECH: - //case wxLANGUAGE_FINNISH: - //case wxLANGUAGE_GREEK: - //case wxLANGUAGE_JAPANESE: - //case wxLANGUAGE_POLISH: - //case wxLANGUAGE_SLOVENIAN: - //case wxLANGUAGE_HUNGARIAN: - //case wxLANGUAGE_PORTUGUESE: - //case wxLANGUAGE_PORTUGUESE_BRAZILIAN: - - //variants of wxLANGUAGE_ARABIC (also needed to detect RTL languages) - case wxLANGUAGE_ARABIC_ALGERIA: - case wxLANGUAGE_ARABIC_BAHRAIN: - case wxLANGUAGE_ARABIC_EGYPT: - case wxLANGUAGE_ARABIC_IRAQ: - case wxLANGUAGE_ARABIC_JORDAN: - case wxLANGUAGE_ARABIC_KUWAIT: - case wxLANGUAGE_ARABIC_LEBANON: - case wxLANGUAGE_ARABIC_LIBYA: - case wxLANGUAGE_ARABIC_MOROCCO: - case wxLANGUAGE_ARABIC_OMAN: - case wxLANGUAGE_ARABIC_QATAR: - case wxLANGUAGE_ARABIC_SAUDI_ARABIA: - case wxLANGUAGE_ARABIC_SUDAN: - case wxLANGUAGE_ARABIC_SYRIA: - case wxLANGUAGE_ARABIC_TUNISIA: - case wxLANGUAGE_ARABIC_UAE: - case wxLANGUAGE_ARABIC_YEMEN: - return wxLANGUAGE_ARABIC; - - //variants of wxLANGUAGE_ENGLISH_UK - case wxLANGUAGE_ENGLISH_AUSTRALIA: - case wxLANGUAGE_ENGLISH_NEW_ZEALAND: - case wxLANGUAGE_ENGLISH_TRINIDAD: - case wxLANGUAGE_ENGLISH_CARIBBEAN: - case wxLANGUAGE_ENGLISH_JAMAICA: - case wxLANGUAGE_ENGLISH_BELIZE: - case wxLANGUAGE_ENGLISH_EIRE: - case wxLANGUAGE_ENGLISH_SOUTH_AFRICA: - case wxLANGUAGE_ENGLISH_ZIMBABWE: - case wxLANGUAGE_ENGLISH_BOTSWANA: - case wxLANGUAGE_ENGLISH_DENMARK: - return wxLANGUAGE_ENGLISH_UK; - - default: - return language; + //variants of wxLANGUAGE_GERMAN + case wxLANGUAGE_GERMAN_AUSTRIAN: + case wxLANGUAGE_GERMAN_BELGIUM: + case wxLANGUAGE_GERMAN_LIECHTENSTEIN: + case wxLANGUAGE_GERMAN_LUXEMBOURG: + case wxLANGUAGE_GERMAN_SWISS: + return wxLANGUAGE_GERMAN; + + //variants of wxLANGUAGE_FRENCH + case wxLANGUAGE_FRENCH_BELGIAN: + case wxLANGUAGE_FRENCH_CANADIAN: + case wxLANGUAGE_FRENCH_LUXEMBOURG: + case wxLANGUAGE_FRENCH_MONACO: + case wxLANGUAGE_FRENCH_SWISS: + return wxLANGUAGE_FRENCH; + + //variants of wxLANGUAGE_DUTCH + case wxLANGUAGE_DUTCH_BELGIAN: + return wxLANGUAGE_DUTCH; + + //variants of wxLANGUAGE_ITALIAN + case wxLANGUAGE_ITALIAN_SWISS: + return wxLANGUAGE_ITALIAN; + + //variants of wxLANGUAGE_CHINESE_SIMPLIFIED + case wxLANGUAGE_CHINESE: + case wxLANGUAGE_CHINESE_SINGAPORE: + return wxLANGUAGE_CHINESE_SIMPLIFIED; + + //variants of wxLANGUAGE_CHINESE_TRADITIONAL + case wxLANGUAGE_CHINESE_TAIWAN: + case wxLANGUAGE_CHINESE_HONGKONG: + case wxLANGUAGE_CHINESE_MACAU: + return wxLANGUAGE_CHINESE_TRADITIONAL; + + //variants of wxLANGUAGE_RUSSIAN + case wxLANGUAGE_RUSSIAN_UKRAINE: + return wxLANGUAGE_RUSSIAN; + + //variants of wxLANGUAGE_SPANISH + case wxLANGUAGE_SPANISH_ARGENTINA: + case wxLANGUAGE_SPANISH_BOLIVIA: + case wxLANGUAGE_SPANISH_CHILE: + case wxLANGUAGE_SPANISH_COLOMBIA: + case wxLANGUAGE_SPANISH_COSTA_RICA: + case wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC: + case wxLANGUAGE_SPANISH_ECUADOR: + case wxLANGUAGE_SPANISH_EL_SALVADOR: + case wxLANGUAGE_SPANISH_GUATEMALA: + case wxLANGUAGE_SPANISH_HONDURAS: + case wxLANGUAGE_SPANISH_MEXICAN: + case wxLANGUAGE_SPANISH_MODERN: + case wxLANGUAGE_SPANISH_NICARAGUA: + case wxLANGUAGE_SPANISH_PANAMA: + case wxLANGUAGE_SPANISH_PARAGUAY: + case wxLANGUAGE_SPANISH_PERU: + case wxLANGUAGE_SPANISH_PUERTO_RICO: + case wxLANGUAGE_SPANISH_URUGUAY: + case wxLANGUAGE_SPANISH_US: + case wxLANGUAGE_SPANISH_VENEZUELA: + return wxLANGUAGE_SPANISH; + + //variants of wxLANGUAGE_SWEDISH + case wxLANGUAGE_SWEDISH_FINLAND: + return wxLANGUAGE_SWEDISH; + + //case wxLANGUAGE_CZECH: + //case wxLANGUAGE_FINNISH: + //case wxLANGUAGE_GREEK: + //case wxLANGUAGE_JAPANESE: + //case wxLANGUAGE_POLISH: + //case wxLANGUAGE_SLOVENIAN: + //case wxLANGUAGE_HUNGARIAN: + //case wxLANGUAGE_PORTUGUESE: + //case wxLANGUAGE_PORTUGUESE_BRAZILIAN: + //case wxLANGUAGE_KOREAN: + + //variants of wxLANGUAGE_ARABIC (also needed to detect RTL languages) + case wxLANGUAGE_ARABIC_ALGERIA: + case wxLANGUAGE_ARABIC_BAHRAIN: + case wxLANGUAGE_ARABIC_EGYPT: + case wxLANGUAGE_ARABIC_IRAQ: + case wxLANGUAGE_ARABIC_JORDAN: + case wxLANGUAGE_ARABIC_KUWAIT: + case wxLANGUAGE_ARABIC_LEBANON: + case wxLANGUAGE_ARABIC_LIBYA: + case wxLANGUAGE_ARABIC_MOROCCO: + case wxLANGUAGE_ARABIC_OMAN: + case wxLANGUAGE_ARABIC_QATAR: + case wxLANGUAGE_ARABIC_SAUDI_ARABIA: + case wxLANGUAGE_ARABIC_SUDAN: + case wxLANGUAGE_ARABIC_SYRIA: + case wxLANGUAGE_ARABIC_TUNISIA: + case wxLANGUAGE_ARABIC_UAE: + case wxLANGUAGE_ARABIC_YEMEN: + return wxLANGUAGE_ARABIC; + + //variants of wxLANGUAGE_ENGLISH_UK + case wxLANGUAGE_ENGLISH_AUSTRALIA: + case wxLANGUAGE_ENGLISH_NEW_ZEALAND: + case wxLANGUAGE_ENGLISH_TRINIDAD: + case wxLANGUAGE_ENGLISH_CARIBBEAN: + case wxLANGUAGE_ENGLISH_JAMAICA: + case wxLANGUAGE_ENGLISH_BELIZE: + case wxLANGUAGE_ENGLISH_EIRE: + case wxLANGUAGE_ENGLISH_SOUTH_AFRICA: + case wxLANGUAGE_ENGLISH_ZIMBABWE: + case wxLANGUAGE_ENGLISH_BOTSWANA: + case wxLANGUAGE_ENGLISH_DENMARK: + return wxLANGUAGE_ENGLISH_UK; + + default: + return language; } } -typedef wxString TextOriginal; -typedef wxString TextTranslation; - -class Translation : public std::map<TextOriginal, TextTranslation> {}; - - -CustomLocale& CustomLocale::getInstance() -{ - static CustomLocale instance; - return instance; -} - - -CustomLocale::CustomLocale() : - translationDB(new Translation), - currentLanguage(wxLANGUAGE_ENGLISH) -{ - Init(wxLANGUAGE_DEFAULT); //setting a different language needn't be supported on all systems! - - //actually these two parameters are language dependent, but we take system setting to handle all kinds of language derivations - const lconv* localInfo = localeconv(); - THOUSANDS_SEPARATOR = wxString::FromUTF8(localInfo->thousands_sep); - DECIMAL_POINT = wxString::FromUTF8(localInfo->decimal_point); - - // why not working? - // THOUSANDS_SEPARATOR = std::use_facet<std::numpunct<wchar_t> >(std::locale("")).thousands_sep(); - // DECIMAL_POINT = std::use_facet<std::numpunct<wchar_t> >(std::locale("")).decimal_point(); -} - - -CustomLocale::~CustomLocale() {} //non-inline destructor for std::auto_ptr to work with forward declaration - - inline void exchangeEscapeChars(wxString& data) { @@ -407,20 +390,20 @@ void exchangeEscapeChars(wxString& data) switch (value) { - case wxChar('\\'): - output += wxChar('\\'); - break; - case wxChar('n'): - output += wxChar('\n'); - break; - case wxChar('t'): - output += wxChar('\t'); - break; - case wxChar('\"'): - output += wxChar('\"'); - break; - default: - output += value; + case wxChar('\\'): + output += wxChar('\\'); + break; + case wxChar('n'): + output += wxChar('\n'); + break; + case wxChar('t'): + output += wxChar('\t'); + break; + case wxChar('\"'): + output += wxChar('\"'); + break; + default: + output += value; } } else @@ -432,13 +415,13 @@ void exchangeEscapeChars(wxString& data) } +//workaround to get a FILE* from a unicode filename in a portable way class UnicodeFileReader { public: UnicodeFileReader(const wxString& filename) : inputFile(NULL) { - //workaround to get a FILE* from a unicode filename wxFFile dummyFile(filename, wxT("rb")); if (dummyFile.IsOpened()) { @@ -489,9 +472,182 @@ private: }; +typedef std::map<wxString, wxString> TranslationMap; //map original text |-> translation + +void loadTranslation(const wxString& filename, TranslationMap& trans) //empty translation on error +{ + trans.clear(); + + UnicodeFileReader langFile(ffs3::getResourceDir() + wxT("Languages") + ffs3::zToWx(common::FILE_NAME_SEPARATOR) + filename); + if (langFile.isOkay()) + { + //save encoding info: required by mo file generator + trans.insert(std::make_pair(wxEmptyString, wxT("Content-Type: text/plain; charset=UTF-8\n"))); + + int rowNumber = 0; + wxString original; + wxString tmpString; + while (langFile.getNextLine(tmpString)) + { + exchangeEscapeChars(tmpString); + + if (rowNumber++ % 2 == 0) + original = tmpString; + else + { + const wxString& translation = tmpString; + + if (!original.empty() && !translation.empty()) + trans.insert(std::make_pair(original, translation)); + } + } + } +} +} + + +#if wxCHECK_VERSION(2, 9, 1) +//this whole abomination is required to support language formats other than "mo" in wxWidgets v2.9 +class FFSTranslationLoader : public wxTranslationsLoader +{ +public: + static const wxString domainName() + { + return wxT("FFS"); + } + + FFSTranslationLoader(const TranslationMap& trans, wxLanguage langId) : langId_(langId) + { + //generate mo file: http://www.gnu.org/software/hello/manual/gettext/MO-Files.html + + std::string binaryStream; + + const size_t offsetTableOrig = sizeof(wxMsgCatalogHeader); + const size_t offsetTableTrans = offsetTableOrig + trans.size() * sizeof(wxMsgTableEntry); + const size_t offsetTableString = offsetTableTrans + trans.size() * sizeof(wxMsgTableEntry); + + wxMsgCatalogHeader header = + { + 0x950412de, //magic number (save in this machine's byte order) + 0, //revision + trans.size(), //numStrings + offsetTableOrig, //ofsOrigTable + offsetTableTrans, //ofsTransTable + 0, //nHashSize + 0, //ofsHashTable + }; + writeCobject(binaryStream, header); + + std::string tableOrig; + std::string tableTrans; + std::string stringsList; + for (TranslationMap::const_iterator i = trans.begin(); i != trans.end(); ++i) + { + +#ifndef _MSC_VER +#warning redundant UTF8 conversion!!! +#endif + std::string origString = i->first.ToUTF8(); + const wxMsgTableEntry origEntry = {origString.length(), offsetTableString + stringsList.size()}; + writeCobject(tableOrig, origEntry); + stringsList.append(origString.c_str(), origString.length() + 1); //include NULL-termination + +#ifndef _MSC_VER +#warning redundant UTF8 conversion!!! +#endif + std::string transString = i->second.ToUTF8(); + const wxMsgTableEntry transEntry = {transString.length(), offsetTableString + stringsList.size()}; + writeCobject(tableTrans, transEntry); + stringsList.append(transString.c_str(), transString.length() + 1); //include NULL-termination + } + binaryStream += tableOrig; + binaryStream += tableTrans; + binaryStream += stringsList; + + buffer = wxScopedCharBuffer::CreateOwned(static_cast<char*>(::malloc(binaryStream.size())), binaryStream.size()); //takes buffer ownership, calls ::free() + std::copy(binaryStream.begin(), binaryStream.end(), buffer.data()); + } + + virtual wxMsgCatalog* LoadCatalog(const wxString& domain, const wxString& lang) + { + if (domain != domainName() || lang != wxLocale::GetLanguageCanonicalName(langId_)) //avoid superfluous calls by wxWidgets framework + return NULL; + + return wxMsgCatalog::CreateFromData(buffer, domain); + } + + virtual wxArrayString GetAvailableTranslations(const wxString& domain) const + { + wxArrayString output; + if (domain == domainName()) + output.Add(wxLocale::GetLanguageCanonicalName(langId_)); + return output; + } + +private: + struct wxMsgTableEntry + { + boost::uint32_t nLen, // length of the string + ofsString; // pointer to the string + }; + + // header of a .mo file + struct wxMsgCatalogHeader + { + boost::uint32_t magic, // offset +00: magic id + revision, // +04: revision + numStrings, // +08: number of strings in the file + ofsOrigTable, // +0C: start of original string table + ofsTransTable, // +10: start of translated string table + nHashSize, // +14: hash table size + ofsHashTable; // +18: offset of hash table start + }; + + template <class T> + void writeCobject(std::string& str, T obj) + { + str.append(reinterpret_cast<const char*>(&obj), sizeof(obj)); + } + + wxScopedCharBuffer buffer; //raw data in mo file format + const wxLanguage langId_; +}; +#endif + + +CustomLocale& CustomLocale::getInstance() +{ + static CustomLocale instance; + return instance; +} + + +class Translation : public TranslationMap {}; + + +CustomLocale::CustomLocale() : + translationDB(new Translation), + currentLanguage(wxLANGUAGE_ENGLISH) +{ + Init(wxLANGUAGE_DEFAULT); //setting a different language needn't be supported on all systems! + + //actually these two parameters are language dependent, but we take system setting to handle all kinds of language derivations + const lconv* localInfo = localeconv(); + THOUSANDS_SEPARATOR = wxString::FromUTF8(localInfo->thousands_sep); + DECIMAL_POINT = wxString::FromUTF8(localInfo->decimal_point); + + // why not working? + // THOUSANDS_SEPARATOR = std::use_facet<std::numpunct<wchar_t> >(std::locale("")).thousands_sep(); + // DECIMAL_POINT = std::use_facet<std::numpunct<wchar_t> >(std::locale("")).decimal_point(); +} + + +CustomLocale::~CustomLocale() {} //non-inline destructor for std::auto_ptr to work with forward declaration + + void CustomLocale::setLanguage(int language) { - currentLanguage = language; + currentLanguage = static_cast<wxLanguage>(language); //default: english wxString languageFile; @@ -509,29 +665,8 @@ void CustomLocale::setLanguage(int language) translationDB->clear(); if (!languageFile.empty()) { - UnicodeFileReader langFile(ffs3::getResourceDir() + wxT("Languages") + - zToWx(common::FILE_NAME_SEPARATOR) + languageFile); - if (langFile.isOkay()) - { - int rowNumber = 0; - wxString original; - wxString tmpString; - while (langFile.getNextLine(tmpString)) - { - exchangeEscapeChars(tmpString); - - if (rowNumber++ % 2 == 0) - original = tmpString; - else - { - const wxString& translation = tmpString; - - if (!translation.empty()) - translationDB->insert(std::make_pair(original, translation)); - } - } - } - else + loadTranslation(languageFile, *translationDB); //empty translation on error + if (translationDB->empty()) { wxMessageBox(wxString(_("Error reading file:")) + wxT(" \"") + languageFile + wxT("\""), _("Error"), wxOK | wxICON_ERROR); currentLanguage = wxLANGUAGE_ENGLISH; //reset to english language to show this error just once @@ -539,6 +674,16 @@ void CustomLocale::setLanguage(int language) } else ; //if languageFile is empty texts will be english per default + + + +#if wxCHECK_VERSION(2, 9, 1) + wxTranslations::Set(new wxTranslations); + wxTranslations::Get()->SetLoader(new FFSTranslationLoader(*translationDB, currentLanguage)); //ownership passed + wxTranslations::Get()->SetLanguage(currentLanguage); + wxTranslations::Get()->AddCatalog(FFSTranslationLoader::domainName(), wxLANGUAGE_ENGLISH_US); + //... a little over design going on?!? +#endif } @@ -553,23 +698,3 @@ const wxChar* CustomLocale::GetString(const wxChar* szOrigString, const wxChar* return szOrigString; } - - -/* - -wxWidgets 2.9.1: - -class CustomTranslation : public wxTranslations -{ - virtual const wxString& GetString(const wxString& origString, - const wxString& domain = wxEmptyString) const - { - static const wxString blah = "map origString to translation by some arbitrary means"; - return blah; - } - - wxTranslations::Set(new CustomTranslation); - -}; - -*/ |