Skip to content

Commit

Permalink
Fix garbled translations in scripts due to parsing as Latin1 instead …
Browse files Browse the repository at this point in the history
…of UTF-8.

This appears to be a Qt5 bug.

Refs ticket:4380.
  • Loading branch information
Cyp committed May 21, 2016
1 parent b6baadb commit ee69d3a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/qtscript.cpp
Expand Up @@ -567,7 +567,7 @@ QScriptEngine *loadPlayerScript(QString path, int player, int difficulty)
engine->globalObject().setProperty("difficulty", (int)getDifficultyLevel(), QScriptValue::ReadOnly | QScriptValue::Undeletable);
}
//== \item[mapName] The name of the current map.
engine->globalObject().setProperty("mapName", game.map, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("mapName", QString(game.map), QScriptValue::ReadOnly | QScriptValue::Undeletable); // QString cast to work around bug in Qt5 QScriptValue(char *) constructor.
//== \item[baseType] The area name of the map.
QString tilesetType("CUSTOM");
if (strcmp(tilesetDir, "texpages/tertilesc1hw") == 0)
Expand Down
5 changes: 3 additions & 2 deletions src/qtscriptfuncs.cpp
Expand Up @@ -3103,7 +3103,8 @@ static QScriptValue js_allianceExistsBetween(QScriptContext *context, QScriptEng
//-- Mark string for translation.
static QScriptValue js_translate(QScriptContext *context, QScriptEngine *engine)
{
return QScriptValue(gettext(context->argument(0).toString().toUtf8().constData()));
// The redundant QString cast is a workaround for a Qt5 bug, the QScriptValue(char const *) constructor interprets as Latin1 instead of UTF-8!
return QScriptValue(QString(gettext(context->argument(0).toString().toUtf8().constData())));
}

//-- \subsection{playerPower(player)}
Expand Down Expand Up @@ -5121,7 +5122,7 @@ bool registerFunctions(QScriptEngine *engine, QString scriptName)
for (int i = 0; i < game.maxPlayers; i++)
{
QScriptValue vector = engine->newObject();
vector.setProperty("name", NetPlay.players[i].name, QScriptValue::ReadOnly | QScriptValue::Undeletable);
vector.setProperty("name", QString(NetPlay.players[i].name), QScriptValue::ReadOnly | QScriptValue::Undeletable); // QString cast to work around bug in Qt5 QScriptValue(char *) constructor.
vector.setProperty("difficulty", NetPlay.players[i].difficulty, QScriptValue::ReadOnly | QScriptValue::Undeletable);
vector.setProperty("colour", NetPlay.players[i].colour, QScriptValue::ReadOnly | QScriptValue::Undeletable);
vector.setProperty("position", NetPlay.players[i].position, QScriptValue::ReadOnly | QScriptValue::Undeletable);
Expand Down

0 comments on commit ee69d3a

Please sign in to comment.