From 059745d7599f2cc3d10d3729f51e6cd7a3820a7b Mon Sep 17 00:00:00 2001 From: Daniel Serrano Date: Sun, 23 Jan 2022 16:32:47 +0100 Subject: [PATCH] Adapt Spanish Ordinalizer to allow for abbreviations --- .../Ordinalizers/SpanishOrdinalizer.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs b/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs index a2ddce725..53905d80c 100644 --- a/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs +++ b/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs @@ -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.Masculine, ".º" }, { GrammaticalGender.Feminine, ".ª" }, - { GrammaticalGender.Neuter, GetNeuterMap(number) } + { GrammaticalGender.Masculine, GetWordForm(number, wordForm) }, + { GrammaticalGender.Neuter, GetWordForm(number, wordForm) } }; // N/A in Spanish @@ -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" : ".º"; } } }