From 44aaf4dd07926df99271c9702dceb8dd028f1058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 19 Oct 2022 12:20:25 +0200 Subject: [PATCH] Localise text notifications. --- OpenRA.Game/Game.cs | 5 ++++- OpenRA.Mods.Common/Commands/ChatCommands.cs | 5 ++++- OpenRA.Mods.Common/Commands/DevCommands.cs | 10 ++++++++-- OpenRA.Mods.Common/Commands/HelpCommand.cs | 12 +++++++++--- .../Traits/Player/DeveloperMode.cs | 6 +++++- mods/common/languages/en.ftl | 17 +++++++++++++++++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index faabe05b31..3baf1f5ece 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -571,6 +571,9 @@ namespace OpenRA public static void RunAfterTick(Action a) { delayedActions.Add(a, RunTime); } public static void RunAfterDelay(int delayMilliseconds, Action a) { delayedActions.Add(a, RunTime + delayMilliseconds); } + [TranslationReference("filename")] + static readonly string SavedScreenshot = "saved-screenshot"; + static void TakeScreenshotInner() { using (new PerfTimer("Renderer.SaveScreenshot")) @@ -584,7 +587,7 @@ namespace OpenRA Log.Write("debug", "Taking screenshot " + path); Renderer.SaveScreenshot(path); - TextNotificationsManager.Debug("Saved screenshot " + filename); + TextNotificationsManager.Debug(ModData.Translation.GetString(SavedScreenshot, Translation.Arguments("filename", filename))); } } diff --git a/OpenRA.Mods.Common/Commands/ChatCommands.cs b/OpenRA.Mods.Common/Commands/ChatCommands.cs index 677d1ee681..c881fef88e 100644 --- a/OpenRA.Mods.Common/Commands/ChatCommands.cs +++ b/OpenRA.Mods.Common/Commands/ChatCommands.cs @@ -24,6 +24,9 @@ namespace OpenRA.Mods.Common.Commands { public Dictionary Commands { get; } + [TranslationReference("name")] + static readonly string InvalidCommand = "invalid-command"; + public ChatCommands() { Commands = new Dictionary(); @@ -39,7 +42,7 @@ namespace OpenRA.Mods.Common.Commands if (command.Value != null) command.Value.InvokeCommand(name.ToLowerInvariant(), message.Substring(1 + name.Length).Trim()); else - TextNotificationsManager.Debug("{0} is not a valid command.", name); + TextNotificationsManager.Debug(Game.ModData.Translation.GetString(InvalidCommand, Translation.Arguments("name", name))); return false; } diff --git a/OpenRA.Mods.Common/Commands/DevCommands.cs b/OpenRA.Mods.Common/Commands/DevCommands.cs index efb0c863d6..f2f7c7eb86 100644 --- a/OpenRA.Mods.Common/Commands/DevCommands.cs +++ b/OpenRA.Mods.Common/Commands/DevCommands.cs @@ -24,6 +24,12 @@ namespace OpenRA.Mods.Common.Commands public class DevCommands : IChatCommand, IWorldLoaded { + [TranslationReference] + static readonly string CheatsDisabled = "cheats-disabled"; + + [TranslationReference] + static readonly string InvalidCashAmount = "invalid-cash-amount"; + readonly IDictionary Handler)> commandHandlers = new Dictionary)> { { "visibility", ("toggles visibility checks and minimap.", Visibility) }, @@ -70,7 +76,7 @@ namespace OpenRA.Mods.Common.Commands if (!developerMode.Enabled) { - TextNotificationsManager.Debug("Cheats are disabled."); + TextNotificationsManager.Debug(Game.ModData.Translation.GetString(CheatsDisabled)); return; } @@ -98,7 +104,7 @@ namespace OpenRA.Mods.Common.Commands giveCashOrder.ExtraData = (uint)cash; else { - TextNotificationsManager.Debug("Invalid amount of cash."); + TextNotificationsManager.Debug(Game.ModData.Translation.GetString(InvalidCashAmount)); return; } diff --git a/OpenRA.Mods.Common/Commands/HelpCommand.cs b/OpenRA.Mods.Common/Commands/HelpCommand.cs index 05ff181e73..7a5d2c2fb3 100644 --- a/OpenRA.Mods.Common/Commands/HelpCommand.cs +++ b/OpenRA.Mods.Common/Commands/HelpCommand.cs @@ -23,6 +23,12 @@ namespace OpenRA.Mods.Common.Commands { readonly Dictionary helpDescriptions; + [TranslationReference] + static readonly string AvailableCommands = "available-commands"; + + [TranslationReference] + static readonly string NoDescription = "no-description"; + World world; ChatCommands console; @@ -42,14 +48,14 @@ namespace OpenRA.Mods.Common.Commands public void InvokeCommand(string name, string arg) { - TextNotificationsManager.Debug("Here are the available commands:"); + TextNotificationsManager.Debug(Game.ModData.Translation.GetString(AvailableCommands)); foreach (var key in console.Commands.Keys) { if (!helpDescriptions.TryGetValue(key, out var description)) - description = "no description available."; + description = Game.ModData.Translation.GetString(NoDescription); - TextNotificationsManager.Debug("{0}: {1}", key, description); + TextNotificationsManager.Debug($"{key}: {description}"); } } diff --git a/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs b/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs index dd37e4aad6..f268b4daa2 100644 --- a/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs @@ -106,6 +106,9 @@ namespace OpenRA.Mods.Common.Traits bool enableAll; + [TranslationReference("cheat", "player", "suffix")] + static readonly string CheatUsed = "cheat-used"; + public DeveloperMode(DeveloperModeInfo info) { this.info = info; @@ -273,7 +276,8 @@ namespace OpenRA.Mods.Common.Traits return; } - TextNotificationsManager.Debug("Cheat used: {0} by {1}{2}", order.OrderString, self.Owner.PlayerName, debugSuffix); + var arguments = Translation.Arguments("cheat", order.OrderString, "player", self.Owner.PlayerName, "suffix", debugSuffix); + TextNotificationsManager.Debug(Game.ModData.Translation.GetString(CheatUsed, arguments)); } bool IUnlocksRenderPlayer.RenderPlayerUnlocked => Enabled; diff --git a/mods/common/languages/en.ftl b/mods/common/languages/en.ftl index 66e3b53718..d421185b43 100644 --- a/mods/common/languages/en.ftl +++ b/mods/common/languages/en.ftl @@ -590,3 +590,20 @@ password-protected = Password protected waiting-for-players = Waiting for players server-shutting-down = Server shutting down unknown-server-state = Unknown server state + +## Game +saved-screenshot = Saved screenshot { $filename } + +## ChatCommands +invalid-command = { $name } is not a valid command. + +## DevCommands +cheats-disabled = Cheats are disabled. +invalid-cash-amount = Invalid amount of cash. + +## HelpCommands +available-commands = Here are the available commands: +no-description = no description available. + +## DeveloperMode +cheat-used = Cheat used: { $cheat } by { $player }{ $suffix }