diff --git a/bin/language-en.txt b/bin/language-en.txt index e8c2ba14..2a769903 100644 --- a/bin/language-en.txt +++ b/bin/language-en.txt @@ -1,7 +1,7 @@ Bridge Command Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms ok="OK" scnChoose="Please choose a scenario:" diff --git a/bin/language-es.txt b/bin/language-es.txt index 02cb6179..9bc2db63 100644 --- a/bin/language-es.txt +++ b/bin/language-es.txt @@ -1,7 +1,7 @@ Bridge Command Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms ok="OK" scnChoose="Seleccione un escenario:" diff --git a/bin/language-fr.txt b/bin/language-fr.txt index 47312598..20e571b2 100644 --- a/bin/language-fr.txt +++ b/bin/language-fr.txt @@ -1,7 +1,7 @@ Bridge Command Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms ok="OK" scnChoose="Veuillez choisir un scénario :" diff --git a/bin/languageController-en.txt b/bin/languageController-en.txt index 8023567f..95bfbefa 100644 --- a/bin/languageController-en.txt +++ b/bin/languageController-en.txt @@ -1,7 +1,7 @@ Map Controller Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms waiting = "Waiting..." startBC = "Please start the Bridge Command session. This computer's hostname and port is:" diff --git a/bin/languageController-es.txt b/bin/languageController-es.txt index 9cd529c7..0f0e21ae 100644 --- a/bin/languageController-es.txt +++ b/bin/languageController-es.txt @@ -1,7 +1,7 @@ Map Controller Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms waiting = "Espere..." startBC = "Abra una sesión de Bridge Command. El nombre y el puerto de este ordenador son:" diff --git a/bin/languageController-fr.txt b/bin/languageController-fr.txt index 42ef9eb9..c5d4ba5c 100644 --- a/bin/languageController-fr.txt +++ b/bin/languageController-fr.txt @@ -1,7 +1,7 @@ Map Controller Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms waiting = "Patientez..." startBC = "Veuillez démarrer la session Bridge Command. Le nom et le port de cet ordinateur sont :" diff --git a/bin/languageIniEditor-en.txt b/bin/languageIniEditor-en.txt index 72178827..c7e1e3c4 100644 --- a/bin/languageIniEditor-en.txt +++ b/bin/languageIniEditor-en.txt @@ -1,7 +1,7 @@ Ini Editor Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms name="Setting name" value="Setting value" diff --git a/bin/languageIniEditor-es.txt b/bin/languageIniEditor-es.txt index 5d7c6a62..7d38168f 100644 --- a/bin/languageIniEditor-es.txt +++ b/bin/languageIniEditor-es.txt @@ -1,7 +1,7 @@ Ini Editor Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms name="Nombre de la variáble" value="Valor de la variable" diff --git a/bin/languageIniEditor-fr.txt b/bin/languageIniEditor-fr.txt index a2cb6ec0..0491412a 100644 --- a/bin/languageIniEditor-fr.txt +++ b/bin/languageIniEditor-fr.txt @@ -1,7 +1,7 @@ Ini Editor Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms name="Nom du paramètre" value="Valeur du paramètre" diff --git a/bin/languageLauncher-en.txt b/bin/languageLauncher-en.txt index 8906bdfd..dffede4f 100644 --- a/bin/languageLauncher-en.txt +++ b/bin/languageLauncher-en.txt @@ -1,7 +1,7 @@ Launcher Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms startBC = "Start Bridge Command " startMC = "Map Controller " diff --git a/bin/languageLauncher-es.txt b/bin/languageLauncher-es.txt index 6a0596df..d7d2d423 100644 --- a/bin/languageLauncher-es.txt +++ b/bin/languageLauncher-es.txt @@ -1,7 +1,7 @@ Launcher Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms startBC = "Abrir Bridge Command " startMC = "Map Controller " diff --git a/bin/languageLauncher-fr.txt b/bin/languageLauncher-fr.txt index 6a45ffe9..bdb9670a 100644 --- a/bin/languageLauncher-fr.txt +++ b/bin/languageLauncher-fr.txt @@ -1,7 +1,7 @@ Launcher Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms startBC = "Démarrer Bridge Command " startMC = "Contrôleur de carte " diff --git a/bin/languageMultiplayer-en.txt b/bin/languageMultiplayer-en.txt index 57a9b0ac..c0dfacad 100644 --- a/bin/languageMultiplayer-en.txt +++ b/bin/languageMultiplayer-en.txt @@ -1,7 +1,7 @@ Multiplayer Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms scnChoose="Please choose a scenario:" hostname="Hostname (PC name) for each player.\nEntries should be comma separated." diff --git a/bin/languageMultiplayer-es.txt b/bin/languageMultiplayer-es.txt index 9bdc36c3..a7968752 100644 --- a/bin/languageMultiplayer-es.txt +++ b/bin/languageMultiplayer-es.txt @@ -1,7 +1,7 @@ Multiplayer Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms scnChoose="Elija un escenario:" hostname="Nombre del PC servidor para cada jugador.\nLas máquinas deben separarse por comas." diff --git a/bin/languageMultiplayer-fr.txt b/bin/languageMultiplayer-fr.txt index f2634116..a3ba3003 100644 --- a/bin/languageMultiplayer-fr.txt +++ b/bin/languageMultiplayer-fr.txt @@ -1,7 +1,7 @@ Multiplayer Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms scnChoose="Veuillez choisir un scénario :" hostname="Nom d'hôte (nom du PC) pour chaque joueur.\nLes entrées doivent être séparées par des virgules." diff --git a/bin/languageRepeater-en.txt b/bin/languageRepeater-en.txt index 56d026ad..938e79cc 100644 --- a/bin/languageRepeater-en.txt +++ b/bin/languageRepeater-en.txt @@ -1,7 +1,7 @@ Bridge Command Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms moveMessage="Please move this message box to the monitor where the repeater should run, and click OK" diff --git a/bin/languageRepeater-es.txt b/bin/languageRepeater-es.txt index 4ee5e6bd..d9914b39 100644 --- a/bin/languageRepeater-es.txt +++ b/bin/languageRepeater-es.txt @@ -1,7 +1,7 @@ Bridge Command Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms moveMessage="Mueva esta ventana al monitor donde quiera el repetidor y haga click sobre OK." diff --git a/bin/languageRepeater-fr.txt b/bin/languageRepeater-fr.txt index 5ea822bb..13309780 100644 --- a/bin/languageRepeater-fr.txt +++ b/bin/languageRepeater-fr.txt @@ -1,7 +1,7 @@ Bridge Command Language file. To translate, please change the part after the 'equals' symbol The characters \n will be replaced with a line break, so multiple lines of text are possible -This file must be saved with default (ANSI) encoding on Windows, and UTF-8 encoding on other platforms (Linux, OSX, ...) +This file must be saved with UTF-8 encoding on all platforms moveMessage="Veuillez déplacer cette fenêtre vers le moniteur où le répéteur doit être lancé, et cliquez sur OK." diff --git a/bin/macOScopy b/bin/macOScopy index 291fa390..bfbc917c 100755 --- a/bin/macOScopy +++ b/bin/macOScopy @@ -50,3 +50,9 @@ cp -a languageMultiplayer-fr.txt BridgeCommand.app/Contents/Resources/languageMu cp -a languageLauncher-fr.txt BridgeCommand.app/Contents/Resources/languageLauncher-fr.txt cp -a languageIniEditor-fr.txt BridgeCommand.app/Contents/Resources/languageIniEditor-fr.txt cp -a languageRepeater-fr.txt BridgeCommand.app/Contents/Resources/languageRepeater-fr.txt +cat language-es.txt | sed -E 's/Ctrl/Cmd/g' > BridgeCommand.app/Contents/Resources/language-es.txt +cp -a languageController-es.txt BridgeCommand.app/Contents/Resources/languageController-es.txt +cp -a languageMultiplayer-es.txt BridgeCommand.app/Contents/Resources/languageMultiplayer-es.txt +cp -a languageLauncher-es.txt BridgeCommand.app/Contents/Resources/languageLauncher-es.txt +cp -a languageIniEditor-es.txt BridgeCommand.app/Contents/Resources/languageIniEditor-es.txt +cp -a languageRepeater-es.txt BridgeCommand.app/Contents/Resources/languageRepeater-es.txt diff --git a/src/IniFile.cpp b/src/IniFile.cpp index ea5b7012..f39df5c5 100644 --- a/src/IniFile.cpp +++ b/src/IniFile.cpp @@ -36,26 +36,17 @@ class IniCache IniCache() = default; std::string getStringValue(const std::string &fileName, const std::string &key, const std::string &defValue = ""); - std::wstring getWStringValue(const std::string &fileName, const std::string &key, const std::wstring &defValue = L""); - irr::u32 getUIntValue(const std::string &fileName, const std::string &key, irr::u32 defValue = 0); irr::s32 getSIntValue(const std::string &fileName, const std::string &key, irr::s32 defValue = 0); irr::f32 getFloatValue(const std::string &fileName, const std::string &key, irr::f32 defValue = 0.f); private: bool readFile(const std::string &fileName); - - bool readWFile(const std::string &fileName); - -private: std::map> m_stringData; - std::map> m_wstringData; }; - static IniCache g_iniCache; - bool IniCache::readFile(const std::string& fileName) { if (m_stringData.find(fileName) != m_stringData.end()) { @@ -111,63 +102,6 @@ bool IniCache::readFile(const std::string& fileName) return true; } - -bool IniCache::readWFile(const std::string& fileName) -{ - if (m_stringData.find(fileName) != m_stringData.end()) { - return true; // file already read - } - - std::wifstream file(fileName.c_str()); - - //Set UTF-8 on Linux/OSX etc - #ifndef _WIN32 - try { - # ifdef __APPLE__ - char* thisLocale = setlocale(LC_ALL, ""); - if (thisLocale) { - file.imbue(std::locale(thisLocale)); - } - # else - file.imbue(std::locale("en_US.UTF8")); - # endif - } catch (const std::runtime_error& runtimeError) { - file.imbue(std::locale("")); - } - #endif - - if (!file.is_open()) { - if (IniFile::irrlichtLogger) { - std::string logMessage = "Unable to open file: "; - logMessage.append(fileName); - IniFile::irrlichtLogger->log(logMessage.c_str()); - } - else { - std::cerr << "Unable to open file " << fileName << std::endl; - } - return false; - } - - std::wstring line; - while ( std::getline (file,line) ) - { - const std::size_t equalsPos = line.find_first_of(L"="); - if (equalsPos != std::wstring::npos) { - std::wstring key = Utilities::trim(line.substr(0, equalsPos)); - std::wstring value = Utilities::trim(line.substr(equalsPos+1, std::wstring::npos)); - - Utilities::to_lower(key); - value = Utilities::trim(value, L"\""); - - m_wstringData[fileName][key] = value; - } - } - - file.close(); - return true; -} - - std::string IniCache::getStringValue(const std::string& fileName, const std::string& key, const std::string& defValue) { std::string keyLow = key; @@ -191,30 +125,6 @@ std::string IniCache::getStringValue(const std::string& fileName, const std::str return keyIt->second; } -std::wstring IniCache::getWStringValue(const std::string& fileName, const std::string& key, const std::wstring& defValue) -{ - std::wstring keyLow = std::wstring(key.begin(), key.end()); - Utilities::to_lower(keyLow); - - auto fileIt = m_wstringData.find(fileName); - if (fileIt == m_wstringData.end()) { - if (!readWFile(fileName)) { - // file not found - return defValue; - } - fileIt = m_wstringData.find(fileName); - assert(fileIt != m_wstringData.end()); - } - - const auto keyIt = fileIt->second.find(keyLow); - if (keyIt == (fileIt->second).end()) { - return defValue; - } - - return keyIt->second; - -} - irr::u32 IniCache::getUIntValue(const std::string& fileName, const std::string& key, irr::u32 defValue) { const std::string value = getStringValue(fileName, key, ""); @@ -290,11 +200,6 @@ namespace IniFile return g_iniCache.getStringValue(fileName, key, defValue); } - std::wstring iniFileToWString(const std::string &fileName, const std::string &key, const std::wstring &defValue) - { - return g_iniCache.getWStringValue(fileName, key, defValue); - } - //Load unsigned integer from an ini file irr::u32 iniFileTou32(const std::string &fileName, const std::string &key, irr::u32 defValue) { diff --git a/src/IniFile.hpp b/src/IniFile.hpp index 93c2f453..82ae85fe 100644 --- a/src/IniFile.hpp +++ b/src/IniFile.hpp @@ -28,8 +28,6 @@ namespace IniFile std::string enumerate2(std::string commandName, irr::s32 number1, irr::s32 number2); std::string iniFileToString(const std::string &fileName, const std::string &key, const std::string &defValue = ""); - std::wstring iniFileToWString(const std::string &fileName, const std::string &key, const std::wstring &defValue = L""); - irr::u32 iniFileTou32(const std::string &fileName, const std::string &key, irr::u32 defValue = 0); irr::s32 iniFileTos32(const std::string &fileName, const std::string &key, irr::s32 defValue = 0); irr::f32 iniFileTof32(const std::string &fileName, const std::string &key, irr::f32 defValue = 0.f); diff --git a/src/Lang.cpp b/src/Lang.cpp index 5588c10f..78cb5e76 100644 --- a/src/Lang.cpp +++ b/src/Lang.cpp @@ -18,6 +18,13 @@ #include "Lang.hpp" #include "IniFile.hpp" +#ifdef _WIN32 +// For UTF8 to ANSI conversion +#include +#include +#include +#endif // _WIN32 + //using namespace irr; Lang::Lang(std::string language) @@ -28,9 +35,9 @@ Lang::Lang(std::string language) irr::core::stringw Lang::translate(std::string phraseName) { //Look up - std::wstring translatedPhrase = IniFile::iniFileToWString(languageFileName, phraseName); + std::string translatedPhrase = IniFile::iniFileToString(languageFileName, phraseName); //Fall back - if (translatedPhrase==L"") { + if (translatedPhrase=="") { if (phraseName == "deg") { //FIXME: Temp fix for the degree symbol, while utf-8 isn't properly sorted on all platforms wchar_t degSymbolChar = 176; @@ -39,21 +46,32 @@ irr::core::stringw Lang::translate(std::string phraseName) return degSymbolString; } else { std::cout << "Translation for " << phraseName << " not found in " << languageFileName << std::endl; - translatedPhrase = std::wstring(phraseName.begin(), phraseName.end()); + translatedPhrase = phraseName; } } //Convert '\n' characters within string to a newline - based on http://stackoverflow.com/a/24315631 size_t start_pos = 0; - std::wstring from = L"\\n"; - std::wstring to = L"\n"; - while((start_pos = translatedPhrase.find(from, start_pos)) != std::wstring::npos) { + std::string from = "\\n"; + std::string to = "\n"; + while((start_pos = translatedPhrase.find(from, start_pos)) != std::string::npos) { translatedPhrase.replace(start_pos, from.length(), to); start_pos += to.length(); // Handles case where 'to' is a substring of 'from' } +#ifdef _WIN32 + // If Windows, convert the UTF8 string to ANSI: + std::wstring_convert> wconv; + std::wstring wstr = wconv.from_bytes(translatedPhrase); + // wstring to string + std::vector buf(wstr.size()); + std::use_facet>(std::locale(".1252")).narrow(wstr.data(), wstr.data() + wstr.size(), '?', buf.data()); + translatedPhrase = std::string(buf.data(), buf.size()); +#endif + //convert to stringw - irr::core::stringw returnPhrase(translatedPhrase.c_str()); + irr::core::stringw returnPhrase; + irr::core::multibyteToWString(returnPhrase, translatedPhrase.c_str()); return returnPhrase; }