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

Added Gender for ToOrdinalWords (needed for Brazilian Portuguese) #196

Merged
merged 6 commits into from
Apr 12, 2014
Merged
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
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,18 @@ This is kind of mixing `ToWords` with `Ordinalize`. You can call `ToOrdinalWords
121.ToOrdinalWords() => "hundred and twenty first"
```

`ToOrdinalWords` also supports `GrammaticalGender`, if that is applicable to your culture, you can pass a second argument to `ToOrdinalWords` to specify which gender the number should be outputted in. The possible values are `GrammaticalGender.Masculine`, `GrammaticalGender.Feminine` and `GrammaticalGender.Neuter`. Passing `GrammaticalGender` is optional since it doesn't apply to all cultures.

```C#
// for Brazilian Portuguese locale
1.ToOrdinalWords(GrammaticalGender.Masculine) => "primeiro"
Copy link
Member

Choose a reason for hiding this comment

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

May be worth adding an example for Neuter or if it doesn't apply explaining what it would output.

1.ToOrdinalWords(GrammaticalGender.Feminine) => "primeira"
1.ToOrdinalWords(GrammaticalGender.Neuter) => "primeiro"
2.ToOrdinalWords(GrammaticalGender.Masculine) => "segundo"
2.ToOrdinalWords(GrammaticalGender.Feminine) => "segunda"
2.ToOrdinalWords(GrammaticalGender.Neuter) => "segundo"
```

###<a id="roman-numerals">Roman numerals</a>
Humanizer can change numbers to Roman numerals using the `ToRoman` extension. The numbers 1 to 10 can be expressed in Roman numerals as follows:

Expand Down
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
- [#196](https://github.com/MehdiK/Humanizer/pull/196): Added Gender for ToOrdinalWords (needed for Brazilian Portuguese). Added pt-br OrdinalToWords localisation
- [#194](https://github.com/MehdiK/Humanizer/pull/194): Added pt-BR NumberToWords localisation
- [#147](https://github.com/MehdiK/Humanizer/pull/147): Added Russian translation for ToWords
- [#190](https://github.com/MehdiK/Humanizer/pull/190): Added French translation for ToWords and ToOrdinalWords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public class NumberToTimeSpanExtensions
public class NumberToWordsExtension
{
public string ToOrdinalWords(int number) { }
public string ToOrdinalWords(int number, Humanizer.GrammaticalGender gender) { }
public string ToWords(int number) { }
public string ToWords(int number, Humanizer.GrammaticalGender gender) { }
}
Expand Down
1 change: 0 additions & 1 deletion src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
<Compile Include="StringExtensionsTests.cs" />
<Compile Include="ToQuantityTests.cs" />
<Compile Include="TransformersTests.cs" />
<Compile Include="NumberToOrdinalWordsTests.cs" />
<Compile Include="Localisation\ro-Ro\DateHumanizeTests.cs" />
<Compile Include="DateHumanizeDefaultStrategyTests.cs" />
<Compile Include="DehumanizeToEnumTests.cs" />
Expand Down
152 changes: 150 additions & 2 deletions src/Humanizer.Tests/Localisation/pt-BR/NumberToWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ namespace Humanizer.Tests.Localisation.ptBR
{
public class NumberToWordsTests : AmbientCulture
{
public NumberToWordsTests() : base("pt-BR") { }
public NumberToWordsTests()
: base("pt-BR")
{
}

[Theory]
[InlineData(1, "um")]
[InlineData(10, "dez")]
[InlineData(11, "onze")]
[InlineData(21, "vinte e um")]
[InlineData(122, "cento e vinte e dois")]
[InlineData(3501, "três mil quinhentos e um")]
[InlineData(100, "cem")]
Expand All @@ -23,9 +27,11 @@ public NumberToWordsTests() : base("pt-BR") { }
[InlineData(111, "cento e onze")]
[InlineData(1111, "mil cento e onze")]
[InlineData(111111, "cento e onze mil cento e onze")]
[InlineData(1111101, "um milhão cento e onze mil cento e um")]
[InlineData(1111111, "um milhão cento e onze mil cento e onze")]
[InlineData(11111111, "onze milhões cento e onze mil cento e onze")]
[InlineData(111111111, "cento e onze milhões cento e onze mil cento e onze")]
[InlineData(1101111101, "um bilhão cento e um milhões cento e onze mil cento e um")]
[InlineData(1111111111, "um bilhão cento e onze milhões cento e onze mil cento e onze")]
[InlineData(123, "cento e vinte e três")]
[InlineData(1234, "mil duzentos e trinta e quatro")]
Expand All @@ -43,5 +49,147 @@ public void ToWords(int number, string expected)
{
Assert.Equal(expected, number.ToWords());
}

[Theory]
[InlineData(1, "uma")]
[InlineData(2, "duas")]
[InlineData(3, "três")]
[InlineData(11, "onze")]
[InlineData(21, "vinte e uma")]
[InlineData(122, "cento e vinte e duas")]
[InlineData(232, "duzentas e trinta e duas")]
[InlineData(343, "trezentas e quarenta e três")]
[InlineData(3501, "três mil quinhentas e uma")]
[InlineData(100, "cem")]
[InlineData(1000, "mil")]
[InlineData(111, "cento e onze")]
[InlineData(1111, "mil cento e onze")]
[InlineData(111111, "cento e onze mil cento e onze")]
[InlineData(1111101, "um milhão cento e onze mil cento e uma")]
[InlineData(1111111, "um milhão cento e onze mil cento e onze")]
[InlineData(1101111101, "um bilhão cento e um milhões cento e onze mil cento e uma")]
[InlineData(1234, "mil duzentas e trinta e quatro")]
[InlineData(8100, "oito mil e cem")]
[InlineData(12345, "doze mil trezentas e quarenta e cinco")]
public void ToFeminineWords(int number, string expected)
{
Assert.Equal(expected, number.ToWords(GrammaticalGender.Feminine));
}

[Theory]
[InlineData(0, "zero")]
[InlineData(1, "primeiro")]
[InlineData(2, "segundo")]
[InlineData(3, "terceiro")]
[InlineData(4, "quarto")]
[InlineData(5, "quinto")]
[InlineData(6, "sexto")]
[InlineData(7, "sétimo")]
[InlineData(8, "oitavo")]
[InlineData(9, "nono")]
[InlineData(10, "décimo")]
[InlineData(11, "décimo primeiro")]
[InlineData(12, "décimo segundo")]
[InlineData(13, "décimo terceiro")]
[InlineData(14, "décimo quarto")]
[InlineData(15, "décimo quinto")]
[InlineData(16, "décimo sexto")]
[InlineData(17, "décimo sétimo")]
[InlineData(18, "décimo oitavo")]
[InlineData(19, "décimo nono")]
[InlineData(20, "vigésimo")]
[InlineData(21, "vigésimo primeiro")]
[InlineData(22, "vigésimo segundo")]
[InlineData(30, "trigésimo")]
[InlineData(40, "quadragésimo")]
[InlineData(50, "quinquagésimo")]
[InlineData(60, "sexagésimo")]
[InlineData(70, "septuagésimo")]
[InlineData(80, "octogésimo")]
[InlineData(90, "nonagésimo")]
[InlineData(95, "nonagésimo quinto")]
[InlineData(96, "nonagésimo sexto")]
[InlineData(100, "centésimo")]
[InlineData(120, "centésimo vigésimo")]
[InlineData(121, "centésimo vigésimo primeiro")]
[InlineData(200, "ducentésimo")]
[InlineData(300, "trecentésimo")]
[InlineData(400, "quadringentésimo")]
[InlineData(500, "quingentésimo")]
[InlineData(600, "sexcentésimo")]
[InlineData(700, "septingentésimo")]
[InlineData(800, "octingentésimo")]
[InlineData(900, "noningentésimo")]
[InlineData(1000, "milésimo")]
[InlineData(1001, "milésimo primeiro")]
[InlineData(1021, "milésimo vigésimo primeiro")]
[InlineData(2021, "segundo milésimo vigésimo primeiro")]
[InlineData(10000, "décimo milésimo")]
[InlineData(10121, "décimo milésimo centésimo vigésimo primeiro")]
[InlineData(100000, "centésimo milésimo")]
[InlineData(1000000, "milionésimo")]
[InlineData(1000000000, "bilionésimo")]
public void ToOrdinalWords(int number, string words)
{
Assert.Equal(words, number.ToOrdinalWords());
}

[Theory]
[InlineData(0, "zero")]
[InlineData(1, "primeira")]
[InlineData(2, "segunda")]
[InlineData(3, "terceira")]
[InlineData(4, "quarta")]
[InlineData(5, "quinta")]
[InlineData(6, "sexta")]
[InlineData(7, "sétima")]
[InlineData(8, "oitava")]
[InlineData(9, "nona")]
[InlineData(10, "décima")]
[InlineData(11, "décima primeira")]
[InlineData(12, "décima segunda")]
[InlineData(13, "décima terceira")]
[InlineData(14, "décima quarta")]
[InlineData(15, "décima quinta")]
[InlineData(16, "décima sexta")]
[InlineData(17, "décima sétima")]
[InlineData(18, "décima oitava")]
[InlineData(19, "décima nona")]
[InlineData(20, "vigésima")]
[InlineData(21, "vigésima primeira")]
[InlineData(22, "vigésima segunda")]
[InlineData(30, "trigésima")]
[InlineData(40, "quadragésima")]
[InlineData(50, "quinquagésima")]
[InlineData(60, "sexagésima")]
[InlineData(70, "septuagésima")]
[InlineData(80, "octogésima")]
[InlineData(90, "nonagésima")]
[InlineData(95, "nonagésima quinta")]
[InlineData(96, "nonagésima sexta")]
[InlineData(100, "centésima")]
[InlineData(120, "centésima vigésima")]
[InlineData(121, "centésima vigésima primeira")]
[InlineData(200, "ducentésima")]
[InlineData(300, "trecentésima")]
[InlineData(400, "quadringentésima")]
[InlineData(500, "quingentésima")]
[InlineData(600, "sexcentésima")]
[InlineData(700, "septingentésima")]
[InlineData(800, "octingentésima")]
[InlineData(900, "noningentésima")]
[InlineData(1000, "milésima")]
[InlineData(1001, "milésima primeira")]
[InlineData(1021, "milésima vigésima primeira")]
[InlineData(2021, "segunda milésima vigésima primeira")]
[InlineData(10000, "décima milésima")]
[InlineData(10121, "décima milésima centésima vigésima primeira")]
[InlineData(100000, "centésima milésima")]
[InlineData(1000000, "milionésima")]
[InlineData(1000000000, "bilionésima")]
public void ToFeminineOrdinalWords(int number, string words)
{
Assert.Equal(words, number.ToOrdinalWords(GrammaticalGender.Feminine));
}
}
}
}
58 changes: 0 additions & 58 deletions src/Humanizer.Tests/NumberToOrdinalWordsTests.cs

This file was deleted.

50 changes: 49 additions & 1 deletion src/Humanizer.Tests/NumberToWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,53 @@ public void ToWords(int number, string expected)
{
Assert.Equal(expected, number.ToWords());
}

[Theory]
[InlineData(0, "zeroth")]
[InlineData(1, "first")]
[InlineData(2, "second")]
[InlineData(3, "third")]
[InlineData(4, "fourth")]
[InlineData(5, "fifth")]
[InlineData(6, "sixth")]
[InlineData(7, "seventh")]
[InlineData(8, "eighth")]
[InlineData(9, "ninth")]
[InlineData(10, "tenth")]
[InlineData(11, "eleventh")]
[InlineData(12, "twelfth")]
[InlineData(13, "thirteenth")]
[InlineData(14, "fourteenth")]
[InlineData(15, "fifteenth")]
[InlineData(16, "sixteenth")]
[InlineData(17, "seventeenth")]
[InlineData(18, "eighteenth")]
[InlineData(19, "nineteenth")]
[InlineData(20, "twentieth")]
[InlineData(21, "twenty first")]
[InlineData(22, "twenty second")]
[InlineData(30, "thirtieth")]
[InlineData(40, "fortieth")]
[InlineData(50, "fiftieth")]
[InlineData(60, "sixtieth")]
[InlineData(70, "seventieth")]
[InlineData(80, "eightieth")]
[InlineData(90, "ninetieth")]
[InlineData(95, "ninety fifth")]
[InlineData(96, "ninety sixth")]
[InlineData(100, "hundredth")]
[InlineData(120, "hundred and twentieth")]
[InlineData(121, "hundred and twenty first")]
[InlineData(1000, "thousandth")]
[InlineData(1001, "thousand first")]
[InlineData(1021, "thousand and twenty first")]
[InlineData(10000, "ten thousandth")]
[InlineData(10121, "ten thousand one hundred and twenty first")]
[InlineData(100000, "hundred thousandth")]
[InlineData(1000000, "millionth")]
public void ToOrdinalWords(int number, string words)
{
Assert.Equal(words, number.ToOrdinalWords());
}
}
}
}
Loading