Skip to content

Commit

Permalink
Added Spanish Ordinalize localisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
akamud committed Apr 15, 2014
1 parent dba5594 commit 18d47a5
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
2 changes: 1 addition & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###In Development
- [#217](https://github.com/Mehdik/Humanizer/pull/217): Changed OrdinalizeExtensions to better accommodate localisations. Added pt-br Ordinalize localisation.
- [#217](https://github.com/Mehdik/Humanizer/pull/217): Changed OrdinalizeExtensions to better accommodate localisations. Added pt-BR and Spanish Ordinalize localisation.

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

Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="Localisation\cs\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\da\DateHumanizeTests.cs" />
<Compile Include="Localisation\da\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\es\OrdinalizeTests.cs" />
<Compile Include="Localisation\fr-BE\DateHumanizeTests.cs" />
<Compile Include="Localisation\fr-BE\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\fr\DateHumanizeTests.cs" />
Expand Down
91 changes: 91 additions & 0 deletions src/Humanizer.Tests/Localisation/es/OrdinalizeTests.cs
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)
{
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 OrdanizeNumber(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 OrdanizeNumberFeminine(int number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Feminine), ordinalized);
}
}
}
1 change: 1 addition & 0 deletions src/Humanizer/Humanizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="Localisation\NumberToWords\PolishNumberToWordsConverter.cs" />
<Compile Include="Localisation\NumberToWords\RussianNumberToWordsConverter.cs" />
<Compile Include="Localisation\Formatters\HebrewFormatter.cs" />
<Compile Include="Localisation\Ordinalize\SpanishOrdinalizeConverter.cs" />
<Compile Include="Localisation\Ordinalize\DefaultOrdinalizeConverter.cs" />
<Compile Include="Localisation\Ordinalize\EnglishOrdinalizeConverter.cs" />
<Compile Include="Localisation\Ordinalize\BrazilianPortugueseOrdinalizeConverter.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Humanizer.Localisation.Ordinalize
{
internal class SpanishOrdinalizeConverter : DefaultOrdinalizeConverter
{
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 Spanish
if (number == 0)
return "0";

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

return numberString + "º";
}
}
}
1 change: 1 addition & 0 deletions src/Humanizer/OrdinalizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class OrdinalizeExtensions
new Dictionary<string, Func<DefaultOrdinalizeConverter>>
{
{"en", () => new EnglishOrdinalizeConverter()},
{"es", () => new SpanishOrdinalizeConverter()},
{"pt-BR", () => new BrazilianPortugueseOrdinalizeConverter()}
};

Expand Down

0 comments on commit 18d47a5

Please sign in to comment.