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

Farsi ToOrdinalWords #276

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
37 changes: 37 additions & 0 deletions src/Humanizer.Tests/Localisation/fa/NumberToWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,42 @@ public void ToWordsFarsi(int number, string expected)
{
Assert.Equal(expected, number.ToWords());
}

[Theory]
[InlineData(0, "صفرم")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there such thing as "صفرم"?!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, you tell me! I Added it as an equivalent to 'zeroth'.

[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, "یک میلیونم")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be "یک میلیونم" or "یک میلیونیم"? Not sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that "یک میلیونم" is correct.

public void ToOrdinalWords(int number, string words)
{
Assert.Equal(words, number.ToOrdinalWords());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}