From 1f7cffa793f2dc9b3731fd5ad98adb132a07d179 Mon Sep 17 00:00:00 2001 From: brz Date: Sat, 24 May 2014 00:14:44 +0430 Subject: [PATCH 1/2] Added Farsi ToOrdinalWords --- release_notes.md | 1 + .../Localisation/fa/NumberToWordsTests.cs | 37 +++++++++++++++++++ .../FarsiNumberToWordsConverter.cs | 20 ++++++++++ 3 files changed, 58 insertions(+) diff --git a/release_notes.md b/release_notes.md index 3d3900d0a..f4538b289 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,5 @@ ###In Development + - [#257](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); + } } } From cf6b4fbba33bd1f3ec8f574dcff5928d0bf06748 Mon Sep 17 00:00:00 2001 From: Borzoo Date: Sat, 24 May 2014 00:16:32 +0430 Subject: [PATCH 2/2] PR number fix --- release_notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_notes.md b/release_notes.md index f4538b289..c25d3488b 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,5 @@ ###In Development - - [#257](https://github.com/Mehdik/Humanizer/pull/276): Added Farsi ToOrdinalWords + - [#276](https://github.com/Mehdik/Humanizer/pull/276): Added Farsi ToOrdinalWords [Commits](https://github.com/MehdiK/Humanizer/compare/v1.26.1...master)