mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 23:42:55 +08:00
Merge pull request #5530 from nyquillerium/humanizer-fallback
Add a fallback for humanizer localization lookup failures
This commit is contained in:
commit
3c03d36694
@ -2,11 +2,11 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Graphics
|
||||
{
|
||||
@ -71,7 +71,7 @@ namespace osu.Game.Graphics
|
||||
Scheduler.AddDelayed(updateTimeWithReschedule, timeUntilNextUpdate);
|
||||
}
|
||||
|
||||
protected virtual string Format() => Date.Humanize();
|
||||
protected virtual string Format() => HumanizerUtils.Humanize(Date);
|
||||
|
||||
private void updateTime() => Text = Format();
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// 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 Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -14,6 +13,7 @@ using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Users.Drawables;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -132,7 +132,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
{
|
||||
avatar.User = value.User;
|
||||
flag.Country = value.User.Country;
|
||||
date.Text = $@"achieved {value.Date.Humanize()}";
|
||||
date.Text = $@"achieved {HumanizerUtils.Humanize(value.Date)}";
|
||||
|
||||
usernameText.Clear();
|
||||
usernameText.AddUserLink(value.User);
|
||||
|
30
osu.Game/Utils/HumanizerUtils.cs
Normal file
30
osu.Game/Utils/HumanizerUtils.cs
Normal file
@ -0,0 +1,30 @@
|
||||
// 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>
|
||||
/// Turns the current or provided date into a human readable sentence
|
||||
/// </summary>
|
||||
/// <param name="input">The date to be humanized</param>
|
||||
/// <returns>distance of time in words</returns>
|
||||
public static string Humanize(DateTimeOffset input)
|
||||
{
|
||||
// this works around https://github.com/xamarin/xamarin-android/issues/2012 and https://github.com/Humanizr/Humanizer/issues/690#issuecomment-368536282
|
||||
try
|
||||
{
|
||||
return input.Humanize();
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return input.Humanize(culture: new CultureInfo("en-US"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user