From 6e6bf1ca812ad2e7d78b5283794e4129621dd000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 8 May 2023 15:56:04 +0200 Subject: [PATCH] Translate labels with parameters. --- .../Widgets/Logic/Ingame/IngameCashCounterLogic.cs | 5 +---- .../Widgets/Logic/Ingame/ProductionTooltipLogic.cs | 6 ++++-- OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs | 8 +++++++- .../Widgets/Logic/Settings/HotkeysSettingsLogic.cs | 12 ++++++++++-- mods/cnc/chrome/dialogs.yaml | 1 - mods/cnc/chrome/ingame.yaml | 2 -- mods/cnc/chrome/settings-hotkeys.yaml | 2 -- mods/cnc/chrome/tooltips.yaml | 2 -- mods/common/chrome/connection.yaml | 2 -- mods/common/chrome/dropdowns.yaml | 1 - mods/common/chrome/settings-hotkeys.yaml | 2 -- mods/common/chrome/tooltips.yaml | 1 - mods/common/languages/en.ftl | 8 ++++++++ mods/d2k/chrome/dropdowns.yaml | 1 - mods/d2k/chrome/ingame-player.yaml | 2 -- mods/d2k/chrome/tooltips.yaml | 1 - mods/ra/chrome/ingame-player.yaml | 2 -- mods/ts/chrome/dropdowns.yaml | 1 - mods/ts/chrome/ingame-player.yaml | 2 -- mods/ts/chrome/settings-hotkeys.yaml | 2 -- 20 files changed, 30 insertions(+), 33 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs index eae08ad7da..e1f13212f2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs @@ -28,7 +28,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly PlayerResources playerResources; readonly LabelWithTooltipWidget cashLabel; readonly CachedTransform<(int Resources, int Capacity), string> siloUsageTooltipCache; - readonly string cashTemplate; int nextCashTickTime = 0; int displayResources; @@ -47,8 +46,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic TranslationProvider.GetString(SiloUsage, Translation.Arguments("usage", x.Resources, "capacity", x.Capacity))); cashLabel = widget.Get("CASH"); cashLabel.GetTooltipText = () => siloUsageTooltip; - - cashTemplate = cashLabel.Text; } public override void Tick() @@ -80,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } siloUsageTooltip = siloUsageTooltipCache.Update((playerResources.Resources, playerResources.ResourceCapacity)); - cashLabel.Text = string.Format(cashTemplate, displayResources); + cashLabel.Text = displayResources.ToString(); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs index f5f91ec1a1..19bf3cde1e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs @@ -19,6 +19,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class ProductionTooltipLogic : ChromeLogic { + [TranslationReference("prequisites")] + const string Requires = "label-requires"; + [ObjectCreator.UseCtor] public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Player player, Func getTooltipIcon) { @@ -45,7 +48,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic var descFont = Game.Renderer.Fonts[descLabel.Font]; var requiresFont = Game.Renderer.Fonts[requiresLabel.Font]; var formatBuildTime = new CachedTransform(time => WidgetUtils.FormatTime(time, world.Timestep)); - var requiresFormat = requiresLabel.Text; ActorInfo lastActor = null; var lastHotkey = Hotkey.Invalid; @@ -100,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var requiresSize = int2.Zero; if (prereqs.Any()) { - requiresLabel.Text = string.Format(requiresFormat, prereqs.JoinWith(", ")); + requiresLabel.Text = TranslationProvider.GetString(Requires, Translation.Arguments("prequisites", prereqs.JoinWith(", "))); requiresSize = requiresFont.Measure(requiresLabel.Text); requiresLabel.Visible = true; descLabel.Bounds.Y = descLabelY + requiresLabel.Bounds.Height; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index c2a0c957eb..53661dd605 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -31,6 +31,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic [TranslationReference("message")] const string NewsParsingFailed = "label-news-parsing-failed"; + [TranslationReference("author", "datetime")] + const string AuthorDateTime = "label-author-datetime"; + protected enum MenuType { Main, Singleplayer, Extras, MapEditor, StartupPrompts, None } protected enum MenuPanel { None, Missions, Skirmish, Multiplayer, MapEditor, Replays, GameSaves } @@ -425,7 +428,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic titleLabel.GetText = () => item.Title; var authorDateTimeLabel = newsItem.Get("AUTHOR_DATETIME"); - var authorDateTime = string.Format(authorDateTimeLabel.Text, item.Author, item.DateTime.ToLocalTime()); + var authorDateTime = TranslationProvider.GetString(AuthorDateTime, Translation.Arguments( + "author", item.Author, + "datetime", item.DateTime.ToLocalTime().ToString())); + authorDateTimeLabel.GetText = () => authorDateTime; var contentLabel = newsItem.Get("CONTENT"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs index 5dfb7c7ba8..b364cbf041 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs @@ -19,6 +19,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class HotkeysSettingsLogic : ChromeLogic { + [TranslationReference("key")] + const string OriginalNotice = "label-original-notice"; + + [TranslationReference("key", "context")] + const string DuplicateNotice = "label-duplicate-notice"; + readonly ModData modData; readonly Dictionary logicArgs; @@ -220,14 +226,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic duplicateNotice.IsVisible = () => !isHotkeyValid; var duplicateNoticeText = new CachedTransform(hd => hd != null ? - string.Format(duplicateNotice.Text, hd.Description, hd.Contexts.First(c => selectedHotkeyDefinition.Contexts.Contains(c))) : + TranslationProvider.GetString(DuplicateNotice, Translation.Arguments("key", hd.Description, + "context", hd.Contexts.First(c => selectedHotkeyDefinition.Contexts.Contains(c)))) : ""); duplicateNotice.GetText = () => duplicateNoticeText.Update(duplicateHotkeyDefinition); var originalNotice = panel.Get("ORIGINAL_NOTICE"); originalNotice.TextColor = ChromeMetrics.Get("NoticeInfoColor"); originalNotice.IsVisible = () => isHotkeyValid && !isHotkeyDefault; - var originalNoticeText = new CachedTransform(hd => string.Format(originalNotice.Text, hd?.Default.DisplayString())); + var originalNoticeText = new CachedTransform(hd => + TranslationProvider.GetString(OriginalNotice, Translation.Arguments("key", hd?.Default.DisplayString()))); originalNotice.GetText = () => originalNoticeText.Update(selectedHotkeyDefinition); var readonlyNotice = panel.Get("READONLY_NOTICE"); diff --git a/mods/cnc/chrome/dialogs.yaml b/mods/cnc/chrome/dialogs.yaml index c2a1d2feb5..d0977f59ef 100644 --- a/mods/cnc/chrome/dialogs.yaml +++ b/mods/cnc/chrome/dialogs.yaml @@ -301,7 +301,6 @@ ScrollPanel@NEWS_PANEL: Width: PARENT_RIGHT Height: 15 Align: Center - Text: by {0} at {1} Font: TinyBold Label@CONTENT: Y: 46 diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index dfe0e4e817..02d5a242d3 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -1720,7 +1720,6 @@ Container@PLAYER_WIDGETS: Width: 50 Height: 22 Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP_FACTIONSUFFIX Children: @@ -1737,7 +1736,6 @@ Container@PLAYER_WIDGETS: Height: 22 Align: Right Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP_FACTIONSUFFIX Children: diff --git a/mods/cnc/chrome/settings-hotkeys.yaml b/mods/cnc/chrome/settings-hotkeys.yaml index 1b1f153eb4..9a6c67abb4 100644 --- a/mods/cnc/chrome/settings-hotkeys.yaml +++ b/mods/cnc/chrome/settings-hotkeys.yaml @@ -125,12 +125,10 @@ Container@HOTKEYS_PANEL: Width: PARENT_RIGHT Height: PARENT_BOTTOM Font: Tiny - Text: The default is "{0}" Label@DUPLICATE_NOTICE: Width: PARENT_RIGHT Height: PARENT_BOTTOM Font: Tiny - Text: This is already used for "{0}" in the {1} context Label@READONLY_NOTICE: Width: PARENT_RIGHT Height: PARENT_BOTTOM diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index add358bb38..625ef4df80 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -200,7 +200,6 @@ Background@PRODUCTION_TOOLTIP: Y: 20 Height: 15 Font: TinyBold - Text: Requires {0} Label@DESC: X: 5 Y: 20 @@ -262,7 +261,6 @@ Background@PRODUCTION_TOOLTIP_FACTIONSUFFIX: Y: 20 Height: 15 Font: TinyBold - Text: Requires {0} Label@DESC: X: 5 Y: 20 diff --git a/mods/common/chrome/connection.yaml b/mods/common/chrome/connection.yaml index e387033d24..4b884d2676 100644 --- a/mods/common/chrome/connection.yaml +++ b/mods/common/chrome/connection.yaml @@ -18,7 +18,6 @@ Background@CONNECTIONFAILED_PANEL: Y: 46 Width: PARENT_RIGHT Height: 25 - Text: Could not connect to AAA.BBB.CCC.DDD:EEEE Align: Center Label@CONNECTION_ERROR: X: 0 @@ -85,7 +84,6 @@ Background@CONNECTING_PANEL: Y: 61 Width: PARENT_RIGHT Height: 25 - Text: Connecting to AAA.BBB.CCC.DDD:EEEE... Align: Center Button@ABORT_BUTTON: X: PARENT_RIGHT - 180 diff --git a/mods/common/chrome/dropdowns.yaml b/mods/common/chrome/dropdowns.yaml index 39ed403707..3edd9d82df 100644 --- a/mods/common/chrome/dropdowns.yaml +++ b/mods/common/chrome/dropdowns.yaml @@ -171,7 +171,6 @@ ScrollPanel@NEWS_PANEL: Width: PARENT_RIGHT Height: 15 Align: Center - Text: by {0} at {1} Font: TinyBold Label@CONTENT: Y: 45 diff --git a/mods/common/chrome/settings-hotkeys.yaml b/mods/common/chrome/settings-hotkeys.yaml index 9fac07e92f..f21223ab23 100644 --- a/mods/common/chrome/settings-hotkeys.yaml +++ b/mods/common/chrome/settings-hotkeys.yaml @@ -125,12 +125,10 @@ Container@HOTKEYS_PANEL: Width: PARENT_RIGHT Height: PARENT_BOTTOM Font: Tiny - Text: The default is "{0}" Label@DUPLICATE_NOTICE: Width: PARENT_RIGHT Height: PARENT_BOTTOM Font: Tiny - Text: This is already used for "{0}" in the {1} context Label@READONLY_NOTICE: Width: PARENT_RIGHT Height: PARENT_BOTTOM diff --git a/mods/common/chrome/tooltips.yaml b/mods/common/chrome/tooltips.yaml index b9e016851f..b3181e67f9 100644 --- a/mods/common/chrome/tooltips.yaml +++ b/mods/common/chrome/tooltips.yaml @@ -254,7 +254,6 @@ Background@PRODUCTION_TOOLTIP: Y: 26 Height: 15 Font: TinyBold - Text: Requires {0} Label@DESC: X: 7 Y: 27 diff --git a/mods/common/languages/en.ftl b/mods/common/languages/en.ftl index bd1a1b08af..d524ed2590 100644 --- a/mods/common/languages/en.ftl +++ b/mods/common/languages/en.ftl @@ -351,6 +351,10 @@ options-target-lines = .manual = Manual .disabled = Disabled +## HotkeysSettingsLogic +label-original-notice = The default is "{ $key }" +label-duplicate-notice = This is already used for "{ $key }" in the { $context } context + ## InputSettingsLogic options-mouse-scroll-type = .disabled = Disabled @@ -434,6 +438,7 @@ dialog-overwrite-save = label-loading-news = Loading news label-news-retrieval-failed = Failed to retrieve news: { $message } label-news-parsing-failed = Failed to parse news: { $message } +label-author-datetime = by { $author } at { $datetime } ## MapChooserLogic label-all-maps = All Maps @@ -488,6 +493,9 @@ label-audio-unmuted = Audio unmuted. label-loading-player-profile = Loading player profile... label-loading-player-profile-failed = Failed to load player profile. +## ProductionTooltipLogic +label-requires = Requires { $prequisites } + ## ReplayBrowserLogic label-duration = Duration: { $time } diff --git a/mods/d2k/chrome/dropdowns.yaml b/mods/d2k/chrome/dropdowns.yaml index ef3ad29fdb..2a8fa23a52 100644 --- a/mods/d2k/chrome/dropdowns.yaml +++ b/mods/d2k/chrome/dropdowns.yaml @@ -135,7 +135,6 @@ ScrollPanel@NEWS_PANEL: Width: PARENT_RIGHT Height: 15 Align: Center - Text: by {0} at {1} Font: TinyBold Label@CONTENT: Y: 45 diff --git a/mods/d2k/chrome/ingame-player.yaml b/mods/d2k/chrome/ingame-player.yaml index c70ec19bbf..011aee343e 100644 --- a/mods/d2k/chrome/ingame-player.yaml +++ b/mods/d2k/chrome/ingame-player.yaml @@ -446,7 +446,6 @@ Container@PLAYER_WIDGETS: Width: 50 Height: 22 Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP LabelWithTooltip@POWER: @@ -457,7 +456,6 @@ Container@PLAYER_WIDGETS: Height: 22 Align: Right Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP Children: diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index ba43ecbc30..23b5b076b1 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -256,7 +256,6 @@ Background@PRODUCTION_TOOLTIP: Y: 22 Height: 15 Font: TinyBold - Text: Requires {0} Label@DESC: X: 7 Y: 23 diff --git a/mods/ra/chrome/ingame-player.yaml b/mods/ra/chrome/ingame-player.yaml index 68f5ffe0a9..d18db7bb27 100644 --- a/mods/ra/chrome/ingame-player.yaml +++ b/mods/ra/chrome/ingame-player.yaml @@ -623,7 +623,6 @@ Container@PLAYER_WIDGETS: Width: 50 Height: 23 Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP Children: @@ -640,7 +639,6 @@ Container@PLAYER_WIDGETS: Height: 23 Align: Right Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP Children: diff --git a/mods/ts/chrome/dropdowns.yaml b/mods/ts/chrome/dropdowns.yaml index d6e2ea6e55..3d52d689e4 100644 --- a/mods/ts/chrome/dropdowns.yaml +++ b/mods/ts/chrome/dropdowns.yaml @@ -135,7 +135,6 @@ ScrollPanel@NEWS_PANEL: Width: PARENT_RIGHT Height: 15 Align: Center - Text: by {0} at {1} Font: TinyBold Label@CONTENT: Y: 45 diff --git a/mods/ts/chrome/ingame-player.yaml b/mods/ts/chrome/ingame-player.yaml index faacd199e6..2e53cb5dff 100644 --- a/mods/ts/chrome/ingame-player.yaml +++ b/mods/ts/chrome/ingame-player.yaml @@ -441,7 +441,6 @@ Container@PLAYER_WIDGETS: Width: 50 Height: 22 Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP Children: @@ -458,7 +457,6 @@ Container@PLAYER_WIDGETS: Height: 22 Align: Right Font: Bold - Text: {0} TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP Children: diff --git a/mods/ts/chrome/settings-hotkeys.yaml b/mods/ts/chrome/settings-hotkeys.yaml index 49a94d5f38..bba1d29043 100644 --- a/mods/ts/chrome/settings-hotkeys.yaml +++ b/mods/ts/chrome/settings-hotkeys.yaml @@ -127,12 +127,10 @@ Container@HOTKEYS_PANEL: Width: PARENT_RIGHT Height: PARENT_BOTTOM Font: Tiny - Text: The default is "{0}" Label@DUPLICATE_NOTICE: Width: PARENT_RIGHT Height: PARENT_BOTTOM Font: Tiny - Text: This is already used for "{0}" in the {1} context Label@READONLY_NOTICE: Width: PARENT_RIGHT Height: PARENT_BOTTOM