diff --git a/release_notes.md b/release_notes.md index f8ab3c6ee..ae0ddac56 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,6 @@ ###In Development - [#217](https://github.com/Mehdik/Humanizer/pull/217): Changed OrdinalizeExtensions to better accommodate localisations. Added pt-BR and Spanish Ordinalize localisation. + - [#221](https://github.com/Mehdik/Humanizer/pull/221): Added Russian ordinalizer [Commits](https://github.com/MehdiK/Humanizer/compare/v1.22.1...master) diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index aefc802cd..211b172f1 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -106,6 +106,7 @@ + diff --git a/src/Humanizer.Tests/Localisation/ru-RU/OrdinalizeTests.cs b/src/Humanizer.Tests/Localisation/ru-RU/OrdinalizeTests.cs new file mode 100644 index 000000000..2ca54724d --- /dev/null +++ b/src/Humanizer.Tests/Localisation/ru-RU/OrdinalizeTests.cs @@ -0,0 +1,129 @@ +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.ruRU +{ + public class OrdinalizeTests : AmbientCulture + { + public OrdinalizeTests() + : base("ru-RU") + { + } + + [Theory] + [InlineData("0", "0-й")] + [InlineData("1", "1-й")] + [InlineData("2", "2-й")] + [InlineData("3", "3-й")] + [InlineData("4", "4-й")] + [InlineData("5", "5-й")] + [InlineData("6", "6-й")] + [InlineData("23", "23-й")] + [InlineData("100", "100-й")] + [InlineData("101", "101-й")] + [InlineData("102", "102-й")] + [InlineData("103", "103-й")] + [InlineData("1001", "1001-й")] + public void OrdinalizeString(string number, string ordinalized) + { + Assert.Equal(number.Ordinalize(GrammaticalGender.Masculine), ordinalized); + } + + [Theory] + [InlineData("0", "0-я")] + [InlineData("1", "1-я")] + [InlineData("2", "2-я")] + [InlineData("3", "3-я")] + [InlineData("4", "4-я")] + [InlineData("5", "5-я")] + [InlineData("6", "6-я")] + [InlineData("23", "23-я")] + [InlineData("100", "100-я")] + [InlineData("101", "101-я")] + [InlineData("102", "102-я")] + [InlineData("103", "103-я")] + [InlineData("1001", "1001-я")] + public void OrdinalizeStringFeminine(string number, string ordinalized) + { + Assert.Equal(number.Ordinalize(GrammaticalGender.Feminine), ordinalized); + } + + [Theory] + [InlineData("0", "0-е")] + [InlineData("1", "1-е")] + [InlineData("2", "2-е")] + [InlineData("3", "3-е")] + [InlineData("4", "4-е")] + [InlineData("5", "5-е")] + [InlineData("6", "6-е")] + [InlineData("23", "23-е")] + [InlineData("100", "100-е")] + [InlineData("101", "101-е")] + [InlineData("102", "102-е")] + [InlineData("103", "103-е")] + [InlineData("1001", "1001-е")] + public void OrdinalizeStringNeuter(string number, string ordinalized) + { + Assert.Equal(number.Ordinalize(GrammaticalGender.Neuter), ordinalized); + } + + [Theory] + [InlineData(0, "0-й")] + [InlineData(1, "1-й")] + [InlineData(2, "2-й")] + [InlineData(3, "3-й")] + [InlineData(4, "4-й")] + [InlineData(5, "5-й")] + [InlineData(6, "6-й")] + [InlineData(10, "10-й")] + [InlineData(23, "23-й")] + [InlineData(100, "100-й")] + [InlineData(101, "101-й")] + [InlineData(102, "102-й")] + [InlineData(103, "103-й")] + [InlineData(1001, "1001-й")] + public void OrdinalizeNumber(int number, string ordinalized) + { + Assert.Equal(number.Ordinalize(GrammaticalGender.Masculine), ordinalized); + } + + [Theory] + [InlineData(0, "0-я")] + [InlineData(1, "1-я")] + [InlineData(2, "2-я")] + [InlineData(3, "3-я")] + [InlineData(4, "4-я")] + [InlineData(5, "5-я")] + [InlineData(6, "6-я")] + [InlineData(10, "10-я")] + [InlineData(23, "23-я")] + [InlineData(100, "100-я")] + [InlineData(101, "101-я")] + [InlineData(102, "102-я")] + [InlineData(103, "103-я")] + [InlineData(1001, "1001-я")] + public void OrdinalizeNumberFeminine(int number, string ordinalized) + { + Assert.Equal(number.Ordinalize(GrammaticalGender.Feminine), ordinalized); + } + + [Theory] + [InlineData(0, "0-е")] + [InlineData(1, "1-е")] + [InlineData(2, "2-е")] + [InlineData(3, "3-е")] + [InlineData(4, "4-е")] + [InlineData(5, "5-е")] + [InlineData(6, "6-е")] + [InlineData(23, "23-е")] + [InlineData(100, "100-е")] + [InlineData(101, "101-е")] + [InlineData(102, "102-е")] + [InlineData(103, "103-е")] + [InlineData(1001, "1001-е")] + public void OrdinalizeNumberNeuter(int number, string ordinalized) + { + Assert.Equal(number.Ordinalize(GrammaticalGender.Neuter), ordinalized); + } + } +} \ No newline at end of file diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index d73658704..48a21ac9b 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -88,6 +88,7 @@ + diff --git a/src/Humanizer/Localisation/Ordinalizers/RussianOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/RussianOrdinalizer.cs new file mode 100644 index 000000000..f7ae4b004 --- /dev/null +++ b/src/Humanizer/Localisation/Ordinalizers/RussianOrdinalizer.cs @@ -0,0 +1,21 @@ +namespace Humanizer.Localisation.Ordinalizers +{ + internal class RussianOrdinalizer : DefaultOrdinalizer + { + public override string Convert(int number, string numberString) + { + return Convert(number, numberString, GrammaticalGender.Masculine); + } + + public override string Convert(int number, string numberString, GrammaticalGender gender) + { + if (gender == GrammaticalGender.Masculine) + return numberString + "-й"; + + if (gender == GrammaticalGender.Feminine) + return numberString + "-я"; + + return numberString + "-е"; + } + } +} diff --git a/src/Humanizer/OrdinalizeExtensions.cs b/src/Humanizer/OrdinalizeExtensions.cs index 16de75700..403d5295f 100644 --- a/src/Humanizer/OrdinalizeExtensions.cs +++ b/src/Humanizer/OrdinalizeExtensions.cs @@ -15,7 +15,8 @@ public static class OrdinalizeExtensions { {"en", () => new EnglishOrdinalizer()}, {"es", () => new SpanishOrdinalizer()}, - {"pt-BR", () => new BrazilianPortugueseOrdinalizer()} + {"pt-BR", () => new BrazilianPortugueseOrdinalizer()}, + {"ru", () => new RussianOrdinalizer()} }; ///