-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'slovenian-NumberToWords'
- Loading branch information
Showing
6 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests.Localisation.sl | ||
{ | ||
public class NumberToWordsTests : AmbientCulture | ||
{ | ||
public NumberToWordsTests() : base("sl-SI") { } | ||
|
||
[Theory] | ||
[InlineData(0, "nič")] | ||
[InlineData(1, "ena")] | ||
[InlineData(2, "dva")] | ||
[InlineData(3, "tri")] | ||
[InlineData(4, "štiri")] | ||
[InlineData(5, "pet")] | ||
[InlineData(6, "šest")] | ||
[InlineData(7, "sedem")] | ||
[InlineData(8, "osem")] | ||
[InlineData(9, "devet")] | ||
[InlineData(10, "deset")] | ||
[InlineData(20, "dvajset")] | ||
[InlineData(30, "trideset")] | ||
[InlineData(40, "štirideset")] | ||
[InlineData(50, "petdeset")] | ||
[InlineData(60, "šestdeset")] | ||
[InlineData(70, "sedemdeset")] | ||
[InlineData(80, "osemdeset")] | ||
[InlineData(90, "devetdeset")] | ||
[InlineData(100, "sto")] | ||
[InlineData(200, "dvesto")] | ||
[InlineData(1000, "tisoč")] | ||
[InlineData(10000, "deset tisoč")] | ||
[InlineData(100000, "sto tisoč")] | ||
[InlineData(1000000, "milijon")] | ||
[InlineData(10000000, "deset milijonov")] | ||
[InlineData(100000000, "sto milijonov")] | ||
[InlineData(1000000000, "milijarda")] | ||
[InlineData(2000000000, "dve milijardi")] | ||
[InlineData(122, "sto dvaindvajset")] | ||
[InlineData(3501, "tri tisoč petsto ena")] | ||
[InlineData(111, "sto enajst")] | ||
[InlineData(1112, "tisoč sto dvanajst")] | ||
[InlineData(11213, "enajst tisoč dvesto trinajst")] | ||
[InlineData(121314, "sto enaindvajset tisoč tristo štirinajst")] | ||
[InlineData(2132415, "dva milijona sto dvaintrideset tisoč štiristo petnajst")] | ||
[InlineData(12345516, "dvanajst milijonov tristo petinštirideset tisoč petsto šestnajst")] | ||
[InlineData(751633617, "sedemsto enainpetdeset milijonov šeststo triintrideset tisoč šeststo sedemnajst")] | ||
[InlineData(1111111118, "milijarda sto enajst milijonov sto enajst tisoč sto osemnajst")] | ||
[InlineData(-751633619, "minus sedemsto enainpetdeset milijonov šeststo triintrideset tisoč šeststo devetnajst")] | ||
public void ToWords(int number, string expected) | ||
{ | ||
Assert.Equal(expected, number.ToWords()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Humanizer.Localisation.NumberToWords | ||
{ | ||
internal class SlovenianNumberToWordsConverter : DefaultNumberToWordsConverter | ||
{ | ||
private static readonly string[] UnitsMap = {"nič", "ena", "dva", "tri", "štiri", "pet", "šest", "sedem", "osem", "devet", "deset", "enajst", "dvanajst", "trinajst", "štirinajst", "petnajst", "šestnajst", "sedemnajst", "osemnajst", "devetnajst"}; | ||
private static readonly string[] TensMap = {"nič", "deset", "dvajset", "trideset", "štirideset", "petdeset", "šestdeset", "sedemdeset", "osemdeset", "devetdeset"}; | ||
|
||
public override string Convert(int number) | ||
{ | ||
if (number == 0) | ||
return "nič"; | ||
|
||
if (number < 0) | ||
return string.Format("minus {0}", Convert(-number)); | ||
|
||
var parts = new List<string>(); | ||
|
||
var billions = number / 1000000000; | ||
if (billions > 0) | ||
{ | ||
parts.Add(Part("milijarda", "dve milijardi", "{0} milijarde", "{0} milijard", billions)); | ||
number %= 1000000000; | ||
if (number > 0) | ||
parts.Add(" "); | ||
} | ||
|
||
var millions = number / 1000000; | ||
if (millions > 0) | ||
{ | ||
parts.Add(Part("milijon", "dva milijona", "{0} milijone", "{0} milijonov", millions)); | ||
number %= 1000000; | ||
if (number > 0) | ||
parts.Add(" "); | ||
} | ||
|
||
var thousands = number / 1000; | ||
if (thousands > 0) | ||
{ | ||
parts.Add(Part("tisoč", "dva tisoč", "{0} tisoč", "{0} tisoč", thousands)); | ||
number %= 1000; | ||
if (number > 0) | ||
parts.Add(" "); | ||
} | ||
|
||
var hundreds = number / 100; | ||
if (hundreds > 0) | ||
{ | ||
parts.Add(Part("sto", "dvesto", "{0}sto", "{0}sto", hundreds)); | ||
number %= 100; | ||
if (number > 0) | ||
parts.Add(" "); | ||
} | ||
|
||
if (number > 0) | ||
{ | ||
if (number < 20) | ||
{ | ||
if (number > 1) | ||
parts.Add(UnitsMap[number]); | ||
else | ||
parts.Add("ena"); | ||
} | ||
else | ||
{ | ||
var units = number % 10; | ||
if (units > 0) | ||
parts.Add(string.Format("{0}in", UnitsMap[units])); | ||
|
||
parts.Add(TensMap[number / 10]); | ||
} | ||
} | ||
|
||
return string.Join("", parts); | ||
} | ||
|
||
private string Part(string singular, string dual, string trialQuadral, string plural, int number) | ||
{ | ||
if (number == 1) | ||
return singular; | ||
|
||
if (number == 2) | ||
return dual; | ||
|
||
if (number == 3 || number == 4) | ||
return string.Format(trialQuadral, Convert(number)); | ||
|
||
return string.Format(plural, Convert(number)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters