diff options
Diffstat (limited to 'library/localization.cpp')
-rw-r--r-- | library/localization.cpp | 208 |
1 files changed, 141 insertions, 67 deletions
diff --git a/library/localization.cpp b/library/localization.cpp index ef433012..9b5918a8 100644 --- a/library/localization.cpp +++ b/library/localization.cpp @@ -1,25 +1,134 @@ -#include "localization.h" +#include "localization.h" #include <wx/msgdlg.h> -#include "resources.h" +#include "../structures.h" #include "globalFunctions.h" #include <fstream> #include <set> +#include <map> +#include "resources.h" + +using FreeFileSync::CustomLocale; +using FreeFileSync::LocalizationInfo; //_("Browse") <- dummy string for wxDirPickerCtrl to be recognized by automatic text extraction! -struct TranslationLine +const std::vector<FreeFileSync::LocInfoLine>& LocalizationInfo::getMapping() { - wxString original; - wxString translation; + static LocalizationInfo instance; + return instance.locMapping; +} - bool operator<(const TranslationLine& b) const - { - return (original < b.original); - } -}; -class Translation : public std::set<TranslationLine> {}; +LocalizationInfo::LocalizationInfo() +{ + FreeFileSync::LocInfoLine newEntry; + + newEntry.languageID = wxLANGUAGE_GERMAN; + newEntry.languageName = wxT("Deutsch"); + newEntry.languageFile = "Languages/german.lng"; + newEntry.translatorName = wxT("ZenJu"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapGermany; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_ENGLISH; + newEntry.languageName = wxT("English"); + newEntry.languageFile = ""; + newEntry.translatorName = wxT("ZenJu"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapEngland; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_SPANISH; + newEntry.languageName = wxT("Español"); + newEntry.languageFile = "Languages/spanish.lng"; + newEntry.translatorName = wxT("David Rodríguez"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapSpain; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_FRENCH; + newEntry.languageName = wxT("Français"); + newEntry.languageFile = "Languages/french.lng"; + newEntry.translatorName = wxT("Jean-François Hartmann"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapFrance; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_ITALIAN; + newEntry.languageName = wxT("Italiano"); + newEntry.languageFile = "Languages/italian.lng"; + newEntry.translatorName = wxT("Emmo"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapItaly; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_HUNGARIAN; + newEntry.languageName = wxT("Magyar"); + newEntry.languageFile = "Languages/hungarian.lng"; + newEntry.translatorName = wxT("Demon"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapHungary; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_DUTCH; + newEntry.languageName = wxT("Nederlands"); + newEntry.languageFile = "Languages/dutch.lng"; + newEntry.translatorName = wxT("M.D. Vrakking"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapHolland; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_RUSSIAN; + newEntry.languageName = wxT("Pусский язык"); + newEntry.languageFile = "Languages/russian.lng"; + newEntry.translatorName = wxT("Svobodniy"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapRussia; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_POLISH; + newEntry.languageName = wxT("Polski"); + newEntry.languageFile = "Languages/polish.lng"; + newEntry.translatorName = wxT("Wojtek Pietruszewski"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapPoland; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_PORTUGUESE; + newEntry.languageName = wxT("Português"); + newEntry.languageFile = "Languages/portuguese.lng"; + newEntry.translatorName = wxT("QuestMark"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapPortugal; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_PORTUGUESE_BRAZILIAN; + newEntry.languageName = wxT("Português do Brasil"); + newEntry.languageFile = "Languages/portuguese_br.lng"; + newEntry.translatorName = wxT("Edison Aranha"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapBrazil; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_SLOVENIAN; + newEntry.languageName = wxT("Slovenščina"); + newEntry.languageFile = "Languages/slovenian.lng"; + newEntry.translatorName = wxT("Matej Badalic"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapSlovakia; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_JAPANESE; + newEntry.languageName = wxT("日本語"); + newEntry.languageFile = "Languages/japanese.lng"; + newEntry.translatorName = wxT("Tilt"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapJapan; + locMapping.push_back(newEntry); + + newEntry.languageID = wxLANGUAGE_CHINESE_SIMPLIFIED; + newEntry.languageName = wxT("简体中文"); + newEntry.languageFile = "Languages/chinese_simple.lng"; + newEntry.translatorName = wxT("Misty Wu"); + newEntry.languageFlag = GlobalResources::getInstance().bitmapChina; + locMapping.push_back(newEntry); +} + + + +typedef wxString TextOriginal; +typedef wxString TextTranslation; + +class Translation : public std::map<TextOriginal, TextTranslation> {}; CustomLocale::CustomLocale() : @@ -83,51 +192,19 @@ void exchangeEscapeChars(wxString& data) void CustomLocale::setLanguage(const int language) { - currentLanguage = language; - + //default: english std::string languageFile; - switch (language) - { - case wxLANGUAGE_CHINESE_SIMPLIFIED: - languageFile = "Languages/chinese_simple.lng"; - break; - case wxLANGUAGE_DUTCH: - languageFile = "Languages/dutch.lng"; - break; - case wxLANGUAGE_FRENCH: - languageFile = "Languages/french.lng"; - break; - case wxLANGUAGE_GERMAN: - languageFile = "Languages/german.lng"; - break; - case wxLANGUAGE_HUNGARIAN: - languageFile = "Languages/hungarian.lng"; - break; - case wxLANGUAGE_ITALIAN: - languageFile = "Languages/italian.lng"; - break; - case wxLANGUAGE_JAPANESE: - languageFile = "Languages/japanese.lng"; - break; - case wxLANGUAGE_POLISH: - languageFile = "Languages/polish.lng"; - break; - case wxLANGUAGE_PORTUGUESE: - languageFile = "Languages/portuguese.lng"; - break; - case wxLANGUAGE_PORTUGUESE_BRAZILIAN: - languageFile = "Languages/portuguese_br.lng"; - break; - case wxLANGUAGE_SLOVENIAN: - languageFile = "Languages/slovenian.lng"; - break; - case wxLANGUAGE_SPANISH: - languageFile = "Languages/spanish.lng"; - break; - default: - languageFile.clear(); - currentLanguage = wxLANGUAGE_ENGLISH; - } + currentLanguage = wxLANGUAGE_ENGLISH; + + //(try to) retrieve language filename + for (std::vector<LocInfoLine>::const_iterator i = LocalizationInfo::getMapping().begin(); i != LocalizationInfo::getMapping().end(); ++i) + if (language == i->languageID) + { + languageFile = i->languageFile; + currentLanguage = i->languageID; + break; + } + static bool initialized = false; //wxLocale is a static global too! if (!initialized) @@ -145,7 +222,7 @@ void CustomLocale::setLanguage(const int language) std::ifstream langFile(languageFile.c_str(), std::ios::binary); if (langFile) { - TranslationLine currentLine; + wxString original; //Delimiter: //---------- @@ -162,39 +239,36 @@ void CustomLocale::setLanguage(const int language) exchangeEscapeChars(formattedString); if (rowNumber%2 == 0) - currentLine.original = formattedString; + original = formattedString; else { if (!formattedString.empty()) { - currentLine.translation = formattedString; - translationDB->insert(currentLine); + const wxString translation = formattedString; + translationDB->insert(std::pair<TextOriginal, TextTranslation>(original, translation)); } } } langFile.close(); } else - wxMessageBox(wxString(_("Error reading file:")) + wxT(" \"") + wxString(languageFile.c_str(), wxConvUTF8) + wxT("\""), _("An exception occured!"), wxOK | wxICON_ERROR); + wxMessageBox(wxString(_("Error reading file:")) + wxT(" \"") + wxString(languageFile.c_str(), wxConvUTF8) + wxT("\""), _("Error"), wxOK | wxICON_ERROR); } else ; //if languageFile is empty texts will be english per default //these global variables need to be redetermined on language selection - GlobalResources::DECIMAL_POINT = _("."); - GlobalResources::THOUSANDS_SEPARATOR = _(","); + FreeFileSync::DECIMAL_POINT = _("."); + FreeFileSync::THOUSANDS_SEPARATOR = _(","); } const wxChar* CustomLocale::GetString(const wxChar* szOrigString, const wxChar* szDomain) const { - TranslationLine currentLine; - currentLine.original = szOrigString; - //look for translation in buffer table - const Translation::iterator i = translationDB->find(currentLine); + const Translation::const_iterator i = translationDB->find(szOrigString); if (i != translationDB->end()) - return i->translation.c_str(); + return i->second.c_str(); //fallback return szOrigString; |