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

Added Russian, German and Spanish languages for ListItemTextGetter_* classes #44

Open
wants to merge 20 commits into
base: vNext
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
52 changes: 52 additions & 0 deletions OpenXmlPowerTools.Tests/ListItemTextGetter_ru_RUTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Xunit;
using OpenXmlPowerTools;

#if !ELIDE_XUNIT_TESTS

namespace OpenXmlPowerTools.Tests
{
public class ListItemTextGetter_ru_RUTests
{
[Theory]
[InlineData(1, "1-ый")]
[InlineData(2, "2-ой")]
[InlineData(3, "3-ий")]
[InlineData(4, "4-ый")]
[InlineData(5, "5-ый")]
[InlineData(6, "6-ой")]
[InlineData(7, "7-ой")]
[InlineData(8, "8-ой")]
[InlineData(9, "9-ый")]
[InlineData(10, "10-ый")]
[InlineData(11, "11-ый")]
[InlineData(12, "12-ый")]
[InlineData(13, "13-ый")]
[InlineData(14, "14-ый")]
[InlineData(16, "16-ый")]
[InlineData(17, "17-ый")]
[InlineData(18, "18-ый")]
[InlineData(19, "19-ый")]
[InlineData(20, "20-ый")]
[InlineData(23, "23-ий")]
[InlineData(25, "25-ый")]
[InlineData(50, "50-ый")]
[InlineData(56, "56-ой")]
[InlineData(67, "67-ой")]
[InlineData(78, "78-ой")]
[InlineData(100, "100-ый")]
[InlineData(123, "123-ий")]
[InlineData(125, "125-ый")]
[InlineData(1050, "1050-ый")]
public void GetListItemText_Ordinal(int integer, string expectedText)
{
string actualText = ListItemTextGetter_ru_RU.GetListItemText("", integer, "ordinal");

Assert.Equal(expectedText, actualText);
}
}
}

#endif
122 changes: 0 additions & 122 deletions OpenXmlPowerTools/GetListItemText_ru_RU.cs

This file was deleted.

2 changes: 2 additions & 0 deletions OpenXmlPowerTools/ListItemRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ListItemRetrieverSettings
{"fr-FR", ListItemTextGetter_fr_FR.GetListItemText},
{"tr-TR", ListItemTextGetter_tr_TR.GetListItemText},
{"ru-RU", ListItemTextGetter_ru_RU.GetListItemText},
{"de-DE", ListItemTextGetter_de_DE.GetListItemText},
{"es-ES", ListItemTextGetter_es_ES.GetListItemText},
{"sv-SE", ListItemTextGetter_sv_SE.GetListItemText},
{"zh-CN", ListItemTextGetter_zh_CN.GetListItemText},
};
Expand Down
150 changes: 150 additions & 0 deletions OpenXmlPowerTools/ListItemTextGetter_de_DE.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenXmlPowerTools
{
public class ListItemTextGetter_de_DE
{
private static string[] OneThroughNineteen = {
"eins", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht",
"nuen", "zehn", "elf", "zwölf", "dreizehn", "vierzehn",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace nuen with neun everywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I fixed that.

"fünfzehn", "sechzehn", "siebzehn", "achtzehn", "nuenzehn"
};

private static string[] Tens = {
"zehn", "zwanzig", "dreißig", "vierzig", "fünfzig", "sechzig", "siebzig",
"achtzig", "nuenzig"
};

private static string[] OrdinalOneThroughNineteen = {
"erste", "zweite", "dritte", "vierte", "fünfte", "sechste",
"siebte", "achte", "nuente", "zehnte", "elfte", "zwölfte",
"dreizehnte", "vierzehnte", "fünfzehnte", "sechzehnte",
"siebzehnte", "achtzehnte", "nuenzehnte"
};

private static string[] OrdinalTens = {
"zehnte", "zwanzigste", "dreißigste", "vierzigste", "fünfzigste",
"sechzigste", "siebzigste", "achtzigste", "nuenzigste"
};

public static string GetListItemText(string languageCultureName, int levelNumber, string numFmt)
{
if (levelNumber > 19999)
throw new ArgumentOutOfRangeException("levelNumber", "Convering a levelNumber to ordinal text that is greater then 19 999 is not supported");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace Convering with Converting in all of the language-related files of the commit. I recommend to write "19 999" as "19999" because the thausand separator is different in different languages (in English it is a ,).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done. I also found and fixed a few more typos in the code. Additionally, I added tests for German and Spanish.

if (levelNumber == 0)
return "Zero";
if (levelNumber < 0)
throw new ArgumentOutOfRangeException("levelNumber", "Converting a negative levelNumber to ordinal text is not supported");

if (numFmt == "ordinal")
return GetOrdinal(levelNumber);
if (numFmt == "cardinalText")
return GetCardinalText(levelNumber);
if (numFmt == "ordinalText")
return GetOrdinalText(levelNumber);
return null;
}

private static string GetOrdinal(int levelNumber)
{
string suffix;
if (levelNumber % 100 == 11)
suffix = "-te";
else if (levelNumber % 10 == 1)
suffix = "-ste";
else
suffix = "-te";
return levelNumber.ToString() + suffix;
}

private static string GetCardinalText(int levelNumber)
{
string result = "";

// Get thousands
int t1 = levelNumber / 1000;
int t2 = levelNumber % 1000;
if (t1 >= 1)
result += (t1 == 1 ? "ein" : OneThroughNineteen[t1 - 1]) + " thausend";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace thausend with tausend everywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I fixed that.

if (t1 >= 1 && t2 == 0)
return result.Substring(0, 1).ToUpper() + result.Substring(1);
if (t1 >= 1)
result += " ";

// Get hundreds
int h1 = (levelNumber % 1000) / 100;
int h2 = levelNumber % 100;
if (h1 >= 1)
result += (h1 == 1 ? "ein" : OneThroughNineteen[h1 - 1]) + " hundert";
if (h1 >= 1 && h2 == 0)
return result.Substring(0, 1).ToUpper() + result.Substring(1);
if (h1 >= 1)
result += " ";

// Tens and ones
int z = levelNumber % 100;
if (z <= 19)
result += OneThroughNineteen[z - 1];
else
{
int x = z / 10;
int r = z % 10;
if (r >= 1)
result += (r == 1 ? "ein" : OneThroughNineteen[r - 1]) + "und";
result += Tens[x - 1];
}
return result.Substring(0, 1).ToUpper() + result.Substring(1);
}

private static string GetOrdinalText(int levelNumber)
{
string result = "";

// Get thousands
int t1 = levelNumber / 1000;
int t2 = levelNumber % 1000;
if (t1 >= 1 && t2 != 0)
result += (t1 == 1 ? "ein" : OneThroughNineteen[t1 - 1]) + " thausend";
if (t1 >= 1 && t2 == 0)
{
result += (t1 == 1 ? "ein" : OneThroughNineteen[t1 - 1]) + " thausendste";
return result.Substring(0, 1).ToUpper() + result.Substring(1);
}
if (t1 >= 1)
result += " ";

// Get hundreds
int h1 = (levelNumber % 1000) / 100;
int h2 = levelNumber % 100;
if (h1 >= 1 && h2 != 0)
result += (h1 == 1 ? "ein" : OneThroughNineteen[h1 - 1]) + " hundert";
if (h1 >= 1 && h2 == 0)
{
result += (h1 == 1 ? "ein" : OneThroughNineteen[h1 - 1]) + " hundertste";
return result.Substring(0, 1).ToUpper() + result.Substring(1);
}
if (h1 >= 1)
result += " ";

// Get tens and ones
int z = levelNumber % 100;
if (z <= 19)
result += OrdinalOneThroughNineteen[z - 1];
else
{
int x = z / 10;
int r = z % 10;
if (r >= 1)
result += (r == 1 ? "ein" : OneThroughNineteen[r - 1]) + "und";
result += OrdinalTens[x - 1];
}
return result.Substring(0, 1).ToUpper() + result.Substring(1);
}
}
}
Loading