-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add number to words localizer for central kurdish
- Loading branch information
1 parent
2ba67c0
commit 253e692
Showing
5 changed files
with
174 additions
and
15 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
78 changes: 78 additions & 0 deletions
78
src/Humanizer.Tests.Shared/Localisation/ku/NumberToWordsTests.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,78 @@ | ||
using Xunit; | ||
|
||
namespace Humanizer.Tests.Localisation.ku | ||
{ | ||
[UseCulture("ku")] | ||
public class NumberToWordsTests | ||
{ | ||
[Theory] | ||
[InlineData(1, "یەک")] | ||
[InlineData(10, "دە")] | ||
[InlineData(11, "یازدە")] | ||
[InlineData(122, "سەد و بیست و دوو")] | ||
[InlineData(3501, "سێ هەزار و پێنج سەد و یەک")] | ||
[InlineData(100, "سەد")] | ||
[InlineData(1000, "یەک هەزار")] | ||
[InlineData(100000, "سەد هەزار")] | ||
[InlineData(1000000, "یەک میلیۆن")] | ||
[InlineData(10000000, "دە میلیۆن")] | ||
[InlineData(100000000, "سەد میلیۆن")] | ||
[InlineData(1000000000, "یەک میلیارد")] | ||
[InlineData(111, "سەد و یازدە")] | ||
[InlineData(1111, "یەک هەزار و سەد و یازدە")] | ||
[InlineData(111111, "سەد و یازدە هەزار و سەد و یازدە")] | ||
[InlineData(1111111, "یەک میلیۆن و سەد و یازدە هەزار و سەد و یازدە")] | ||
[InlineData(11111111, "یازدە میلیۆن و سەد و یازدە هەزار و سەد و یازدە")] | ||
[InlineData(111111111, "سەد و یازدە میلیۆن و سەد و یازدە هەزار و سەد و یازدە")] | ||
[InlineData(1111111111, "یەک میلیارد و سەد و یازدە میلیۆن و سەد و یازدە هەزار و سەد و یازدە")] | ||
[InlineData(123, "سەد و بیست و سێ")] | ||
[InlineData(1234, "یەک هەزار و دوو سەد و سی و چوار")] | ||
[InlineData(12345, "دوازدە هەزار و سێ سەد و چل و پێنج")] | ||
[InlineData(123456, "سەد و بیست و سێ هەزار و چوار سەد و پەنجا و شەش")] | ||
[InlineData(1234567, "یەک میلیۆن و دوو سەد و سی و چوار هەزار و پێنج سەد و شەست و حەوت")] | ||
[InlineData(12345678, "دوازدە میلیۆن و سێ سەد و چل و پێنج هەزار و شەش سەد و حەفتا و هەشت")] | ||
[InlineData(123456789, "سەد و بیست و سێ میلیۆن و چوار سەد و پەنجا و شەش هەزار و حەوت سەد و هەشتا و نۆ")] | ||
[InlineData(1234567890, "یەک میلیارد و دوو سەد و سی و چوار میلیۆن و پێنج سەد و شەست و حەوت هەزار و هەشت سەد و نەوەد")] | ||
public void ToWordsKurdish(int number, string expected) | ||
{ | ||
Assert.Equal(expected, number.ToWords()); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "سفرەم")] | ||
[InlineData(1, "یەکەم")] | ||
[InlineData(2, "دووەم")] | ||
[InlineData(3, "سێیەم")] | ||
[InlineData(4, "چوارەم")] | ||
[InlineData(5, "پێنجەم")] | ||
[InlineData(6, "شەشەم")] | ||
[InlineData(7, "حەوتەم")] | ||
[InlineData(8, "هەشتەم")] | ||
[InlineData(9, "نۆیەم")] | ||
[InlineData(10, "دەیەم")] | ||
[InlineData(11, "یازدەیەم")] | ||
[InlineData(12, "دوازدەیەم")] | ||
[InlineData(13, "سێزدەیەم")] | ||
[InlineData(21, "بیست و یەکەم")] | ||
[InlineData(22, "بیست و دووەم")] | ||
[InlineData(23, "بیست و سێیەم")] | ||
[InlineData(24, "بیست و چوارەم")] | ||
[InlineData(25, "بیست و پێنجەم")] | ||
[InlineData(30, "سییەم")] | ||
[InlineData(40, "چلەم")] | ||
[InlineData(50, "پەنجایەم")] | ||
[InlineData(60, "شەستەم")] | ||
[InlineData(70, "حەفتایەم")] | ||
[InlineData(80, "هەشتایەم")] | ||
[InlineData(90, "نەوەدەم")] | ||
[InlineData(100, "سەدەم")] | ||
[InlineData(200, "دوو سەدەم")] | ||
[InlineData(1000, "یەک هەزارەم")] | ||
[InlineData(1333, "یەک هەزار و سێ سەد و سی و سێیەم")] | ||
[InlineData(1000000, "یەک میلیۆنەم")] | ||
public void ToOrdinalWordsKurdish(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
79 changes: 79 additions & 0 deletions
79
src/Humanizer/Localisation/NumberToWords/CentralKurdishNumberToWordsConverter.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,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Humanizer.Localisation.NumberToWords | ||
{ | ||
internal class CentralKurdishNumberToWordsConverter : GenderlessNumberToWordsConverter | ||
{ | ||
private static readonly string[] KurdishHundredsMap = { "سفر", "سەد", "دوو سەد", "سێ سەد", "چوار سەد", "پێنج سەد", "شەش سەد", "حەوت سەد", "هەشت سەد", "نۆ سەد" }; | ||
private static readonly string[] KurdishTensMap = { "سفر", "دە", "بیست", "سی", "چل", "پەنجا", "شەست", "حەفتا", "هەشتا", "نەوەد" }; | ||
private static readonly string[] KurdishUnitsMap = { "سفر", "یەک", "دوو", "سێ", "چوار", "پێنج", "شەش", "حەوت", "هەشت", "نۆ", "دە", "یازدە", "دوازدە", "سێزدە", "چواردە", "پازدە", "شازدە", "حەڤدە", "هەژدە", "نۆزدە" }; | ||
|
||
public override string Convert(long number) | ||
{ | ||
var largestNumber = (Math.Pow(10, 15) * 1000) - 1; | ||
if (number > largestNumber || number < -largestNumber) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
if (number < 0) | ||
{ | ||
return string.Format("نێگەتیڤ {0}", Convert(-number)); | ||
} | ||
|
||
if (number == 0) | ||
{ | ||
return "سفر"; | ||
} | ||
|
||
var kurdishGroupsMap = new Dictionary<long, Func<long, string>> | ||
{ | ||
{(long)Math.Pow(10, 15), n => string.Format("{0} کوادریلیۆن", Convert(n)) }, | ||
{(long)Math.Pow(10, 12), n => string.Format("{0} تریلیۆن", Convert(n)) }, | ||
{(long)Math.Pow(10, 9), n => string.Format("{0} میلیارد", Convert(n)) }, | ||
{(long)Math.Pow(10, 6), n => string.Format("{0} میلیۆن", Convert(n)) }, | ||
{(long)Math.Pow(10, 3), n => string.Format("{0} هەزار", Convert(n)) }, | ||
{(long)Math.Pow(10, 2), n => KurdishHundredsMap[n]} | ||
}; | ||
|
||
var parts = new List<string>(); | ||
foreach (var group in kurdishGroupsMap.Keys) | ||
{ | ||
if (number / group > 0) | ||
{ | ||
parts.Add(kurdishGroupsMap[group](number / group)); | ||
number %= group; | ||
} | ||
} | ||
|
||
if (number >= 20) | ||
{ | ||
parts.Add(KurdishTensMap[number / 10]); | ||
number %= 10; | ||
} | ||
|
||
if (number > 0) | ||
{ | ||
parts.Add(KurdishUnitsMap[number]); | ||
} | ||
|
||
return string.Join(" و ", parts); | ||
} | ||
|
||
public override string ConvertToOrdinal(int number) | ||
{ | ||
var word = Convert(number); | ||
return string.Format("{0}{1}", word, IsVowel(word[word.Length - 1]) ? "یەم" : "ەم"); | ||
} | ||
|
||
private bool IsVowel(char c) | ||
{ | ||
return c == 'ا' || | ||
c == 'ێ' || | ||
c == 'ۆ' || | ||
c == 'ە' || | ||
c == 'ی'; | ||
} | ||
} | ||
} |