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

Tweaked Spanish Ordinalize and ToOrdinalWords format #222

Closed
wants to merge 3 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,6 +1,7 @@
###In Development
- [#217](https://github.com/Mehdik/Humanizer/pull/217): Changed OrdinalizeExtensions to better accommodate localisations. Added pt-BR and Spanish Ordinalize localisation.
- [#221](https://github.com/Mehdik/Humanizer/pull/221): Added Russian ordinalizer
- [#222](https://github.com/Mehdik/Humanizer/pull/222): Updated Ordinalize and ToOrdinalWords to account for special exceptions with 1 and 3.

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.22.1...master)

Expand Down
7 changes: 6 additions & 1 deletion src/Humanizer.Tests/Localisation/es/NumberToWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ public void ToWords(int number, string expected)
}

[Theory]
[InlineData(1, "primero", null)]
[InlineData(1, "primer", null)]
[InlineData(1, "primer", GrammaticalGender.Masculine)]
[InlineData(1, "primera", GrammaticalGender.Feminine)]
[InlineData(2, "segundo", GrammaticalGender.Masculine)]
[InlineData(2, "segunda", GrammaticalGender.Feminine)]
[InlineData(2, "segundo", GrammaticalGender.Neuter)]
[InlineData(3, "tercer", null)]
[InlineData(3, "tercer", GrammaticalGender.Masculine)]
[InlineData(3, "tercera", GrammaticalGender.Feminine)]
[InlineData(11, "once", null)]
public void ToOrdinalWords(int number, string words, GrammaticalGender gender)
{
Expand Down
100 changes: 50 additions & 50 deletions src/Humanizer.Tests/Localisation/es/OrdinalizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,77 @@ public OrdinalizeTests()

[Theory]
[InlineData("0", "0")]
[InlineData("1", "")]
[InlineData("2", "")]
[InlineData("3", "")]
[InlineData("4", "")]
[InlineData("5", "")]
[InlineData("6", "")]
[InlineData("23", "23º")]
[InlineData("100", "100º")]
[InlineData("101", "101º")]
[InlineData("102", "102º")]
[InlineData("103", "103º")]
[InlineData("1001", "1001º")]
[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", "")]
[InlineData("2", "")]
[InlineData("3", "")]
[InlineData("4", "")]
[InlineData("5", "")]
[InlineData("6", "")]
[InlineData("23", "23ª")]
[InlineData("100", "100ª")]
[InlineData("101", "101ª")]
[InlineData("102", "102ª")]
[InlineData("103", "103ª")]
[InlineData("1001", "1001ª")]
[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, "")]
[InlineData(2, "")]
[InlineData(3, "")]
[InlineData(4, "")]
[InlineData(5, "")]
[InlineData(6, "")]
[InlineData(10, "10º")]
[InlineData(23, "23º")]
[InlineData(100, "100º")]
[InlineData(101, "101º")]
[InlineData(102, "102º")]
[InlineData(103, "103º")]
[InlineData(1001, "1001º")]
[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, "")]
[InlineData(2, "")]
[InlineData(3, "")]
[InlineData(4, "")]
[InlineData(5, "")]
[InlineData(6, "")]
[InlineData(10, "10ª")]
[InlineData(23, "23ª")]
[InlineData(100, "100ª")]
[InlineData(101, "101ª")]
[InlineData(102, "102ª")]
[InlineData(103, "103ª")]
[InlineData(1001, "1001ª")]
[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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Humanizer.Localisation.NumberToWords
{
internal class SpanishNumberToWordsConverter : DefaultNumberToWordsConverter
{
private static readonly string[] HundredsMap = { "cero", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos" };
private static readonly string[] UnitsMap = { "cero", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve" };
private static readonly string[] TensMap = { "cero", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa" };
private static readonly string[] HundredsMap = { "cero", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos" };

private static readonly Dictionary<int, string> Ordinals = new Dictionary<int, string>
{
Expand Down Expand Up @@ -95,8 +95,11 @@ public override string ConvertToOrdinal(int number, GrammaticalGender gender = G
string towords;
if (!Ordinals.TryGetValue(number, out towords))
towords = Convert(number);

if (gender == GrammaticalGender.Feminine)
towords = towords.TrimEnd('o') + "a";
else if(number % 10 == 1 || number % 10 == 3)
towords = towords.TrimEnd('o');

return towords;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public override string Convert(int number, string numberString, GrammaticalGende
return "0";

if (gender == GrammaticalGender.Feminine)
return numberString + "ª";

return numberString + "º";
return numberString + ".ª";
else
return numberString + ".º";
}
}
}