mirror of
https://github.com/ppy/osu.git
synced 2025-02-27 01:45:36 +08:00
Add a fallback for humanizer localization failure
This commit is contained in:
parent
6f2edaad55
commit
1956098166
@ -2,11 +2,11 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Humanizer;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Graphics
|
namespace osu.Game.Graphics
|
||||||
{
|
{
|
||||||
@ -71,7 +71,7 @@ namespace osu.Game.Graphics
|
|||||||
Scheduler.AddDelayed(updateTimeWithReschedule, timeUntilNextUpdate);
|
Scheduler.AddDelayed(updateTimeWithReschedule, timeUntilNextUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual string Format() => Date.Humanize();
|
protected virtual string Format() => HumanizerUtils.Humanize(Date);
|
||||||
|
|
||||||
private void updateTime() => Text = Format();
|
private void updateTime() => Text = Format();
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using Humanizer;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -14,6 +13,7 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Online.Leaderboards;
|
using osu.Game.Online.Leaderboards;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Users.Drawables;
|
using osu.Game.Users.Drawables;
|
||||||
|
using osu.Game.Utils;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
{
|
{
|
||||||
avatar.User = value.User;
|
avatar.User = value.User;
|
||||||
flag.Country = value.User.Country;
|
flag.Country = value.User.Country;
|
||||||
date.Text = $@"achieved {value.Date.Humanize()}";
|
date.Text = $@"achieved {HumanizerUtils.Humanize(value.Date)}";
|
||||||
|
|
||||||
usernameText.Clear();
|
usernameText.Clear();
|
||||||
usernameText.AddUserLink(value.User);
|
usernameText.AddUserLink(value.User);
|
||||||
|
36
osu.Game/Utils/HumanizerUtils.cs
Normal file
36
osu.Game/Utils/HumanizerUtils.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Humanizer;
|
||||||
|
|
||||||
|
namespace osu.Game.Utils
|
||||||
|
{
|
||||||
|
public static class HumanizerUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Humanizes a string using the system culture, then falls back if one cannot be found.
|
||||||
|
/// <remarks>
|
||||||
|
/// A localization lookup failure will throw an exception of type <see cref="ArgumentException"/>
|
||||||
|
/// </remarks>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dateTimeOffset">The time to humanize.</param>
|
||||||
|
/// <returns>A humanized string of the given time.</returns>
|
||||||
|
public static string Humanize(DateTimeOffset dateTimeOffset)
|
||||||
|
{
|
||||||
|
string offset;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
offset = dateTimeOffset.Humanize();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
offset = dateTimeOffset.Humanize(culture: new CultureInfo("en-US"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user