-
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 pull request #312 from erdemergin/master
- Loading branch information
Showing
8 changed files
with
201 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,75 @@ | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests.Localisation.tr | ||
{ | ||
public class NumberToWordsTests : AmbientCulture | ||
{ | ||
public NumberToWordsTests() : base("tr") { } | ||
|
||
[Theory] | ||
[InlineData("sıfır", 0)] | ||
[InlineData("bir", 1)] | ||
[InlineData("iki", 2)] | ||
[InlineData("on", 10)] | ||
[InlineData("yüz on iki", 112)] | ||
[InlineData("bin dört yüz kırk", 1440)] | ||
[InlineData("yirmi iki", 22)] | ||
[InlineData("on bir", 11)] | ||
[InlineData("üç bin beş yüz bir", 3501)] | ||
[InlineData("bir milyon bir", 1000001)] | ||
[InlineData("eksi bir milyon üç yüz kırk altı bin yedi yüz on bir", -1346711)] | ||
public void ToWords(string expected, int number) | ||
{ | ||
Assert.Equal(expected, number.ToWords()); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "sıfırıncı")] | ||
[InlineData(1, "birinci")] | ||
[InlineData(2, "ikinci")] | ||
[InlineData(3, "üçüncü")] | ||
[InlineData(4, "dördüncü")] | ||
[InlineData(5, "beşinci")] | ||
[InlineData(6, "altıncı")] | ||
[InlineData(7, "yedinci")] | ||
[InlineData(8, "sekizinci")] | ||
[InlineData(9, "dokuzuncu")] | ||
[InlineData(10, "onuncu")] | ||
[InlineData(11, "on birinci")] | ||
[InlineData(12, "on ikinci")] | ||
[InlineData(13, "on üçüncü")] | ||
[InlineData(14, "on dördüncü")] | ||
[InlineData(15, "on beşinci")] | ||
[InlineData(16, "on altıncı")] | ||
[InlineData(17, "on yedinci")] | ||
[InlineData(18, "on sekizinci")] | ||
[InlineData(19, "on dokuzuncu")] | ||
[InlineData(20, "yirminci")] | ||
[InlineData(21, "yirmi birinci")] | ||
[InlineData(30, "otuzuncu")] | ||
[InlineData(40, "kırkıncı")] | ||
[InlineData(50, "ellinci")] | ||
[InlineData(60, "altmışıncı")] | ||
[InlineData(70, "yetmişinci")] | ||
[InlineData(80, "sekseninci")] | ||
[InlineData(90, "doksanıncı")] | ||
[InlineData(100, "yüzüncü")] | ||
[InlineData(120, "yüz yirminci")] | ||
[InlineData(121, "yüz yirmi birinci")] | ||
[InlineData(200, "iki yüzüncü")] | ||
[InlineData(221, "iki yüz yirmi birinci")] | ||
[InlineData(300, "üç yüzüncü")] | ||
[InlineData(321, "üç yüz yirmi birinci")] | ||
[InlineData(1000, "bininci")] | ||
[InlineData(1001, "bin birinci")] | ||
[InlineData(10000, "on bininci")] | ||
[InlineData(100000, "yüz bininci")] | ||
[InlineData(1000000, "bir milyonuncu")] | ||
[InlineData(1022135, "bir milyon yirmi iki bin yüz otuz beşinci")] | ||
public void ToOrdinalWords(int number, string words) | ||
{ | ||
Assert.Equal(words, number.ToOrdinalWords()); | ||
} | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.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,105 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Humanizer.Localisation.NumberToWords | ||
{ | ||
internal class TurkishNumberToWordConverter : GenderlessNumberToWordsConverter | ||
{ | ||
private static readonly string[] UnitsMap = { "sıfır", "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz" }; | ||
private static readonly string[] TensMap = { "sıfır", "on", "yirmi", "otuz", "kırk", "elli", "altmış", "yetmiş", "seksen", "doksan" }; | ||
|
||
private static readonly Dictionary<char, string> OrdinalSuffix = new Dictionary<char, string> | ||
{ | ||
{'ı', "ıncı"}, | ||
{'i', "inci"}, | ||
{'u', "uncu"}, | ||
{'ü', "üncü"}, | ||
{'o', "uncu"}, | ||
{'ö', "üncü"}, | ||
{'e', "inci"}, | ||
{'a', "ıncı"}, | ||
}; | ||
|
||
public override string Convert(int number) | ||
{ | ||
if (number == 0) | ||
return UnitsMap[0]; | ||
|
||
if (number < 0) | ||
return string.Format("eksi {0}", Convert(-number)); | ||
|
||
var parts = new List<string>(); | ||
|
||
if ((number / 1000000000) > 0) | ||
{ | ||
parts.Add(string.Format("{0} milyar", Convert(number / 1000000000))); | ||
number %= 1000000000; | ||
} | ||
|
||
if ((number / 1000000) > 0) | ||
{ | ||
parts.Add(string.Format("{0} milyon", Convert(number / 1000000))); | ||
number %= 1000000; | ||
} | ||
|
||
var thousand = (number / 1000); | ||
if (thousand > 0) | ||
{ | ||
parts.Add(string.Format("{0} bin", thousand > 1 ? Convert(thousand) : "").Trim()); | ||
number %= 1000; | ||
} | ||
|
||
var hundred = (number / 100); | ||
if (hundred > 0) | ||
{ | ||
parts.Add(string.Format("{0} yüz", hundred > 1 ? Convert(number / 100) : "").Trim()); | ||
number %= 100; | ||
} | ||
|
||
if ((number / 10) > 0) | ||
{ | ||
parts.Add(TensMap[number / 10]); | ||
number %= 10; | ||
} | ||
|
||
if (number > 0) | ||
{ | ||
parts.Add(UnitsMap[number]); | ||
} | ||
|
||
string toWords = string.Join(" ", parts.ToArray()); | ||
|
||
return toWords; | ||
} | ||
|
||
public override string ConvertToOrdinal(int number) | ||
{ | ||
var word = Convert(number); | ||
var wordSuffix = string.Empty; | ||
var wordChars = word.ToCharArray().Reverse().ToArray(); | ||
var suffixFoundOnLastVowel = false; | ||
|
||
for (int i = 0; i < wordChars.Count(); i++) | ||
{ | ||
wordSuffix = (from suffix in OrdinalSuffix where suffix.Key == wordChars[i] select suffix.Value).FirstOrDefault(); | ||
if (!string.IsNullOrEmpty(wordSuffix)) | ||
{ | ||
suffixFoundOnLastVowel = i == 0; | ||
break; | ||
} | ||
} | ||
|
||
if (wordChars[0] == 't') | ||
word = word.Substring(0, word.Length - 1) + 'd'; | ||
|
||
if (suffixFoundOnLastVowel) | ||
word = word.Substring(0, word.Length - 1); | ||
|
||
return String.Format("{0}{1}", word, wordSuffix); | ||
} | ||
|
||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Humanizer/Localisation/Ordinalizers/TurkishOrdinalizer.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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Humanizer.Localisation.Ordinalizers | ||
{ | ||
internal class TurkishOrdinalizer : DefaultOrdinalizer | ||
{ | ||
public override string Convert(int number, string numberString) | ||
{ | ||
return numberString + "."; | ||
} | ||
} | ||
} |