Skip to content

Commit

Permalink
Adapt Spanish Ordinalizer to allow for abbreviations
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Serrano committed Jan 27, 2022
1 parent 2c38b39 commit 059745d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ internal class SpanishOrdinalizer : DefaultOrdinalizer
{
public override string Convert(int number, string numberString)
{
return Convert(number, numberString, GrammaticalGender.Masculine);
return Convert(number, numberString, GrammaticalGender.Masculine, WordForm.Normal);
}

public override string Convert(int number, string numberString, GrammaticalGender gender)
{
return Convert(number, numberString, gender, WordForm.Normal);
}

public override string Convert(int number, string numberString, GrammaticalGender gender, WordForm wordForm)
{
var genderMap = new Dictionary<GrammaticalGender, string>()
{
{ GrammaticalGender.Masculine, ".º" },
{ GrammaticalGender.Feminine, ".ª" },
{ GrammaticalGender.Neuter, GetNeuterMap(number) }
{ GrammaticalGender.Masculine, GetWordForm(number, wordForm) },
{ GrammaticalGender.Neuter, GetWordForm(number, wordForm) }
};

// N/A in Spanish
Expand All @@ -33,14 +38,14 @@ public override string Convert(int number, string numberString, GrammaticalGende
return $"{numberString}{genderMap[gender]}";
}

private static string GetNeuterMap(int number)
private static string GetNumberString(int number)
{
return (number % 10 == 1 || number % 10 == 3) ? ".er" : ".º";
return number.ToString(new CultureInfo("es-ES"));
}

private static string GetNumberString(int number)
private static string GetWordForm(int number, WordForm wordForm)
{
return number.ToString(CultureInfo.InvariantCulture);
return (number % 10 == 1 || number % 10 == 3) && wordForm == WordForm.Abbreviation ? ".er" : ".º";
}
}
}

0 comments on commit 059745d

Please sign in to comment.