Some i18n fixed on the JavaScript side

Do not try to translate empty strings in translateObjectKeys().
Do not try to translate empty formation tooltips.
Do not translate player names at a point where they are already
translated.

This was SVN commit r15005.
This commit is contained in:
Adrián Chaves 2014-04-26 18:27:53 +00:00
parent f5b0fc1076
commit 4770e64449
3 changed files with 17 additions and 5 deletions

View File

@ -3,6 +3,18 @@ var g_pluralTranslations = {};
var g_translationsWithContext = {};
var g_pluralTranslationsWithContext = {};
// Checks if the specified variable is a string, and if it is, it checks that it
// is not empty.
function isNonEmptyString(variable)
{
if (typeof variable != "string")
return false;
else if (variable.trim())
return true;
else
return false;
}
// Translates the specified English message into the current language.
//
// This function relies on the g_translations cache when possible. You should use this function instead of
@ -157,7 +169,7 @@ function translateObjectKeys(object, keys) {
{
if (keys.indexOf(property) > -1)
{
if (typeof object[property] == "string")
if (isNonEmptyString(object[property]))
object[property] = translate(object[property]);
else if (object[property] instanceof Object)
{
@ -177,7 +189,7 @@ function translateObjectKeys(object, keys) {
{
if (property in keys)
{
if (typeof object[property] == "string")
if (isNonEmptyString(object[property]))
if (keys[property])
object[property] = translateWithContext(keys[property], object[property]);
else

View File

@ -633,8 +633,8 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, playerState, items, c
{
grayscale = "grayscale:";
// Display a meaningful tooltip why the formation is disabled
button.tooltip += "\n" + "[color=\"red\"]" + translate(formationInfo.tooltip) + "[/color]";
if (formationInfo.tooltip)
button.tooltip += "\n" + "[color=\"red\"]" + translate(formationInfo.tooltip) + "[/color]";
}
var formationSelected = Engine.GuiInterfaceCall("IsFormationSelected", {

View File

@ -45,7 +45,7 @@ function getPlayerData(playerAssignments)
{
var playerState = simState.players[i];
var name = translate(playerState.name);
var name = playerState.name;
var civ = playerState.civ;
var color = {
"r": playerState.colour.r*255,