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

Add Greek for To Ordinal Words #1090

Merged
merged 2 commits into from
Jul 3, 2021
Merged
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
42 changes: 42 additions & 0 deletions src/Humanizer.Tests/Localisation/el/NumberToOrdinalWordsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xunit;

namespace Humanizer.Tests.Localisation.el
{

[UseCulture("el")]
public class NumberToOrdinalWordsTests
{
[InlineData(-1, "")]
[InlineData(0, "")]
[InlineData(1, "πρώτος")]
[InlineData(10, "δέκατος")]
[InlineData(11, "ενδέκατος")]
[InlineData(12, "δωδέκατος")]
[InlineData(20, "εικοστός")]
[InlineData(31, "τριακοστός πρώτος")]
[InlineData(100, "εκατοστός")]
[InlineData(105, "εκατοστός πέμπτος")]
[InlineData(286, "διακοσιοστός ογδοηκοστός έκτος")]
[InlineData(530, "πεντακοσιοστός τριακοστός")]
[InlineData(912, "εννιακοσιοστός δωδέκατος")]
[InlineData(1203, "χιλιοστός διακοσιοστός τρίτος")]
[InlineData(1596, "χιλιοστός πεντακοσιοστός ενενηκοστός έκτος")]
[InlineData(1061, "χιλιοστός εξηκοστός πρώτος")]
[InlineData(1008, "χιλιοστός όγδοος")]
[InlineData(1211, "χιλιοστός διακοσιοστός ενδέκατος")]
[InlineData(1999, "χιλιοστός εννιακοσιοστός ενενηκοστός ένατος")]
[InlineData(2000, "")]

[Theory]
public void ToOrdinalWordsInt(int number, string expected)
{
Assert.Equal(expected, number.ToOrdinalWords());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@ internal class GreekNumberToWordsConverter : GenderlessNumberToWordsConverter

private readonly string[] HundredsMap = { "", "εκατόν", "διακόσιες", "τριακόσιες", "τετρακόσιες", "πεντακόσιες", "εξακόσιες", "επτακόσιες", "οκτακόσιες", "Εενιακόσιες" };

private static readonly Dictionary<long, string> ΟrdinalMap = new()
{
{ 0, string.Empty },
{ 1, "πρώτος" },
{ 2, "δεύτερος" },
{ 3, "τρίτος" },
{ 4, "τέταρτος" },
{ 5, "πέμπτος" },
{ 6, "έκτος" },
{ 7, "έβδομος" },
{ 8, "όγδοος" },
{ 9, "ένατος" },
{ 10, "δέκατος" },
{ 20, "εικοστός" },
{ 30, "τριακοστός" },
{ 40, "τεσσαρακοστός" },
{ 50, "πεντηκοστός" },
{ 60, "εξηκοστός" },
{ 70, "εβδομηκοστός" },
{ 80, "ογδοηκοστός" },
{ 90, "ενενηκοστός" },
{ 100, "εκατοστός" },
{ 200, "διακοσιοστός" },
{ 300, "τριακοσιοστός" },
{ 400, "τετρακοσιστός" },
{ 500, "πεντακοσιοστός" },
{ 600, "εξακοσιοστός" },
{ 700, "εφτακοσιοστός" },
{ 800, "οχτακοσιοστός" },
{ 900, "εννιακοσιοστός" },
{ 1000, "χιλιοστός" }
};


public override string Convert(long number)
{
Expand All @@ -26,7 +59,99 @@ public override string Convert(long number)

public override string ConvertToOrdinal(int number)
{
return null;
if (number / 10 == 0)
{
return GetOneDigitOrdinal(number);
}

if (number / 10 > 0 && number / 10 < 10)
{
return GetTwoDigigOrdinal(number);

}

if (number / 100 > 0 && number / 100 < 10)
{
return GetThreeDigitOrdinal(number);
}

if (number / 1000 > 0 && number / 1000 < 10)
{
return GetFourDigitOrdinal(number);
}

return string.Empty;
}


private string GetOneDigitOrdinal(int number)
{
if (!ΟrdinalMap.TryGetValue(number, out var output)) return string.Empty;

return output;
}

private string GetTwoDigigOrdinal(int number)
{
if (number == 11) return "ενδέκατος";
if (number == 12) return "δωδέκατος";

var decades = number / 10;

if (!ΟrdinalMap.TryGetValue(decades*10, out var decadesString)) return string.Empty;

if(number -decades*10 > 0)
{
return decadesString + " " + GetOneDigitOrdinal(number - decades * 10);
}

return decadesString;
}

private string GetThreeDigitOrdinal(int number)
{

var hundrends = number / 100;

if (!ΟrdinalMap.TryGetValue(hundrends*100, out var hundrentsString)) return string.Empty;

if (number - hundrends*100> 10)
{
return hundrentsString + " " + GetTwoDigigOrdinal(number - hundrends*100);
}

if(number - hundrends * 100 > 0)
{
return hundrentsString + " " + GetOneDigitOrdinal(number - hundrends*100);
}

return hundrentsString;
}

private string GetFourDigitOrdinal(int number)
{

var thousands = number / 1000;

if (!ΟrdinalMap.TryGetValue(thousands*1000, out var thousandsString)) return string.Empty;

if (number - thousands * 1000 > 100)
{
return thousandsString + " " + GetThreeDigitOrdinal(number - thousands*1000);
}

if (number - thousands * 1000 > 10)
{
return thousandsString + " " + GetTwoDigigOrdinal(number - thousands * 1000);
}

if (number - thousands * 1000 > 0)
{
return thousandsString + " " + GetOneDigitOrdinal(number - thousands * 1000);
}

return thousandsString;

}

private string ConvertImpl(long number, bool returnPluralized)
Expand Down