Translate labels with parameters.
This commit is contained in:
committed by
Gustas
parent
474463111f
commit
6e6bf1ca81
@@ -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<LabelWithTooltipWidget>("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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ProductionIcon> 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<int, string>(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;
|
||||
|
||||
@@ -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<LabelWidget>("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<LabelWidget>("CONTENT");
|
||||
|
||||
@@ -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<string, MiniYaml> logicArgs;
|
||||
|
||||
@@ -220,14 +226,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
duplicateNotice.IsVisible = () => !isHotkeyValid;
|
||||
var duplicateNoticeText = new CachedTransform<HotkeyDefinition, string>(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<LabelWidget>("ORIGINAL_NOTICE");
|
||||
originalNotice.TextColor = ChromeMetrics.Get<Color>("NoticeInfoColor");
|
||||
originalNotice.IsVisible = () => isHotkeyValid && !isHotkeyDefault;
|
||||
var originalNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => string.Format(originalNotice.Text, hd?.Default.DisplayString()));
|
||||
var originalNoticeText = new CachedTransform<HotkeyDefinition, string>(hd =>
|
||||
TranslationProvider.GetString(OriginalNotice, Translation.Arguments("key", hd?.Default.DisplayString())));
|
||||
originalNotice.GetText = () => originalNoticeText.Update(selectedHotkeyDefinition);
|
||||
|
||||
var readonlyNotice = panel.Get<LabelWidget>("READONLY_NOTICE");
|
||||
|
||||
Reference in New Issue
Block a user