-
Notifications
You must be signed in to change notification settings - Fork 966
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
Changed OrdinalizeExtensions to better accommodate localisations. #217
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
caa1e3d
Changed OrdinalizeExtensions to better accommodate localisations.
akamud dba5594
Added PR #217 in release notes.
akamud 18d47a5
Added Spanish Ordinalize localisation.
akamud b353f33
Added an extra test to show that some cultures (en) ignore Grammatica…
akamud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests.Localisation.es | ||
{ | ||
public class OrdinalizeTests : AmbientCulture | ||
{ | ||
public OrdinalizeTests() | ||
: base("es-ES") | ||
{ | ||
} | ||
|
||
[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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Never mind. I see the reason now. |
||
{ | ||
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(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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests.Localisation.ptBR | ||
{ | ||
public class OrdinalizeTests : AmbientCulture | ||
{ | ||
public OrdinalizeTests() | ||
: base("pt-BR") | ||
{ | ||
} | ||
|
||
[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(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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Humanizer/Localisation/Ordinalizer/BrazilianPortugueseOrdinalizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Humanizer.Localisation.Ordinalizer | ||
{ | ||
internal class BrazilianPortugueseOrdinalizer : 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) | ||
{ | ||
// N/A in Portuguese | ||
if (number == 0) | ||
return "0"; | ||
|
||
if (gender == GrammaticalGender.Feminine) | ||
return numberString + "ª"; | ||
|
||
return numberString + "º"; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Humanizer/Localisation/Ordinalizer/DefaultOrdinalizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Humanizer.Localisation.Ordinalizer | ||
{ | ||
internal class DefaultOrdinalizer | ||
{ | ||
public virtual string Convert(int number, string numberString, GrammaticalGender gender) | ||
{ | ||
return Convert(number, numberString); | ||
} | ||
|
||
public virtual string Convert(int number, string numberString) | ||
{ | ||
return numberString; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need unit tests to verify this assumption.