diff --git a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs index 3e88924c04..5922fcdc4b 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/GeneralProperties.cs @@ -185,8 +185,10 @@ namespace OpenRA.Mods.Common.Scripting get { var tooltip = tooltips.FirstEnabledConditionalTraitOrDefault(); + if (tooltip == null) + return null; - return tooltip?.Info.Name; + return TranslationProvider.GetString(tooltip.Info.Name); } } diff --git a/OpenRA.Mods.Common/Traits/Buildable.cs b/OpenRA.Mods.Common/Traits/Buildable.cs index 8c0042d806..3ee742f35b 100644 --- a/OpenRA.Mods.Common/Traits/Buildable.cs +++ b/OpenRA.Mods.Common/Traits/Buildable.cs @@ -56,7 +56,8 @@ namespace OpenRA.Mods.Common.Traits public readonly int BuildPaletteOrder = 9999; [Desc("Text shown in the production tooltip.")] - public readonly string Description = ""; + [TranslationReference(optional: true)] + public readonly string Description; public static string GetInitialFaction(ActorInfo ai, string defaultFaction) { diff --git a/OpenRA.Mods.Common/Traits/Encyclopedia.cs b/OpenRA.Mods.Common/Traits/Encyclopedia.cs index 232b6ad312..51e11c29b5 100644 --- a/OpenRA.Mods.Common/Traits/Encyclopedia.cs +++ b/OpenRA.Mods.Common/Traits/Encyclopedia.cs @@ -16,7 +16,8 @@ namespace OpenRA.Mods.Common.Traits public class EncyclopediaInfo : TraitInfo { [Desc("Explains the purpose in the in-game encyclopedia.")] - public readonly string Description = null; + [TranslationReference] + public readonly string Description; [Desc("Number for ordering the list.")] public readonly int Order; diff --git a/OpenRA.Mods.Common/Traits/Tooltip.cs b/OpenRA.Mods.Common/Traits/Tooltip.cs index 1be99cafc1..1abb4be26b 100644 --- a/OpenRA.Mods.Common/Traits/Tooltip.cs +++ b/OpenRA.Mods.Common/Traits/Tooltip.cs @@ -15,7 +15,8 @@ namespace OpenRA.Mods.Common.Traits { public abstract class TooltipInfoBase : ConditionalTraitInfo, Requires { - public readonly string Name = ""; + [TranslationReference] + public readonly string Name; } [Desc("Shown in map editor.")] @@ -29,19 +30,23 @@ namespace OpenRA.Mods.Common.Traits { [Desc("An optional generic name (i.e. \"Soldier\" or \"Structure\")" + "to be shown to chosen players.")] - public readonly string GenericName = null; + [TranslationReference(optional: true)] + public readonly string GenericName; [Desc("Prefix generic tooltip name with 'Ally/Neutral/EnemyPrefix'.")] public readonly bool GenericStancePrefix = true; [Desc("Prefix to display in the tooltip for allied units.")] - public readonly string AllyPrefix = "Allied"; + [TranslationReference(optional: true)] + public readonly string AllyPrefix = "label-tooltip-prefix.ally"; [Desc("Prefix to display in the tooltip for neutral units.")] - public readonly string NeutralPrefix = null; + [TranslationReference(optional: true)] + public readonly string NeutralPrefix; [Desc("Prefix to display in the tooltip for enemy units.")] - public readonly string EnemyPrefix = "Enemy"; + [TranslationReference(optional: true)] + public readonly string EnemyPrefix = "label-tooltip-prefix.enemy"; [Desc("Player stances that the generic name should be shown to.")] public readonly PlayerRelationship GenericVisibility = PlayerRelationship.None; @@ -54,18 +59,22 @@ namespace OpenRA.Mods.Common.Traits public string TooltipForPlayerStance(PlayerRelationship relationship) { if (relationship == PlayerRelationship.None || !GenericVisibility.HasRelationship(relationship)) - return Name; + return TranslationProvider.GetString(Name); - if (GenericStancePrefix && !string.IsNullOrEmpty(AllyPrefix) && relationship == PlayerRelationship.Ally) - return AllyPrefix + " " + GenericName; + var genericName = string.IsNullOrEmpty(GenericName) ? "" : TranslationProvider.GetString(GenericName); + if (GenericStancePrefix) + { + if (!string.IsNullOrEmpty(AllyPrefix) && relationship == PlayerRelationship.Ally) + return TranslationProvider.GetString(AllyPrefix) + " " + genericName; - if (GenericStancePrefix && !string.IsNullOrEmpty(NeutralPrefix) && relationship == PlayerRelationship.Neutral) - return NeutralPrefix + " " + GenericName; + if (!string.IsNullOrEmpty(NeutralPrefix) && relationship == PlayerRelationship.Neutral) + return TranslationProvider.GetString(NeutralPrefix) + " " + genericName; - if (GenericStancePrefix && !string.IsNullOrEmpty(EnemyPrefix) && relationship == PlayerRelationship.Enemy) - return EnemyPrefix + " " + GenericName; + if (!string.IsNullOrEmpty(EnemyPrefix) && relationship == PlayerRelationship.Enemy) + return TranslationProvider.GetString(EnemyPrefix) + " " + genericName; + } - return GenericName; + return genericName; } public bool IsOwnerRowVisible => ShowOwnerRow; diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index 736e3ee333..5bd1393485 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits public readonly SelectionBoxAnnotationRenderable SelectionBox; public string Tooltip => - (tooltip == null ? " < " + Info.Name + " >" : tooltip.Name) + "\n" + Owner.Name + " (" + Owner.Faction + ")" + (tooltip == null ? " < " + Info.Name + " >" : TranslationProvider.GetString(tooltip.Name)) + "\n" + Owner.Name + " (" + Owner.Faction + ")" + "\nID: " + ID + "\nType: " + Info.Name; public string Type => reference.Type; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs index e285c4dabe..11f35a4ac8 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs @@ -111,13 +111,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic var tooltip = a.TraitInfos().FirstOrDefault(ti => ti.EnabledByDefault) as TooltipInfoBase ?? a.TraitInfos().FirstOrDefault(ti => ti.EnabledByDefault); + var actorType = TranslationProvider.GetString(ActorTypeTooltip, Translation.Arguments("actorType", a.Name)); + var searchTerms = new List() { a.Name }; if (tooltip != null) - searchTerms.Add(tooltip.Name); - - var actorType = TranslationProvider.GetString(ActorTypeTooltip, Translation.Arguments("actorType", a.Name)); - var tooltipText = tooltip == null ? actorType : tooltip.Name + $"\n{actorType}"; - allActorsTemp.Add(new ActorSelectorActor(a, editorData.Categories, searchTerms.ToArray(), tooltipText)); + { + var actorName = TranslationProvider.GetString(tooltip.Name); + searchTerms.Add(actorName); + allActorsTemp.Add(new ActorSelectorActor(a, editorData.Categories, searchTerms.ToArray(), actorName + $"\n{actorType}")); + } + else + allActorsTemp.Add(new ActorSelectorActor(a, editorData.Categories, searchTerms.ToArray(), actorType)); } allActors = allActorsTemp.ToArray(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs index eec50c2e22..7fa8511c7b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs @@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = item.Get("TITLE"); var name = actor.TraitInfoOrDefault()?.Name; if (!string.IsNullOrEmpty(name)) - WidgetUtils.TruncateLabelToTooltip(label, name); + WidgetUtils.TruncateLabelToTooltip(label, TranslationProvider.GetString(name)); if (firstItem == null) { @@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var info = actor.TraitInfoOrDefault(); if (info != null && !string.IsNullOrEmpty(info.Description)) - text += WidgetUtils.WrapText(info.Description.Replace("\\n", "\n") + "\n\n", descriptionLabel.Bounds.Width, descriptionFont); + text += WidgetUtils.WrapText(TranslationProvider.GetString(info.Description) + "\n\n", descriptionLabel.Bounds.Width, descriptionFont); var height = descriptionFont.Measure(text).Y; descriptionLabel.Text = text; @@ -175,7 +175,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var actorTooltip = actor.TraitInfos().FirstOrDefault(info => info.EnabledByDefault); if (actorTooltip != null) - return actorTooltip.Name; + return TranslationProvider.GetString(actorTooltip.Name); } return name; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ArmyTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ArmyTooltipLogic.cs index a9ad948a32..fe37ecb5db 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ArmyTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ArmyTooltipLogic.cs @@ -38,15 +38,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic return; var tooltip = armyUnit.TooltipInfo; - var name = tooltip?.Name ?? armyUnit.ActorInfo.Name; + var name = tooltip != null ? TranslationProvider.GetString(tooltip.Name) : armyUnit.ActorInfo.Name; var buildable = armyUnit.BuildableInfo; nameLabel.Text = name; var nameSize = font.Measure(name); - descLabel.Text = buildable.Description.Replace("\\n", "\n"); - var descSize = descFont.Measure(descLabel.Text); + var desc = string.IsNullOrEmpty(buildable.Description) ? "" : TranslationProvider.GetString(buildable.Description); + descLabel.Text = desc; + var descSize = descFont.Measure(desc); descLabel.Bounds.Width = descSize.X; descLabel.Bounds.Height = descSize.Y + descLabelPadding; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs index 0014edf3fb..f3d8ce130c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return; var tooltip = actor.TraitInfos().FirstOrDefault(info => info.EnabledByDefault); - var name = tooltip?.Name ?? actor.Name; + var name = tooltip != null ? TranslationProvider.GetString(tooltip.Name) : actor.Name; var buildable = actor.TraitInfo(); var cost = 0; @@ -137,8 +137,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic costLabel.GetColor = () => pr.GetCashAndResources() >= cost ? Color.White : Color.Red; var costSize = font.Measure(costLabel.Text); - descLabel.Text = buildable.Description.Replace("\\n", "\n"); - var descSize = descFont.Measure(descLabel.Text); + var desc = string.IsNullOrEmpty(buildable.Description) ? "" : TranslationProvider.GetString(buildable.Description); + descLabel.Text = desc; + var descSize = descFont.Measure(desc); descLabel.Bounds.Width = descSize.X; descLabel.Bounds.Height = descSize.Y + descLabelPadding; @@ -170,7 +171,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { var actorTooltip = ai.TraitInfos().FirstOrDefault(info => info.EnabledByDefault); if (actorTooltip != null) - return actorTooltip.Name; + return TranslationProvider.GetString(actorTooltip.Name); } return a; diff --git a/mods/common/languages/rules/en.ftl b/mods/common/languages/rules/en.ftl index 8dbae62edb..d12925e351 100644 --- a/mods/common/languages/rules/en.ftl +++ b/mods/common/languages/rules/en.ftl @@ -54,3 +54,8 @@ dropdown-starting-units = dropdown-time-limit = .label = Time Limit .description = Player or team with the highest score after this time wins + +## Tooltip +label-tooltip-prefix = + .ally = Ally + .enemy = Enemy