From 3e6db9bc799041f6c8258beeeb0180e635631852 Mon Sep 17 00:00:00 2001 From: mxurshid Date: Wed, 22 Oct 2014 18:35:13 +0500 Subject: [PATCH 1/2] Added Uzbek localization and tests --- src/Humanizer.Tests/Humanizer.Tests.csproj | 8 + .../uz-Cyrl-UZ/DateHumanizeTests.cs | 118 +++++++++ .../uz-Cyrl-UZ/NumberToWordsTests.cs | 109 ++++++++ .../uz-Cyrl-UZ/TimeSpanHumanizeTests.cs | 73 ++++++ .../uz-Latn-UZ/DateHumanizeTests.cs | 118 +++++++++ .../uz-Latn-UZ/NumberToWordsTests.cs | 109 ++++++++ .../uz-Latn-UZ/TimeSpanHumanizeTests.cs | 73 ++++++ .../Configuration/FormatterRegistry.cs | 2 + .../NumberToWordsConverterRegistry.cs | 2 + src/Humanizer/Humanizer.csproj | 9 + .../UzbekCyrlNumberToWordConverter.cs | 86 +++++++ .../UzbekLatnNumberToWordConverter.cs | 86 +++++++ .../Properties/Resources.uz-Cyrl-UZ.resx | 234 ++++++++++++++++++ .../Properties/Resources.uz-Latn-UZ.resx | 234 ++++++++++++++++++ 14 files changed, 1261 insertions(+) create mode 100644 src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/DateHumanizeTests.cs create mode 100644 src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/NumberToWordsTests.cs create mode 100644 src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs create mode 100644 src/Humanizer.Tests/Localisation/uz-Latn-UZ/DateHumanizeTests.cs create mode 100644 src/Humanizer.Tests/Localisation/uz-Latn-UZ/NumberToWordsTests.cs create mode 100644 src/Humanizer.Tests/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs create mode 100644 src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs create mode 100644 src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs create mode 100644 src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx create mode 100644 src/Humanizer/Properties/Resources.uz-Latn-UZ.resx diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 5ac60c407..7b83281a8 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -136,9 +136,17 @@ + + + + + Code + + + diff --git a/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/DateHumanizeTests.cs new file mode 100644 index 000000000..90acaf733 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/DateHumanizeTests.cs @@ -0,0 +1,118 @@ +using Humanizer.Localisation; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.uzCyrl +{ + public class DateHumanizeTests : AmbientCulture + { + public DateHumanizeTests() + : base("uz-Cyrl-UZ") + { + } + + [Theory] + [InlineData(1, "бир сония аввал")] + [InlineData(10, "10 секунд аввал")] + public void SecondsAgo(int seconds, string expected) + { + var cul = System.Threading.Thread.CurrentThread.CurrentCulture; + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); + } + + [Theory] + [InlineData(1, "бир сониядан сўнг")] + [InlineData(10, "10 секунддан сўнг")] + public void SecondsFromNow(int seconds, string expected) + { + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); + } + + [Theory] + [InlineData(1, "бир дақиқа аввал")] + [InlineData(10, "10 минут аввал")] + [InlineData(60, "бир соат аввал")] + public void MinutesAgo(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); + } + + [Theory] + [InlineData(1, "бир дақиқадан сўнг")] + [InlineData(10, "10 минутдан сўнг")] + public void MinutesFromNow(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); + } + + [Theory] + [InlineData(1, "бир соат аввал")] + [InlineData(10, "10 соат аввал")] + public void HoursAgo(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); + } + + [Theory] + [InlineData(1, "бир соатдан сўнг")] + [InlineData(10, "10 соатдан сўнг")] + public void HoursFromNow(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); + } + + [Theory] + [InlineData(1, "кеча")] + [InlineData(10, "10 кун аввал")] + public void DaysAgo(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); + } + + [Theory] + [InlineData(1, "эртага")] + [InlineData(10, "10 кундан сўнг")] + public void DaysFromNow(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); + } + + [Theory] + [InlineData(1, "бир ой аввал")] + [InlineData(10, "10 ой аввал")] + public void MonthsAgo(int months, string expected) + { + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); + } + + [Theory] + [InlineData(1, "бир ойдан сўнг")] + [InlineData(10, "10 ойдан сўнг")] + public void MonthsFromNow(int months, string expected) + { + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); + } + + [Theory] + [InlineData(1, "бир йил аввал")] + [InlineData(2, "2 йил аввал")] + public void YearsAgo(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); + } + + [Theory] + [InlineData(1, "бир йилдан сўнг")] + [InlineData(2, "2 йилдан сўнг")] + public void YearsFromNow(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); + } + + [Fact] + public void Now() + { + DateHumanize.Verify("ҳозир", 0, TimeUnit.Year, Tense.Future); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/NumberToWordsTests.cs b/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/NumberToWordsTests.cs new file mode 100644 index 000000000..4cc4c5028 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/NumberToWordsTests.cs @@ -0,0 +1,109 @@ +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.uzCyrl +{ + public class NumberToWordsTests : AmbientCulture + { + public NumberToWordsTests() : base("uz-Cyrl-UZ") { } + + [Theory] + [InlineData(0, "нол")] + [InlineData(1, "бир")] + [InlineData(10, "ўн")] + [InlineData(11, "ўн бир")] + [InlineData(12, "ўн икки")] + [InlineData(13, "ўн уч")] + [InlineData(14, "ўн тўрт")] + [InlineData(15, "ўн беш")] + [InlineData(16, "ўн олти")] + [InlineData(17, "ўн етти")] + [InlineData(18, "ўн саккиз")] + [InlineData(19, "ўн тўққиз")] + [InlineData(20, "йигирма")] + [InlineData(30, "ўттиз")] + [InlineData(40, "қирқ")] + [InlineData(50, "эллик")] + [InlineData(60, "олтмиш")] + [InlineData(70, "етмиш")] + [InlineData(80, "саксон")] + [InlineData(90, "тўқсон")] + [InlineData(100, "юз")] + [InlineData(200, "икки юз")] + [InlineData(300, "уч юз")] + [InlineData(400, "тўрт юз")] + [InlineData(500, "беш юз")] + [InlineData(600, "олти юз")] + [InlineData(700, "етти юз")] + [InlineData(800, "саккиз юз")] + [InlineData(900, "тўққиз юз")] + [InlineData(1000, "бир минг")] + [InlineData(2000, "икки минг")] + [InlineData(3000, "уч минг")] + [InlineData(10000, "ўн минг")] + [InlineData(100000, "юз минг")] + [InlineData(100100, "юз минг бир юз")] + [InlineData(200100, "икки юз минг бир юз")] + [InlineData(1000000, "бир миллион")] + [InlineData(1001000, "бир миллион бир минг")] + [InlineData(1000100, "бир миллион бир юз")] + [InlineData(2000000, "икки миллион")] + [InlineData(10000000, "ўн миллион")] + [InlineData(100000000, "юз миллион")] + [InlineData(100001000, "юз миллион бир минг")] + [InlineData(1000000000, "бир миллиард")] + [InlineData(2000000000, "икки миллиард")] + [InlineData(122, "бир юз йигирма икки")] + [InlineData(3501, "уч минг беш юз бир")] + [InlineData(111, "бир юз ўн бир")] + [InlineData(1112, "бир минг бир юз ўн икки")] + [InlineData(11213, "ўн бир минг икки юз ўн уч")] + [InlineData(121314, "бир юз йигирма бир минг уч юз ўн тўрт")] + [InlineData(2132415, "икки миллион бир юз ўттиз икки минг тўрт юз ўн беш")] + [InlineData(12345516, "ўн икки миллион уч юз қирқ беш минг беш юз ўн олти")] + [InlineData(751633617, "етти юз эллик бир миллион олти юз ўттиз уч минг олти юз ўн етти")] + [InlineData(1111111118, "бир миллиард бир юз ўн бир миллион бир юз ўн бир минг бир юз ўн саккиз")] + [InlineData(-751633617, "минус етти юз эллик бир миллион олти юз ўттиз уч минг олти юз ўн етти")] + public void ToWords(int number, string expected) + { + Assert.Equal(expected, number.ToWords()); + } + + [Theory] + [InlineData(0, "нолинчи")] + [InlineData(1, "биринчи")] + [InlineData(10, "ўнинчи")] + [InlineData(11, "ўн биринчи")] + [InlineData(12, "ўн иккинчи")] + [InlineData(13, "ўн учинчи")] + [InlineData(14, "ўн тўртинчи")] + [InlineData(15, "ўн бешинчи")] + [InlineData(16, "ўн олтинчи")] + [InlineData(17, "ўн еттинчи")] + [InlineData(18, "ўн саккизинчи")] + [InlineData(19, "ўн тўққизинчи")] + [InlineData(20, "йигирманчи")] + [InlineData(30, "ўттизинчи")] + [InlineData(40, "қирқинчи")] + [InlineData(50, "элликинчи")] + [InlineData(60, "олтмишинчи")] + [InlineData(70, "етмишинчи")] + [InlineData(80, "саксонинчи")] + [InlineData(90, "тўқсонинчи")] + [InlineData(100, "юзинчи")] + [InlineData(200, "икки юзинчи")] + [InlineData(1000, "бир мингинчи")] + [InlineData(2000000, "икки миллионинчи")] + [InlineData(1000000000, "бир миллиардинчи")] + [InlineData(122, "бир юз йигирма иккинчи")] + [InlineData(3501, "уч минг беш юз биринчи")] + [InlineData(111, "бир юз ўн биринчи")] + [InlineData(751633617, "етти юз эллик бир миллион олти юз ўттиз уч минг олти юз ўн еттинчи")] + [InlineData(1111111118, "бир миллиард бир юз ўн бир миллион бир юз ўн бир минг бир юз ўн саккизинчи")] + [InlineData(-751633617, "минус етти юз эллик бир миллион олти юз ўттиз уч минг олти юз ўн еттинчи")] + public void ToOrdinalWords(int number, string words) + { + Assert.Equal(words, number.ToOrdinalWords()); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs new file mode 100644 index 000000000..89c4b81b9 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs @@ -0,0 +1,73 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.uzCyrl +{ + public class TimeSpanHumanizeTests : AmbientCulture + { + public TimeSpanHumanizeTests() : base("uz-Cyrl-UZ") { } + + [Theory] + [InlineData(14, "2 ҳафта")] + [InlineData(7, "1 ҳафта")] + public void Weeks(int days, string expected) + { + var actual = TimeSpan.FromDays(days).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(6, "6 кун")] + [InlineData(2, "2 кун")] + public void Days(int days, string expected) + { + var actual = TimeSpan.FromDays(days).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 соат")] + [InlineData(1, "1 соат")] + public void Hours(int hours, string expected) + { + var actual = TimeSpan.FromHours(hours).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 минут")] + [InlineData(1, "1 минут")] + public void Minutes(int minutes, string expected) + { + var actual = TimeSpan.FromMinutes(minutes).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 секунд")] + [InlineData(1, "1 секунд")] + public void Seconds(int seconds, string expected) + { + var actual = TimeSpan.FromSeconds(seconds).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 миллисекунд")] + [InlineData(1, "1 миллисекунд")] + public void Milliseconds(int ms, string expected) + { + var actual = TimeSpan.FromMilliseconds(ms).Humanize(); + Assert.Equal(expected, actual); + } + + [Fact] + public void NoTime() + { + var noTime = TimeSpan.Zero; + var actual = noTime.Humanize(); + Assert.Equal("вақт йўқ", actual); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/uz-Latn-UZ/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/uz-Latn-UZ/DateHumanizeTests.cs new file mode 100644 index 000000000..c8da37e8f --- /dev/null +++ b/src/Humanizer.Tests/Localisation/uz-Latn-UZ/DateHumanizeTests.cs @@ -0,0 +1,118 @@ +using Humanizer.Localisation; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.uzLatn +{ + public class DateHumanizeTests : AmbientCulture + { + public DateHumanizeTests() + : base("uz-Latn-UZ") + { + } + + [Theory] + [InlineData(1, "bir soniya avval")] + [InlineData(10, "10 sekund avval")] + public void SecondsAgo(int seconds, string expected) + { + var cul = System.Threading.Thread.CurrentThread.CurrentCulture; + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); + } + + [Theory] + [InlineData(1, "bir soniyadan so`ng")] + [InlineData(10, "10 sekunddan so`ng")] + public void SecondsFromNow(int seconds, string expected) + { + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); + } + + [Theory] + [InlineData(1, "bir daqiqa avval")] + [InlineData(10, "10 minut avval")] + [InlineData(60, "bir soat avval")] + public void MinutesAgo(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); + } + + [Theory] + [InlineData(1, "bir daqiqadan so`ng")] + [InlineData(10, "10 minutdan so`ng")] + public void MinutesFromNow(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); + } + + [Theory] + [InlineData(1, "bir soat avval")] + [InlineData(10, "10 soat avval")] + public void HoursAgo(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); + } + + [Theory] + [InlineData(1, "bir soatdan so`ng")] + [InlineData(10, "10 soatdan so`ng")] + public void HoursFromNow(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); + } + + [Theory] + [InlineData(1, "kecha")] + [InlineData(10, "10 kun avval")] + public void DaysAgo(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); + } + + [Theory] + [InlineData(1, "ertaga")] + [InlineData(10, "10 kundan so`ng")] + public void DaysFromNow(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); + } + + [Theory] + [InlineData(1, "bir oy avval")] + [InlineData(10, "10 oy avval")] + public void MonthsAgo(int months, string expected) + { + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); + } + + [Theory] + [InlineData(1, "bir oydan so`ng")] + [InlineData(10, "10 oydan so`ng")] + public void MonthsFromNow(int months, string expected) + { + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); + } + + [Theory] + [InlineData(1, "bir yil avval")] + [InlineData(2, "2 yil avval")] + public void YearsAgo(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); + } + + [Theory] + [InlineData(1, "bir yildan so`ng")] + [InlineData(2, "2 yildan so`ng")] + public void YearsFromNow(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); + } + + [Fact] + public void Now() + { + DateHumanize.Verify("hozir", 0, TimeUnit.Year, Tense.Future); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/uz-Latn-UZ/NumberToWordsTests.cs b/src/Humanizer.Tests/Localisation/uz-Latn-UZ/NumberToWordsTests.cs new file mode 100644 index 000000000..e84b33c45 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/uz-Latn-UZ/NumberToWordsTests.cs @@ -0,0 +1,109 @@ +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.uzLatn +{ + public class NumberToWordsTests : AmbientCulture + { + public NumberToWordsTests() : base("uz-Latn-UZ") { } + + [Theory] + [InlineData(0, "nol")] + [InlineData(1, "bir")] + [InlineData(10, "o`n")] + [InlineData(11, "o`n bir")] + [InlineData(12, "o`n ikki")] + [InlineData(13, "o`n uch")] + [InlineData(14, "o`n to`rt")] + [InlineData(15, "o`n besh")] + [InlineData(16, "o`n olti")] + [InlineData(17, "o`n yetti")] + [InlineData(18, "o`n sakkiz")] + [InlineData(19, "o`n to`qqiz")] + [InlineData(20, "yigirma")] + [InlineData(30, "o`ttiz")] + [InlineData(40, "qirq")] + [InlineData(50, "ellik")] + [InlineData(60, "oltmish")] + [InlineData(70, "yetmish")] + [InlineData(80, "sakson")] + [InlineData(90, "to`qson")] + [InlineData(100, "yuz")] + [InlineData(200, "ikki yuz")] + [InlineData(300, "uch yuz")] + [InlineData(400, "to`rt yuz")] + [InlineData(500, "besh yuz")] + [InlineData(600, "olti yuz")] + [InlineData(700, "yetti yuz")] + [InlineData(800, "sakkiz yuz")] + [InlineData(900, "to`qqiz yuz")] + [InlineData(1000, "bir ming")] + [InlineData(2000, "ikki ming")] + [InlineData(3000, "uch ming")] + [InlineData(10000, "o`n ming")] + [InlineData(100000, "yuz ming")] + [InlineData(100100, "yuz ming bir yuz")] + [InlineData(200100, "ikki yuz ming bir yuz")] + [InlineData(1000000, "bir million")] + [InlineData(1001000, "bir million bir ming")] + [InlineData(1000100, "bir million bir yuz")] + [InlineData(2000000, "ikki million")] + [InlineData(10000000, "o`n million")] + [InlineData(100000000, "yuz million")] + [InlineData(100001000, "yuz million bir ming")] + [InlineData(1000000000, "bir milliard")] + [InlineData(2000000000, "ikki milliard")] + [InlineData(122, "bir yuz yigirma ikki")] + [InlineData(3501, "uch ming besh yuz bir")] + [InlineData(111, "bir yuz o`n bir")] + [InlineData(1112, "bir ming bir yuz o`n ikki")] + [InlineData(11213, "o`n bir ming ikki yuz o`n uch")] + [InlineData(121314, "bir yuz yigirma bir ming uch yuz o`n to`rt")] + [InlineData(2132415, "ikki million bir yuz o`ttiz ikki ming to`rt yuz o`n besh")] + [InlineData(12345516, "o`n ikki million uch yuz qirq besh ming besh yuz o`n olti")] + [InlineData(751633617, "yetti yuz ellik bir million olti yuz o`ttiz uch ming olti yuz o`n yetti")] + [InlineData(1111111118, "bir milliard bir yuz o`n bir million bir yuz o`n bir ming bir yuz o`n sakkiz")] + [InlineData(-751633617, "minus yetti yuz ellik bir million olti yuz o`ttiz uch ming olti yuz o`n yetti")] + public void ToWords(int number, string expected) + { + Assert.Equal(expected, number.ToWords()); + } + + [Theory] + [InlineData(0, "nolinchi")] + [InlineData(1, "birinchi")] + [InlineData(10, "o`ninchi")] + [InlineData(11, "o`n birinchi")] + [InlineData(12, "o`n ikkinchi")] + [InlineData(13, "o`n uchinchi")] + [InlineData(14, "o`n to`rtinchi")] + [InlineData(15, "o`n beshinchi")] + [InlineData(16, "o`n oltinchi")] + [InlineData(17, "o`n yettinchi")] + [InlineData(18, "o`n sakkizinchi")] + [InlineData(19, "o`n to`qqizinchi")] + [InlineData(20, "yigirmanchi")] + [InlineData(30, "o`ttizinchi")] + [InlineData(40, "qirqinchi")] + [InlineData(50, "ellikinchi")] + [InlineData(60, "oltmishinchi")] + [InlineData(70, "yetmishinchi")] + [InlineData(80, "saksoninchi")] + [InlineData(90, "to`qsoninchi")] + [InlineData(100, "yuzinchi")] + [InlineData(200, "ikki yuzinchi")] + [InlineData(1000, "bir minginchi")] + [InlineData(2000000, "ikki millioninchi")] + [InlineData(1000000000, "bir milliardinchi")] + [InlineData(122, "bir yuz yigirma ikkinchi")] + [InlineData(3501, "uch ming besh yuz birinchi")] + [InlineData(111, "bir yuz o`n birinchi")] + [InlineData(751633617, "yetti yuz ellik bir million olti yuz o`ttiz uch ming olti yuz o`n yettinchi")] + [InlineData(1111111118, "bir milliard bir yuz o`n bir million bir yuz o`n bir ming bir yuz o`n sakkizinchi")] + [InlineData(-751633617, "minus yetti yuz ellik bir million olti yuz o`ttiz uch ming olti yuz o`n yettinchi")] + public void ToOrdinalWords(int number, string words) + { + Assert.Equal(words, number.ToOrdinalWords()); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs new file mode 100644 index 000000000..497cf40be --- /dev/null +++ b/src/Humanizer.Tests/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs @@ -0,0 +1,73 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.uzLatn +{ + public class TimeSpanHumanizeTests : AmbientCulture + { + public TimeSpanHumanizeTests() : base("uz-Latn-UZ") { } + + [Theory] + [InlineData(14, "2 hafta")] + [InlineData(7, "1 hafta")] + public void Weeks(int days, string expected) + { + var actual = TimeSpan.FromDays(days).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(6, "6 kun")] + [InlineData(2, "2 kun")] + public void Days(int days, string expected) + { + var actual = TimeSpan.FromDays(days).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 soat")] + [InlineData(1, "1 soat")] + public void Hours(int hours, string expected) + { + var actual = TimeSpan.FromHours(hours).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 minut")] + [InlineData(1, "1 minut")] + public void Minutes(int minutes, string expected) + { + var actual = TimeSpan.FromMinutes(minutes).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 sekund")] + [InlineData(1, "1 sekund")] + public void Seconds(int seconds, string expected) + { + var actual = TimeSpan.FromSeconds(seconds).Humanize(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, "2 millisekund")] + [InlineData(1, "1 millisekund")] + public void Milliseconds(int ms, string expected) + { + var actual = TimeSpan.FromMilliseconds(ms).Humanize(); + Assert.Equal(expected, actual); + } + + [Fact] + public void NoTime() + { + var noTime = TimeSpan.Zero; + var actual = noTime.Humanize(); + Assert.Equal("vaqt yo`q", actual); + } + } +} diff --git a/src/Humanizer/Configuration/FormatterRegistry.cs b/src/Humanizer/Configuration/FormatterRegistry.cs index 2bd4bd8d3..430b0cca4 100644 --- a/src/Humanizer/Configuration/FormatterRegistry.cs +++ b/src/Humanizer/Configuration/FormatterRegistry.cs @@ -39,6 +39,8 @@ public FormatterRegistry() : base(new DefaultFormatter("en-US")) RegisterDefaultFormatter("nl"); RegisterDefaultFormatter("bn-BD"); RegisterDefaultFormatter("it"); + RegisterDefaultFormatter("uz-Latn-UZ"); + RegisterDefaultFormatter("uz-Cyrl-UZ"); } private void RegisterDefaultFormatter(string localeCode) diff --git a/src/Humanizer/Configuration/NumberToWordsConverterRegistry.cs b/src/Humanizer/Configuration/NumberToWordsConverterRegistry.cs index 52efb010c..16e0e9a7b 100644 --- a/src/Humanizer/Configuration/NumberToWordsConverterRegistry.cs +++ b/src/Humanizer/Configuration/NumberToWordsConverterRegistry.cs @@ -21,6 +21,8 @@ internal class NumberToWordsConverterRegistry : LocaliserRegistry + + @@ -181,6 +183,13 @@ + + Resources.uz-Cyrl-UZ.Designer.cs + Designer + + + Resources.uz-Latn-UZ1.Designer.cs + diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs new file mode 100644 index 000000000..b1fb7ac23 --- /dev/null +++ b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Humanizer.Localisation.NumberToWords +{ + internal class UzbekCyrlNumberToWordConverter : GenderlessNumberToWordsConverter + { + private static readonly string[] UnitsMap = { "нол", "бир", "икки", "уч", "тўрт", "беш", "олти", "етти", "саккиз", "тўққиз" }; + private static readonly string[] TensMap = { "нол", "ўн", "йигирма", "ўттиз", "қирқ", "эллик", "олтмиш", "етмиш", "саксон", "тўқсон" }; + + private static readonly string[] OrdinalSuffixes = new string[] { "инчи", "нчи" }; + + public override string Convert(int number) + { + if (number < 0) + return string.Format("минус {0}", Convert(-number, true)); + return Convert(number, true); + } + + private string Convert(int number, bool checkForHoundredRule) + { + if (number == 0) + return UnitsMap[0]; + + if (checkForHoundredRule && number == 100) + return "юз"; + + var sb = new StringBuilder(); + + if ((number / 1000000000) > 0) + { + sb.AppendFormat("{0} миллиард ", Convert(number / 1000000000, false)); + number %= 1000000000; + } + + if ((number / 1000000) > 0) + { + sb.AppendFormat("{0} миллион ", Convert(number / 1000000, true)); + number %= 1000000; + } + + var thousand = (number / 1000); + if (thousand > 0) + { + sb.AppendFormat("{0} минг ", Convert(thousand, true)); + number %= 1000; + } + + var hundred = (number / 100); + if (hundred > 0) + { + sb.AppendFormat("{0} юз ", Convert(hundred, false)); + number %= 100; + } + + if ((number / 10) > 0) + { + sb.AppendFormat("{0} ", TensMap[number / 10]); + number %= 10; + } + + if (number > 0) + { + sb.AppendFormat("{0} ", UnitsMap[number]); + } + + return sb.ToString().Trim(); + } + + public override string ConvertToOrdinal(int number) + { + var word = Convert(number); + var i = 0; + if (string.IsNullOrEmpty(word)) + return string.Empty; + + var lastChar = word[word.Length - 1]; + if (lastChar == 'и' || lastChar == 'а') + i = 1; + + return String.Format("{0}{1}", word, OrdinalSuffixes[i]); + } + } +} diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs new file mode 100644 index 000000000..47b349b53 --- /dev/null +++ b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Humanizer.Localisation.NumberToWords +{ + internal class UzbekLatnNumberToWordConverter : GenderlessNumberToWordsConverter + { + private static readonly string[] UnitsMap = { "nol", "bir", "ikki", "uch", "to`rt", "besh", "olti", "yetti", "sakkiz", "to`qqiz" }; + private static readonly string[] TensMap = { "nol", "o`n", "yigirma", "o`ttiz", "qirq", "ellik", "oltmish", "yetmish", "sakson", "to`qson" }; + + private static readonly string[] OrdinalSuffixes = new string[] { "inchi", "nchi" }; + + public override string Convert(int number) + { + if (number < 0) + return string.Format("minus {0}", Convert(-number, true)); + return Convert(number, true); + } + + private string Convert(int number, bool checkForHoundredRule) + { + if (number == 0) + return UnitsMap[0]; + + if (checkForHoundredRule && number == 100) + return "yuz"; + + var sb = new StringBuilder(); + + if ((number / 1000000000) > 0) + { + sb.AppendFormat("{0} milliard ", Convert(number / 1000000000, false)); + number %= 1000000000; + } + + if ((number / 1000000) > 0) + { + sb.AppendFormat("{0} million ", Convert(number / 1000000, true)); + number %= 1000000; + } + + var thousand = (number / 1000); + if (thousand > 0) + { + sb.AppendFormat("{0} ming ", Convert(thousand, true)); + number %= 1000; + } + + var hundred = (number / 100); + if (hundred > 0) + { + sb.AppendFormat("{0} yuz ", Convert(hundred, false)); + number %= 100; + } + + if ((number / 10) > 0) + { + sb.AppendFormat("{0} ", TensMap[number / 10]); + number %= 10; + } + + if (number > 0) + { + sb.AppendFormat("{0} ", UnitsMap[number]); + } + + return sb.ToString().Trim(); + } + + public override string ConvertToOrdinal(int number) + { + var word = Convert(number); + var i = 0; + if (string.IsNullOrEmpty(word)) + return string.Empty; + + var lastChar = word[word.Length - 1]; + if (lastChar == 'i' || lastChar == 'a') + i = 1; + + return String.Format("{0}{1}", word, OrdinalSuffixes[i]); + } + } +} diff --git a/src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx b/src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx new file mode 100644 index 000000000..f6f910d3d --- /dev/null +++ b/src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + {0} кун аввал + + + {0} кундан сўнг + + + {0} соат аввал + + + {0} соатдан сўнг + + + {0} минут аввал + + + {0} минутдан сўнг + + + {0} ой аввал + + + {0} ойдан сўнг + + + {0} секунд аввал + + + {0} секунддан сўнг + + + {0} йил аввал + + + {0} йилдан сўнг + + + ҳозир + + + кеча + + + эртага + + + бир соат аввал + + + бир соатдан сўнг + + + бир дақиқа аввал + + + бир дақиқадан сўнг + + + бир ой аввал + + + бир ойдан сўнг + + + бир сония аввал + + + бир сониядан сўнг + + + бир йил аввал + + + бир йилдан сўнг + + + {0} кун + + + {0} соат + + + {0} миллисекунд + + + {0} минут + + + {0} секунд + + + {0} ҳафта + + + 1 кун + + + 1 соат + + + 1 миллисекунд + + + 1 минут + + + 1 секунд + + + 1 ҳафта + + + вақт йўқ + + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.uz-Latn-UZ.resx b/src/Humanizer/Properties/Resources.uz-Latn-UZ.resx new file mode 100644 index 000000000..4f9a367bc --- /dev/null +++ b/src/Humanizer/Properties/Resources.uz-Latn-UZ.resx @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + {0} kun avval + + + {0} kundan so`ng + + + {0} soat avval + + + {0} soatdan so`ng + + + {0} minut avval + + + {0} minutdan so`ng + + + {0} oy avval + + + {0} oydan so`ng + + + {0} sekund avval + + + {0} sekunddan so`ng + + + {0} yil avval + + + {0} yildan so`ng + + + hozir + + + kecha + + + ertaga + + + bir soat avval + + + bir soatdan so`ng + + + bir daqiqa avval + + + bir daqiqadan so`ng + + + bir oy avval + + + bir oydan so`ng + + + bir soniya avval + + + bir soniyadan so`ng + + + bir yil avval + + + bir yildan so`ng + + + {0} kun + + + {0} soat + + + {0} millisekund + + + {0} minut + + + {0} sekund + + + {0} hafta + + + 1 kun + + + 1 soat + + + 1 millisekund + + + 1 minut + + + 1 sekund + + + 1 hafta + + + vaqt yo`q + + \ No newline at end of file From d7d1bec4419d6c9244c0807a46bb5eed9ffeab32 Mon Sep 17 00:00:00 2001 From: mxurshid Date: Thu, 23 Oct 2014 14:04:11 +0500 Subject: [PATCH 2/2] Removed autogenerated lines in ".csproj" files --- src/Humanizer.Tests/Humanizer.Tests.csproj | 4 +--- src/Humanizer/Humanizer.csproj | 9 ++------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 7b83281a8..e557a818e 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -139,9 +139,7 @@ - - Code - + diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 44a931381..902036456 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -183,13 +183,8 @@ - - Resources.uz-Cyrl-UZ.Designer.cs - Designer - - - Resources.uz-Latn-UZ1.Designer.cs - + +