Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/language-en.txt
Original file line number Diff line number Diff line change
@@ -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:"
Expand Down
2 changes: 1 addition & 1 deletion bin/language-es.txt
Original file line number Diff line number Diff line change
@@ -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:"
Expand Down
2 changes: 1 addition & 1 deletion bin/language-fr.txt
Original file line number Diff line number Diff line change
@@ -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 :"
Expand Down
2 changes: 1 addition & 1 deletion bin/languageController-en.txt
Original file line number Diff line number Diff line change
@@ -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:"
Expand Down
2 changes: 1 addition & 1 deletion bin/languageController-es.txt
Original file line number Diff line number Diff line change
@@ -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:"
Expand Down
2 changes: 1 addition & 1 deletion bin/languageController-fr.txt
Original file line number Diff line number Diff line change
@@ -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 :"
Expand Down
2 changes: 1 addition & 1 deletion bin/languageIniEditor-en.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/languageIniEditor-es.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/languageIniEditor-fr.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/languageLauncher-en.txt
Original file line number Diff line number Diff line change
@@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion bin/languageLauncher-es.txt
Original file line number Diff line number Diff line change
@@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion bin/languageLauncher-fr.txt
Original file line number Diff line number Diff line change
@@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion bin/languageMultiplayer-en.txt
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 1 addition & 1 deletion bin/languageMultiplayer-es.txt
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 1 addition & 1 deletion bin/languageMultiplayer-fr.txt
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 1 addition & 1 deletion bin/languageRepeater-en.txt
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion bin/languageRepeater-es.txt
Original file line number Diff line number Diff line change
@@ -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."

Expand Down
2 changes: 1 addition & 1 deletion bin/languageRepeater-fr.txt
Original file line number Diff line number Diff line change
@@ -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."

Expand Down
6 changes: 6 additions & 0 deletions bin/macOScopy
Original file line number Diff line number Diff line change
Expand Up @@ -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
95 changes: 0 additions & 95 deletions src/IniFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::map<std::string, std::string>> m_stringData;
std::map<std::string, std::map<std::wstring, std::wstring>> m_wstringData;
};


static IniCache g_iniCache;


bool IniCache::readFile(const std::string& fileName)
{
if (m_stringData.find(fileName) != m_stringData.end()) {
Expand Down Expand Up @@ -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;
Expand All @@ -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, "");
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions src/IniFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 25 additions & 7 deletions src/Lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
#include "Lang.hpp"
#include "IniFile.hpp"

#ifdef _WIN32
// For UTF8 to ANSI conversion
#include <codecvt>
#include <locale>
#include <vector>
#endif // _WIN32

//using namespace irr;

Lang::Lang(std::string language)
Expand All @@ -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;
Expand All @@ -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<std::codecvt_utf8<wchar_t>> wconv;
std::wstring wstr = wconv.from_bytes(translatedPhrase);
// wstring to string
std::vector<char> buf(wstr.size());
std::use_facet<std::ctype<wchar_t>>(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;
}
Loading