From 45dfe03f4a53640a868cf847234e967f284b5341 Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Wed, 9 Apr 2014 23:46:57 +0300 Subject: [PATCH 1/9] Initial Hebrew support, based on the Arabic resource file. --- src/Humanizer.Tests/Humanizer.Tests.csproj | 1 + .../Localisation/he/DateHumanizeTests.cs | 71 ++++ src/Humanizer/Configuration/Configurator.cs | 1 + src/Humanizer/Humanizer.csproj | 6 + src/Humanizer/Localisation/HebrewFormatter.cs | 26 ++ src/Humanizer/Properties/Resources.he.resx | 316 ++++++++++++++++++ 6 files changed, 421 insertions(+) create mode 100644 src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs create mode 100644 src/Humanizer/Localisation/HebrewFormatter.cs create mode 100644 src/Humanizer/Properties/Resources.he.resx diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index d35f84148..fce536bcd 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -92,6 +92,7 @@ + diff --git a/src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs new file mode 100644 index 000000000..47dd80972 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs @@ -0,0 +1,71 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.he +{ + public class DateHumanizeTests : AmbientCulture + { + public DateHumanizeTests() : base("he") { } + + [Theory] + [InlineData(-1, "אתמול")] + [InlineData(-2, "לפני יומיים")] + [InlineData(-3, "לפני 3 ימים")] + [InlineData(-11, "לפני 11 יום")] + public void DaysAgo(int days, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + } + + [Theory] + [InlineData(-2, "לפני שעתיים")] + [InlineData(-1, "לפני שעה")] + [InlineData(-3, "לפני 3 שעות")] + [InlineData(-11, "לפני 11 שעות")] + public void HoursAgo(int hours, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + } + + [Theory] + [InlineData(-2, "לפני 2 דקות")] + [InlineData(-1, "לפני דקה")] + [InlineData(-3, "לפני 3 דקות")] + [InlineData(-11, "לפני 11 דקות")] + public void MinutesAgo(int minutes, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + } + + [Theory] + [InlineData(-2, "לפני חודשיים")] + [InlineData(-1, "לפני חודש")] + [InlineData(-3, "לפני 3 חודשים")] + [InlineData(-11, "לפני 11 חודשים")] + public void MonthsAgo(int months, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + } + + [Theory] + [InlineData(-2, "לפני 2 שניות")] + [InlineData(-1, "לפני שניה")] + [InlineData(-3, "לפני 3 שניות")] + [InlineData(-11, "לפני 11 שניות")] + public void SecondsAgo(int seconds, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + } + + [Theory] + [InlineData(-2, "לפני שנתיים")] + [InlineData(-1, "לפני שנה")] + [InlineData(-3, "לפני 3 שנים")] + [InlineData(-11, "לפני 11 שנה")] + public void YearsAgo(int years, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + } + } +} diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index fbf52af16..4d7bfc00e 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -17,6 +17,7 @@ public static class Configurator { "ro", () => new RomanianFormatter() }, { "ru", () => new RussianFormatter() }, { "ar", () => new ArabicFormatter() }, + { "he", () => new HebrewFormatter() }, { "sk", () => new CzechSlovakPolishFormatter() }, { "cs", () => new CzechSlovakPolishFormatter() }, { "pl", () => new CzechSlovakPolishFormatter() } diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 22e30a94d..e72ab436a 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -87,6 +87,8 @@ + + @@ -162,6 +164,10 @@ + + Resources.he1.Designer.cs + Designer + diff --git a/src/Humanizer/Localisation/HebrewFormatter.cs b/src/Humanizer/Localisation/HebrewFormatter.cs new file mode 100644 index 000000000..e84a693d5 --- /dev/null +++ b/src/Humanizer/Localisation/HebrewFormatter.cs @@ -0,0 +1,26 @@ +namespace Humanizer.Localisation +{ + internal class HebrewFormatter : DefaultFormatter + { + private const string DualPostfix = "_Dual"; + private const string PluralPostfix = "_Plural"; + + protected override string GetResourceKey(string resourceKey, int number) + { + //In Hebrew pluralization 2 entities gets a different word. + if (number == 2) + { + return resourceKey + DualPostfix; + } + + //In Hebrew pluralization entities where the count is between 3 and 10 gets a different word. + //See http://lib.cet.ac.il/pages/item.asp?item=21585 for explanation + if (number >= 3 && number <= 10) + { + return resourceKey + PluralPostfix; + } + + return resourceKey; + } + } +} \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.he.resx b/src/Humanizer/Properties/Resources.he.resx new file mode 100644 index 000000000..440ab1f14 --- /dev/null +++ b/src/Humanizer/Properties/Resources.he.resx @@ -0,0 +1,316 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + לפני שניה + one second ago + + + לפני {0} שניות + {0} seconds ago + + + לפני דקה + a minute ago + + + לפני {0} דקות + {0} minutes ago + + + לפני שעה + an hour ago + + + לפני {0} שעות + {0} hours ago + + + אתמול + yesterday + + + לפני {0} יום + {0} days ago + + + לפני חודש + one month ago + + + לפני {0} חודשים + {0} months ago + + + לפני שנה + one year ago + + + לפני {0} שנה + {0} years ago + + + يوم واحد + single day + + + ساعة واحدة + single hour + + + جزء من الثانية + single millisecond + + + دقيقة واحدة + single minute + + + ثانية واحدة + single second + + + שבוע + single week + + + حالاً + no time + + + לפני יומיים + two days ago + + + לפני שעתיים + two hours ago + + + לפני {0} דקות + two minutes ago + + + לפני חודשיים + two months ago + + + לפני {0} שניות + two seconds ago + + + לפני שנתיים + two years ago + + + שבועיים + two weeks + + + يومين + two days + + + ساعتين + two hours + + + جزئين من الثانية + two milliseconds + + + دقيقتين + two minutes + + + ثانيتين + two seconds + + + {0} يوم + {0} days + + + {0} أيام + {0} days + + + {0} ساعة + {0} hours + + + {0} ساعات + {0} hours + + + {0} جزء من الثانية + {0} milliseconds + + + {0} أجزاء من الثانية + {0} milliseconds + + + {0} دقيقة + {0} minutes + + + {0} دقائق + {0} minutes + + + {0} ثانية + {0} seconds + + + {0} ثوان + {0} seconds + + + {0} שבועות + {0} weeks + + + {0} שבועות + {0} weeks + + + לפני {0} ימים + {0} days ago + + + לפני {0} שעות + {0} hours ago + + + לפני {0} דקות + {0} minutes ago + + + לפני {0} חודשים + {0} months ago + + + לפני {0} שניות + {0} seconds ago + + + לפני {0} שנים + {0} years ago + + \ No newline at end of file From df9cd22f915bf977bc45ca4552f8cb5144e5a40a Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Thu, 10 Apr 2014 00:28:24 +0300 Subject: [PATCH 2/9] Adding TimeSpan Hebrew conversions --- src/Humanizer.Tests/Humanizer.Tests.csproj | 1 + .../Localisation/ar/TimeSpanHumanizeTests.cs | 54 ++++++------- .../Localisation/he/TimeSpanHumanizeTests.cs | 78 +++++++++++++++++++ src/Humanizer/Properties/Resources.he.resx | 42 +++++----- 4 files changed, 128 insertions(+), 47 deletions(-) create mode 100644 src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index fce536bcd..54bcadb5b 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -93,6 +93,7 @@ + diff --git a/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs index 1b54942fa..78a4fb04d 100644 --- a/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs @@ -2,17 +2,19 @@ using Xunit; using Xunit.Extensions; -namespace Humanizer.Tests.Localisation.ar +namespace Humanizer.Tests.Localisation.he { public class TimeSpanHumanizeTests : AmbientCulture { - public TimeSpanHumanizeTests() : base("ar") { } + public TimeSpanHumanizeTests() : base("he") + { + } [Theory] - [InlineData(7, "أسبوع واحد")] - [InlineData(14, "أسبوعين")] - [InlineData(21, "3 أسابيع")] - [InlineData(77, "11 أسبوع")] + [InlineData(7, "שבוע")] + [InlineData(14, "שבועיים")] + [InlineData(21, "3 שבועות")] + [InlineData(77, "11 שבועות")] public void Weeks(int days, string expected) { Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); @@ -20,29 +22,29 @@ public void Weeks(int days, string expected) [Theory] - [InlineData(1, "يوم واحد")] - [InlineData(2, "يومين")] - [InlineData(3, "3 أيام")] + [InlineData(1, "יום")] + [InlineData(2, "יומיים")] + [InlineData(3, "3 ימים")] public void Days(int days, string expected) { Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); } [Theory] - [InlineData(1, "ساعة واحدة")] - [InlineData(2, "ساعتين")] - [InlineData(3, "3 ساعات")] - [InlineData(11, "11 ساعة")] + [InlineData(1, "שעה")] + [InlineData(2, "שעתיים")] + [InlineData(3, "3 שעות")] + [InlineData(11, "11 שעות")] public void Hours(int hours, string expected) { Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize()); } [Theory] - [InlineData(1, "دقيقة واحدة")] - [InlineData(2, "دقيقتين")] - [InlineData(3, "3 دقائق")] - [InlineData(11, "11 دقيقة")] + [InlineData(1, "דקה")] + [InlineData(2, "שתי דקות")] + [InlineData(3, "3 דקות")] + [InlineData(11, "11 דקות")] public void Minutes(int minutes, string expected) { Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize()); @@ -50,20 +52,20 @@ public void Minutes(int minutes, string expected) [Theory] - [InlineData(1, "ثانية واحدة")] - [InlineData(2, "ثانيتين")] - [InlineData(3, "3 ثوان")] - [InlineData(11, "11 ثانية")] + [InlineData(1, "שניה")] + [InlineData(2, "שתי שניות")] + [InlineData(3, "3 שניות")] + [InlineData(11, "11 שניות")] public void Seconds(int seconds, string expected) { Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize()); } [Theory] - [InlineData(1, "جزء من الثانية")] - [InlineData(2, "جزئين من الثانية")] - [InlineData(3, "3 أجزاء من الثانية")] - [InlineData(11, "11 جزء من الثانية")] + [InlineData(1, "מילי שניה")] + [InlineData(2, "שתי מילי שניות")] + [InlineData(3, "3 מילי שניות")] + [InlineData(11, "11 מילי שניות")] public void Milliseconds(int milliseconds, string expected) { Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize()); @@ -72,7 +74,7 @@ public void Milliseconds(int milliseconds, string expected) [Fact] public void NoTime() { - Assert.Equal("حالاً", TimeSpan.Zero.Humanize()); + Assert.Equal("אפס", TimeSpan.Zero.Humanize()); } } } \ No newline at end of file diff --git a/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs new file mode 100644 index 000000000..1b54942fa --- /dev/null +++ b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs @@ -0,0 +1,78 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.ar +{ + public class TimeSpanHumanizeTests : AmbientCulture + { + public TimeSpanHumanizeTests() : base("ar") { } + + [Theory] + [InlineData(7, "أسبوع واحد")] + [InlineData(14, "أسبوعين")] + [InlineData(21, "3 أسابيع")] + [InlineData(77, "11 أسبوع")] + public void Weeks(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); + } + + + [Theory] + [InlineData(1, "يوم واحد")] + [InlineData(2, "يومين")] + [InlineData(3, "3 أيام")] + public void Days(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); + } + + [Theory] + [InlineData(1, "ساعة واحدة")] + [InlineData(2, "ساعتين")] + [InlineData(3, "3 ساعات")] + [InlineData(11, "11 ساعة")] + public void Hours(int hours, string expected) + { + Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize()); + } + + [Theory] + [InlineData(1, "دقيقة واحدة")] + [InlineData(2, "دقيقتين")] + [InlineData(3, "3 دقائق")] + [InlineData(11, "11 دقيقة")] + public void Minutes(int minutes, string expected) + { + Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize()); + } + + + [Theory] + [InlineData(1, "ثانية واحدة")] + [InlineData(2, "ثانيتين")] + [InlineData(3, "3 ثوان")] + [InlineData(11, "11 ثانية")] + public void Seconds(int seconds, string expected) + { + Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize()); + } + + [Theory] + [InlineData(1, "جزء من الثانية")] + [InlineData(2, "جزئين من الثانية")] + [InlineData(3, "3 أجزاء من الثانية")] + [InlineData(11, "11 جزء من الثانية")] + public void Milliseconds(int milliseconds, string expected) + { + Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize()); + } + + [Fact] + public void NoTime() + { + Assert.Equal("حالاً", TimeSpan.Zero.Humanize()); + } + } +} \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.he.resx b/src/Humanizer/Properties/Resources.he.resx index 440ab1f14..d030ce89c 100644 --- a/src/Humanizer/Properties/Resources.he.resx +++ b/src/Humanizer/Properties/Resources.he.resx @@ -166,23 +166,23 @@ {0} years ago - يوم واحد + יום single day - ساعة واحدة + שעה single hour - جزء من الثانية + מילי שניה single millisecond - دقيقة واحدة + דקה single minute - ثانية واحدة + שניה single second @@ -190,7 +190,7 @@ single week - حالاً + אפס no time @@ -222,63 +222,63 @@ two weeks - يومين + יומיים two days - ساعتين + שעתיים two hours - جزئين من الثانية + שתי מילי שניות two milliseconds - دقيقتين + שתי דקות two minutes - ثانيتين + שתי שניות two seconds - {0} يوم + {0} ימים {0} days - {0} أيام + {0} ימים {0} days - {0} ساعة + {0} שעות {0} hours - {0} ساعات + {0} שעות {0} hours - {0} جزء من الثانية + {0} מילי שניות {0} milliseconds - {0} أجزاء من الثانية + {0} מילי שניות {0} milliseconds - {0} دقيقة + {0} דקות {0} minutes - {0} دقائق + {0} דקות {0} minutes - {0} ثانية + {0} שניות {0} seconds - {0} ثوان + {0} שניות {0} seconds From ae5777c19d5af2c95cd61f75ccf6fe2633b85a25 Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Thu, 10 Apr 2014 00:38:29 +0300 Subject: [PATCH 3/9] Mixup with the test files --- .../Localisation/ar/TimeSpanHumanizeTests.cs | 54 +++++++++---------- .../Localisation/he/TimeSpanHumanizeTests.cs | 52 +++++++++--------- 2 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs index 78a4fb04d..1b54942fa 100644 --- a/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/ar/TimeSpanHumanizeTests.cs @@ -2,19 +2,17 @@ using Xunit; using Xunit.Extensions; -namespace Humanizer.Tests.Localisation.he +namespace Humanizer.Tests.Localisation.ar { public class TimeSpanHumanizeTests : AmbientCulture { - public TimeSpanHumanizeTests() : base("he") - { - } + public TimeSpanHumanizeTests() : base("ar") { } [Theory] - [InlineData(7, "שבוע")] - [InlineData(14, "שבועיים")] - [InlineData(21, "3 שבועות")] - [InlineData(77, "11 שבועות")] + [InlineData(7, "أسبوع واحد")] + [InlineData(14, "أسبوعين")] + [InlineData(21, "3 أسابيع")] + [InlineData(77, "11 أسبوع")] public void Weeks(int days, string expected) { Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); @@ -22,29 +20,29 @@ public void Weeks(int days, string expected) [Theory] - [InlineData(1, "יום")] - [InlineData(2, "יומיים")] - [InlineData(3, "3 ימים")] + [InlineData(1, "يوم واحد")] + [InlineData(2, "يومين")] + [InlineData(3, "3 أيام")] public void Days(int days, string expected) { Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); } [Theory] - [InlineData(1, "שעה")] - [InlineData(2, "שעתיים")] - [InlineData(3, "3 שעות")] - [InlineData(11, "11 שעות")] + [InlineData(1, "ساعة واحدة")] + [InlineData(2, "ساعتين")] + [InlineData(3, "3 ساعات")] + [InlineData(11, "11 ساعة")] public void Hours(int hours, string expected) { Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize()); } [Theory] - [InlineData(1, "דקה")] - [InlineData(2, "שתי דקות")] - [InlineData(3, "3 דקות")] - [InlineData(11, "11 דקות")] + [InlineData(1, "دقيقة واحدة")] + [InlineData(2, "دقيقتين")] + [InlineData(3, "3 دقائق")] + [InlineData(11, "11 دقيقة")] public void Minutes(int minutes, string expected) { Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize()); @@ -52,20 +50,20 @@ public void Minutes(int minutes, string expected) [Theory] - [InlineData(1, "שניה")] - [InlineData(2, "שתי שניות")] - [InlineData(3, "3 שניות")] - [InlineData(11, "11 שניות")] + [InlineData(1, "ثانية واحدة")] + [InlineData(2, "ثانيتين")] + [InlineData(3, "3 ثوان")] + [InlineData(11, "11 ثانية")] public void Seconds(int seconds, string expected) { Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize()); } [Theory] - [InlineData(1, "מילי שניה")] - [InlineData(2, "שתי מילי שניות")] - [InlineData(3, "3 מילי שניות")] - [InlineData(11, "11 מילי שניות")] + [InlineData(1, "جزء من الثانية")] + [InlineData(2, "جزئين من الثانية")] + [InlineData(3, "3 أجزاء من الثانية")] + [InlineData(11, "11 جزء من الثانية")] public void Milliseconds(int milliseconds, string expected) { Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize()); @@ -74,7 +72,7 @@ public void Milliseconds(int milliseconds, string expected) [Fact] public void NoTime() { - Assert.Equal("אפס", TimeSpan.Zero.Humanize()); + Assert.Equal("حالاً", TimeSpan.Zero.Humanize()); } } } \ No newline at end of file diff --git a/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs index 1b54942fa..2ae115e54 100644 --- a/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs @@ -2,17 +2,17 @@ using Xunit; using Xunit.Extensions; -namespace Humanizer.Tests.Localisation.ar +namespace Humanizer.Tests.Localisation.he { public class TimeSpanHumanizeTests : AmbientCulture { - public TimeSpanHumanizeTests() : base("ar") { } + public TimeSpanHumanizeTests() : base("he") { } [Theory] - [InlineData(7, "أسبوع واحد")] - [InlineData(14, "أسبوعين")] - [InlineData(21, "3 أسابيع")] - [InlineData(77, "11 أسبوع")] + [InlineData(7, "שבוע")] + [InlineData(14, "שבועיים")] + [InlineData(21, "3 שבועות")] + [InlineData(77, "11 שבועות")] public void Weeks(int days, string expected) { Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); @@ -20,29 +20,29 @@ public void Weeks(int days, string expected) [Theory] - [InlineData(1, "يوم واحد")] - [InlineData(2, "يومين")] - [InlineData(3, "3 أيام")] + [InlineData(1, "יום")] + [InlineData(2, "יומיים")] + [InlineData(3, "3 ימים")] public void Days(int days, string expected) { Assert.Equal(expected, TimeSpan.FromDays(days).Humanize()); } [Theory] - [InlineData(1, "ساعة واحدة")] - [InlineData(2, "ساعتين")] - [InlineData(3, "3 ساعات")] - [InlineData(11, "11 ساعة")] + [InlineData(1, "שעה")] + [InlineData(2, "שעתיים")] + [InlineData(3, "3 שעות")] + [InlineData(11, "11 שעות")] public void Hours(int hours, string expected) { Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize()); } [Theory] - [InlineData(1, "دقيقة واحدة")] - [InlineData(2, "دقيقتين")] - [InlineData(3, "3 دقائق")] - [InlineData(11, "11 دقيقة")] + [InlineData(1, "דקה")] + [InlineData(2, "שתי דקות")] + [InlineData(3, "3 דקות")] + [InlineData(11, "11 דקות")] public void Minutes(int minutes, string expected) { Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize()); @@ -50,20 +50,20 @@ public void Minutes(int minutes, string expected) [Theory] - [InlineData(1, "ثانية واحدة")] - [InlineData(2, "ثانيتين")] - [InlineData(3, "3 ثوان")] - [InlineData(11, "11 ثانية")] + [InlineData(1, "שניה")] + [InlineData(2, "שתי שניות")] + [InlineData(3, "3 שניות")] + [InlineData(11, "11 שניות")] public void Seconds(int seconds, string expected) { Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize()); } [Theory] - [InlineData(1, "جزء من الثانية")] - [InlineData(2, "جزئين من الثانية")] - [InlineData(3, "3 أجزاء من الثانية")] - [InlineData(11, "11 جزء من الثانية")] + [InlineData(1, "מילי שניה")] + [InlineData(2, "שתי מילי שניות")] + [InlineData(3, "3 מילי שניות")] + [InlineData(11, "11 מילי שניות")] public void Milliseconds(int milliseconds, string expected) { Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize()); @@ -72,7 +72,7 @@ public void Milliseconds(int milliseconds, string expected) [Fact] public void NoTime() { - Assert.Equal("حالاً", TimeSpan.Zero.Humanize()); + Assert.Equal("אפס", TimeSpan.Zero.Humanize()); } } } \ No newline at end of file From 1cdd5babdd0b2992bebd27295b9aec58bb7021e8 Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Thu, 10 Apr 2014 00:41:46 +0300 Subject: [PATCH 4/9] Correct translation of TimeSpan.Zero --- src/Humanizer.Tests/Humanizer.Tests.csproj | 4 ++-- src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs | 2 +- src/Humanizer/Properties/Resources.he.resx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 54bcadb5b..3f8f50539 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -93,7 +93,7 @@ - + @@ -104,7 +104,7 @@ - + diff --git a/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs index 2ae115e54..57c31f4ad 100644 --- a/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs @@ -72,7 +72,7 @@ public void Milliseconds(int milliseconds, string expected) [Fact] public void NoTime() { - Assert.Equal("אפס", TimeSpan.Zero.Humanize()); + Assert.Equal("אין זמן", TimeSpan.Zero.Humanize()); } } } \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.he.resx b/src/Humanizer/Properties/Resources.he.resx index d030ce89c..df34ad673 100644 --- a/src/Humanizer/Properties/Resources.he.resx +++ b/src/Humanizer/Properties/Resources.he.resx @@ -190,7 +190,7 @@ single week - אפס + אין זמן no time From 6c79e5efd43d6519590541bf8b7f921a7d0af75b Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Sat, 12 Apr 2014 15:08:16 +0300 Subject: [PATCH 5/9] Moving Hebrew formatter to new location, removing single line braces --- src/Humanizer/Configuration/Configurator.cs | 1 + src/Humanizer/Humanizer.csproj | 3 +-- .../Localisation/{ => Formatters}/HebrewFormatter.cs | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) rename src/Humanizer/Localisation/{ => Formatters}/HebrewFormatter.cs (89%) diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index 4d7bfc00e..792f909da 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using Humanizer.DateTimeHumanizeStrategy; +using Humanizer.Localisation; using Humanizer.Localisation.Formatters; namespace Humanizer.Configuration diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index e72ab436a..83c962ef0 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -87,8 +87,7 @@ - - + diff --git a/src/Humanizer/Localisation/HebrewFormatter.cs b/src/Humanizer/Localisation/Formatters/HebrewFormatter.cs similarity index 89% rename from src/Humanizer/Localisation/HebrewFormatter.cs rename to src/Humanizer/Localisation/Formatters/HebrewFormatter.cs index e84a693d5..23542079f 100644 --- a/src/Humanizer/Localisation/HebrewFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/HebrewFormatter.cs @@ -1,4 +1,4 @@ -namespace Humanizer.Localisation +namespace Humanizer.Localisation.Formatters { internal class HebrewFormatter : DefaultFormatter { @@ -9,16 +9,12 @@ protected override string GetResourceKey(string resourceKey, int number) { //In Hebrew pluralization 2 entities gets a different word. if (number == 2) - { return resourceKey + DualPostfix; - } //In Hebrew pluralization entities where the count is between 3 and 10 gets a different word. //See http://lib.cet.ac.il/pages/item.asp?item=21585 for explanation if (number >= 3 && number <= 10) - { return resourceKey + PluralPostfix; - } return resourceKey; } From e24e08aa10bf5f040be73b776945f5b581e8aa5d Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Sat, 12 Apr 2014 15:10:05 +0300 Subject: [PATCH 6/9] Adding Roslyn's *.sln.ide metadata directory to ignore fir --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f58dc1baa..4212daa65 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,6 @@ PackageBuild/* Build/* src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.received.txt *.tss -src/TestResults/* \ No newline at end of file +src/TestResults/* +# Roslyn's metadata directory +*.sln.ide/ \ No newline at end of file From cd407506e91e9caee5e360ac194d2e302d04fec8 Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Sat, 12 Apr 2014 15:23:01 +0300 Subject: [PATCH 7/9] Fixed Date tests to use DateHumanize.Verify. Fixed some grammatical Hebrew mistakes --- .../Localisation/he/DateHumanizeTests.cs | 15 ++++++++------- .../Localisation/he/TimeSpanHumanizeTests.cs | 10 +++++----- src/Humanizer/Configuration/Configurator.cs | 1 - src/Humanizer/Properties/Resources.he.resx | 12 ++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs index 47dd80972..f44f1c73f 100644 --- a/src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs @@ -1,4 +1,5 @@ using System; +using Humanizer.Localisation; using Xunit; using Xunit.Extensions; @@ -15,7 +16,7 @@ public DateHumanizeTests() : base("he") { } [InlineData(-11, "לפני 11 יום")] public void DaysAgo(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -25,7 +26,7 @@ public void DaysAgo(int days, string expected) [InlineData(-11, "לפני 11 שעות")] public void HoursAgo(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -35,7 +36,7 @@ public void HoursAgo(int hours, string expected) [InlineData(-11, "לפני 11 דקות")] public void MinutesAgo(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -45,17 +46,17 @@ public void MinutesAgo(int minutes, string expected) [InlineData(-11, "לפני 11 חודשים")] public void MonthsAgo(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] [InlineData(-2, "לפני 2 שניות")] - [InlineData(-1, "לפני שניה")] + [InlineData(-1, "לפני שנייה")] [InlineData(-3, "לפני 3 שניות")] [InlineData(-11, "לפני 11 שניות")] public void SecondsAgo(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -65,7 +66,7 @@ public void SecondsAgo(int seconds, string expected) [InlineData(-11, "לפני 11 שנה")] public void YearsAgo(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } } } diff --git a/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs index 57c31f4ad..03ca8097d 100644 --- a/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs @@ -50,7 +50,7 @@ public void Minutes(int minutes, string expected) [Theory] - [InlineData(1, "שניה")] + [InlineData(1, "שנייה")] [InlineData(2, "שתי שניות")] [InlineData(3, "3 שניות")] [InlineData(11, "11 שניות")] @@ -60,10 +60,10 @@ public void Seconds(int seconds, string expected) } [Theory] - [InlineData(1, "מילי שניה")] - [InlineData(2, "שתי מילי שניות")] - [InlineData(3, "3 מילי שניות")] - [InlineData(11, "11 מילי שניות")] + [InlineData(1, "אלפית שנייה")] + [InlineData(2, "שתי אלפיות שנייה")] + [InlineData(3, "3 אלפיות שנייה")] + [InlineData(11, "11 אלפיות שנייה")] public void Milliseconds(int milliseconds, string expected) { Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize()); diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index 792f909da..4d7bfc00e 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Globalization; using Humanizer.DateTimeHumanizeStrategy; -using Humanizer.Localisation; using Humanizer.Localisation.Formatters; namespace Humanizer.Configuration diff --git a/src/Humanizer/Properties/Resources.he.resx b/src/Humanizer/Properties/Resources.he.resx index df34ad673..d446da912 100644 --- a/src/Humanizer/Properties/Resources.he.resx +++ b/src/Humanizer/Properties/Resources.he.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - לפני שניה + לפני שנייה one second ago @@ -174,7 +174,7 @@ single hour - מילי שניה + אלפית שנייה single millisecond @@ -182,7 +182,7 @@ single minute - שניה + שנייה single second @@ -230,7 +230,7 @@ two hours - שתי מילי שניות + שתי אלפיות שנייה two milliseconds @@ -258,11 +258,11 @@ {0} hours - {0} מילי שניות + {0} אלפיות שנייה {0} milliseconds - {0} מילי שניות + {0} אלפיות שנייה {0} milliseconds From 4570b9bff5ad144e5c3f955ba75cedc1c27ca312 Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Sat, 12 Apr 2014 15:25:21 +0300 Subject: [PATCH 8/9] Removed some residual VS-generated metadata for .Designer files (???) --- src/Humanizer/Humanizer.csproj | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 83c962ef0..9a2639b9c 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -163,10 +163,7 @@ - - Resources.he1.Designer.cs - Designer - + From 23ef45089d9df4a9a76e03bde4c480938c779c0f Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Sat, 12 Apr 2014 15:28:36 +0300 Subject: [PATCH 9/9] Adding release notes --- release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release_notes.md b/release_notes.md index 3ce0524ef..28a1811e2 100644 --- a/release_notes.md +++ b/release_notes.md @@ -4,6 +4,7 @@ - [#190](https://github.com/MehdiK/Humanizer/pull/190): Added French translation for ToWords and ToOrdinalWords - [#179](https://github.com/MehdiK/Humanizer/pull/179): Adding Hungarian localisation - [#181](https://github.com/Mehdik/Humanizer/pull/181): Added Bulgarian localization, date and timespan tests + - [#148](https://github.com/Mehdik/Humanizer/pull/148): Adding Hebrew localization for date and timespan [Commits](https://github.com/MehdiK/Humanizer/compare/v1.20.15...master)