Skip to content

Commit

Permalink
Add new overload for Ordinalize that accepts a CultureInfo,
Browse files Browse the repository at this point in the history
so the consumer can override the requested culture. This fixes #593. See
the discussion there for details.
  • Loading branch information
Thijs Brobbel authored and tiesmaster committed Apr 3, 2019
1 parent 6b0deb3 commit 5ca628c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Humanizer.Tests.Shared/OrdinalizeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using System.Globalization;
using Xunit;

namespace Humanizer.Tests
{
Expand Down Expand Up @@ -95,5 +96,13 @@ public void OrdinalizeStringGenderIsImmaterial(string number)
var feminineOrdinalized = number.Ordinalize(GrammaticalGender.Feminine);
Assert.Equal(masculineOrdinalized, feminineOrdinalized);
}

[Theory]
[InlineData("en-US", 1, "1st")]
[InlineData("nl-NL", 1, "1e")]
public void OrdinalizeWithCultureOverridesCurrentCulture(CultureInfo culture, int number, string ordinalized)
{
Assert.Equal(number.Ordinalize(culture), ordinalized);
}
}
}
11 changes: 11 additions & 0 deletions src/Humanizer/OrdinalizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ public static string Ordinalize(this int number)
return Configurator.Ordinalizer.Convert(number, number.ToString(CultureInfo.InvariantCulture));
}

/// <summary>
/// Turns a number into an ordinal number used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
/// </summary>
/// <param name="number">The number to be ordinalized</param>
/// <param name="culture">Culture to use. If null, current thread's UI culture is used.</param>
/// <returns></returns>
public static string Ordinalize(this int number, CultureInfo culture)
{
return Configurator.Ordinalizers.ResolveForCulture(culture).Convert(number, number.ToString(culture));
}

/// <summary>
/// Turns a number into an ordinal number used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
/// Gender for Brazilian Portuguese locale
Expand Down

0 comments on commit 5ca628c

Please sign in to comment.