diff --git a/release_notes.md b/release_notes.md index 3d3900d0a..c25d3488b 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,5 @@ ###In Development + - [#276](https://github.com/Mehdik/Humanizer/pull/276): Added Farsi ToOrdinalWords [Commits](https://github.com/MehdiK/Humanizer/compare/v1.26.1...master) diff --git a/src/Humanizer.Tests/Localisation/fa/NumberToWordsTests.cs b/src/Humanizer.Tests/Localisation/fa/NumberToWordsTests.cs index acb3a29d1..816515c0b 100644 --- a/src/Humanizer.Tests/Localisation/fa/NumberToWordsTests.cs +++ b/src/Humanizer.Tests/Localisation/fa/NumberToWordsTests.cs @@ -39,5 +39,42 @@ public void ToWordsFarsi(int number, string expected) { Assert.Equal(expected, number.ToWords()); } + + [Theory] + [InlineData(0, "صفرم")] + [InlineData(1, "اول")] + [InlineData(2, "دوم")] + [InlineData(3, "سوم")] + [InlineData(4,"چهارم")] + [InlineData(5, "پنجم")] + [InlineData(6, "ششم")] + [InlineData(7, "هفتم")] + [InlineData(8, "هشتم")] + [InlineData(9, "نهم")] + [InlineData(10, "دهم")] + [InlineData(11, "یازدهم")] + [InlineData(12, "دوازدهم")] + [InlineData(13, "سیزدهم")] + [InlineData(21, "بیست و یکم")] + [InlineData(22, "بیست و دوم")] + [InlineData(23, "بیست و سوم")] + [InlineData(24, "بیست و چهارم")] + [InlineData(25, "بیست و پنجم")] + [InlineData(30, "سی ام")] + [InlineData(40, "چهلم")] + [InlineData(50, "پنجاهم")] + [InlineData(60, "شصتم")] + [InlineData(70, "هفتادم")] + [InlineData(80, "هشتادم")] + [InlineData(90, "نودم")] + [InlineData(100, "صدم")] + [InlineData(200, "دویستم")] + [InlineData(1000, "یک هزارم")] + [InlineData(1333, "یک هزار و سیصد و سی و سوم")] + [InlineData(1000000, "یک میلیونم")] + public void ToOrdinalWords(int number, string words) + { + Assert.Equal(words, number.ToOrdinalWords()); + } } } diff --git a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs index d622eb071..9602fde39 100644 --- a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs @@ -46,5 +46,25 @@ public override string Convert(int number) return string.Join(" و ", parts); } + + public override string ConvertToOrdinal(int number) + { + if (number == 1) + return "اول"; + + if (number == 3) + return "سوم"; + + if (number % 10 == 3 && number != 13) + return Convert((number / 10) * 10) + " و سوم"; + + var word = Convert(number); + return string.Format("{0}{1}", word, word.EndsWith("ی") ? " ام" : "م"); + } + + public override string ConvertToOrdinal(int number, GrammaticalGender gender) + { + return ConvertToOrdinal(number); + } } }