diff --git a/binaries/data/mods/mod/globalscripts/l10n.js b/binaries/data/mods/mod/globalscripts/l10n.js index 34b2497138..9a3a176081 100644 --- a/binaries/data/mods/mod/globalscripts/l10n.js +++ b/binaries/data/mods/mod/globalscripts/l10n.js @@ -208,11 +208,22 @@ function translateObjectKeys(object, keys) { * So it may only be used on a plain string, * it won't have any effect on a calculated string. */ -function markForTranslation(message) { +function markForTranslation(message) +{ return message; } -function markForTranslationWithContext(context, message) { +function markForTranslationWithContext(context, message) +{ return message; } + +function markForPluralTranslation(singularMessage, pluralMessage, number) +{ + return { + "message": singularMessage, + "pluralMessage": pluralMessage, + "pluralCount": number + }; +} diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index 647bcfaa0c..6d3fa472e3 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -130,7 +130,10 @@ function updateBuildingPlacementPreview() { var message = result.message; if (result.translateMessage) - message = translate(message); + if (result.pluralMessage) + message = translatePlural(result.message, result.pluralMessage, result.pluralCount); + else + message = translate(message); var parameters = result.parameters; if (result.translateParameters) translateObjectKeys(parameters, result.translateParameters); diff --git a/binaries/data/mods/public/l10n/messages.json b/binaries/data/mods/public/l10n/messages.json index 7a5a7a2b37..d1e43ad7ea 100644 --- a/binaries/data/mods/public/l10n/messages.json +++ b/binaries/data/mods/public/l10n/messages.json @@ -41,7 +41,8 @@ "translateWithContext": [[1], 2], "translatePluralWithContext": [[1], 2, 3], "markForTranslation": [1], - "markForTranslationWithContext": [[1], 2] + "markForTranslationWithContext": [[1], 2], + "markForPluralTranslation": [1, 2] }, "commentTags": [ "Translation:" @@ -85,7 +86,8 @@ "translateWithContext": [[1], 2], "translatePluralWithContext": [[1], 2, 3], "markForTranslation": [1], - "markForTranslationWithContext": [[1], 2] + "markForTranslationWithContext": [[1], 2], + "markForPluralTranslation": [1, 2] }, "commentTags": [ "Translation:" @@ -137,7 +139,8 @@ "translateWithContext": [[1], 2], "translatePluralWithContext": [[1], 2, 3], "markForTranslation": [1], - "markForTranslationWithContext": [[1], 2] + "markForTranslationWithContext": [[1], 2], + "markForPluralTranslation": [1, 2] }, "commentTags": [ "Translation:" @@ -188,7 +191,8 @@ "translateWithContext": [[1], 2], "translatePluralWithContext": [[1], 2, 3], "markForTranslation": [1], - "markForTranslationWithContext": [[1], 2] + "markForTranslationWithContext": [[1], 2], + "markForPluralTranslation": [1, 2] }, "commentTags": [ "Translation:" @@ -250,7 +254,8 @@ "translateWithContext": [[1], 2], "translatePluralWithContext": [[1], 2, 3], "markForTranslation": [1], - "markForTranslationWithContext": [[1], 2] + "markForTranslationWithContext": [[1], 2], + "markForPluralTranslation": [1, 2] }, "commentTags": [ "Translation:" @@ -446,7 +451,8 @@ "translateWithContext": [[1], 2], "translatePluralWithContext": [[1], 2, 3], "markForTranslation": [1], - "markForTranslationWithContext": [[1], 2] + "markForTranslationWithContext": [[1], 2], + "markForPluralTranslation": [1, 2] }, "commentTags": [ "Translation:" @@ -547,7 +553,8 @@ "format": "javascript-format", "keywords": { "markForTranslation": [1], - "markForTranslationWithContext": [[1], 2] + "markForTranslationWithContext": [[1], 2], + "markForPluralTranslation": [1, 2] }, "commentTags": [ "Translation:" diff --git a/binaries/data/mods/public/simulation/components/BuildRestrictions.js b/binaries/data/mods/public/simulation/components/BuildRestrictions.js index 88406b2876..d2723872fb 100644 --- a/binaries/data/mods/public/simulation/components/BuildRestrictions.js +++ b/binaries/data/mods/public/simulation/components/BuildRestrictions.js @@ -69,6 +69,8 @@ BuildRestrictions.prototype.Init = function() * "parameters": parameters to use in the GUI message * "translateMessage": always true * "translateParameters": list of parameters to translate + * "pluralMessage": we might return a plural translation instead (optional) + * "pluralCount": plural translation argument (optional) * } * * Note: The entity which is used to check this should be a preview entity @@ -257,11 +259,20 @@ BuildRestrictions.prototype.CheckPlacement = function() var nearEnts = cmpRangeManager.ExecuteQuery(this.entity, 0, dist, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).filter(filter); if (nearEnts.length) { - result.message = markForTranslation("%(name)s too close to a %(category)s, must be at least %(distance)s meters away"); - result.parameters.category = cat; - result.translateParameters.push("category"); - result.parameters.distance = this.template.Distance.MinDistance; - return result; // Fail + var result = markForPluralTranslation( + "%(name)s too close to a %(category)s, must be at least 1 meter away", + "%(name)s too close to a %(category)s, must be at least %(distance)s meters away", + +this.template.Distance.MinDistance); + + result.success = false; + result.translateMessage = true; + result.parameters = { + "name": name, + "category": cat, + "distance": this.template.Distance.MinDistance + }; + result.translateParameters = ["name", "category"]; + return result; // Fail } } if (this.template.Distance.MaxDistance) @@ -270,10 +281,19 @@ BuildRestrictions.prototype.CheckPlacement = function() var nearEnts = cmpRangeManager.ExecuteQuery(this.entity, 0, dist, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions).filter(filter); if (!nearEnts.length) { - result.message = markForTranslation("%(name)s too far from a %(category)s, must be within %(distance)s meters"); - result.parameters.category = cat; - result.translateParameters.push("category"); - result.parameters.distance = this.template.Distance.MaxDistance; + var result = markForPluralTranslation( + "%(name)s too far from a %(category)s, must be within 1 meter", + "%(name)s too far from a %(category)s, must be within %(distance)s meters", + +this.template.Distance.MinDistance); + + result.success = false; + result.translateMessage = true; + result.parameters = { + "name": name, + "category": cat, + "distance": this.template.Distance.MaxDistance + }; + result.translateParameters = ["name", "category"]; return result; // Fail } } diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 56075b9d67..47a0c0e724 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -979,6 +979,8 @@ GuiInterface.prototype.DisplayRallyPoint = function(player, cmd) * "parameters": parameters to use in the message * "translateMessage": localisation info * "translateParameters": localisation info + * "pluralMessage": we might return a plural translation instead (optional) + * "pluralCount": localisation info (optional) * } */ GuiInterface.prototype.SetBuildingPlacementPreview = function(player, cmd)