Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fallback for humanizer localization lookup failures #5530

Merged
merged 4 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions osu.Game/Graphics/DrawableDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -71,7 +71,7 @@ private void updateTimeWithReschedule()
Scheduler.AddDelayed(updateTimeWithReschedule, timeUntilNextUpdate);
}

protected virtual string Format() => Date.Humanize();
protected virtual string Format() => HumanizerUtils.Humanize(Date);

private void updateTime() => Text = Format();

Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +13,7 @@
using osu.Game.Online.Leaderboards;
using osu.Game.Scoring;
using osu.Game.Users.Drawables;
using osu.Game.Utils;
using osuTK;
using osuTK.Graphics;

Expand Down Expand Up @@ -132,7 +132,7 @@ public ScoreInfo Score
{
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);
Expand Down
30 changes: 30 additions & 0 deletions osu.Game/Utils/HumanizerUtils.cs
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}
}