From b3abd09517a592f5b1457bad9fcabeef96f0a16d Mon Sep 17 00:00:00 2001 From: CloneWith Date: Wed, 10 Sep 2025 07:48:09 +0800 Subject: [PATCH] Add HumanisedLocalisableDate for l10n --- osu.Game/Graphics/DrawableDate.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/DrawableDate.cs b/osu.Game/Graphics/DrawableDate.cs index 641a4d80ce..a5171388c5 100644 --- a/osu.Game/Graphics/DrawableDate.cs +++ b/osu.Game/Graphics/DrawableDate.cs @@ -72,12 +72,33 @@ namespace osu.Game.Graphics Scheduler.AddDelayed(updateTimeWithReschedule, timeUntilNextUpdate); } - protected virtual LocalisableString Format() => HumanizerUtils.Humanize(Date); + protected virtual LocalisableString Format() => new LocalisableString(new HumanisedLocalisableDate(Date)); private void updateTime() => Text = Format(); public ITooltip GetCustomTooltip() => new DateTooltip(); public DateTimeOffset TooltipContent => Date; + + private class HumanisedLocalisableDate : IEquatable, ILocalisableStringData + { + public readonly DateTimeOffset Date; + + public HumanisedLocalisableDate(DateTimeOffset date) + { + Date = date; + } + + public bool Equals(HumanisedLocalisableDate? other) + => other?.Date != null && Date.Equals(other.Date); + + public bool Equals(ILocalisableStringData? other) + => other is HumanisedLocalisableDate otherDate && Equals(otherDate); + + public string GetLocalised(LocalisationParameters parameters) => HumanizerUtils.Humanize(Date); + + // Override for default string interpolations + public override string ToString() => HumanizerUtils.Humanize(Date); + } } }