-
Notifications
You must be signed in to change notification settings - Fork 966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hebrew support #148
Hebrew support #148
Changes from all commits
45dfe03
df9cd22
ae5777c
1cdd5ba
6c79e5e
e24e08a
cd40750
4570b9b
23ef450
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using Humanizer.Localisation; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests.Localisation.he | ||
{ | ||
public class DateHumanizeTests : AmbientCulture | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stop changing the library! :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOL. I've rebased your changes. I can push this up if you want and you can add the other bits later. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, that'd be great. I'll send ToWords and FromNow later! |
||
{ | ||
public DateHumanizeTests() : base("he") { } | ||
|
||
[Theory] | ||
[InlineData(-1, "אתמול")] | ||
[InlineData(-2, "לפני יומיים")] | ||
[InlineData(-3, "לפני 3 ימים")] | ||
[InlineData(-11, "לפני 11 יום")] | ||
public void DaysAgo(int days, string expected) | ||
{ | ||
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "לפני שעתיים")] | ||
[InlineData(-1, "לפני שעה")] | ||
[InlineData(-3, "לפני 3 שעות")] | ||
[InlineData(-11, "לפני 11 שעות")] | ||
public void HoursAgo(int hours, string expected) | ||
{ | ||
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "לפני 2 דקות")] | ||
[InlineData(-1, "לפני דקה")] | ||
[InlineData(-3, "לפני 3 דקות")] | ||
[InlineData(-11, "לפני 11 דקות")] | ||
public void MinutesAgo(int minutes, string expected) | ||
{ | ||
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "לפני חודשיים")] | ||
[InlineData(-1, "לפני חודש")] | ||
[InlineData(-3, "לפני 3 חודשים")] | ||
[InlineData(-11, "לפני 11 חודשים")] | ||
public void MonthsAgo(int months, string expected) | ||
{ | ||
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "לפני 2 שניות")] | ||
[InlineData(-1, "לפני שנייה")] | ||
[InlineData(-3, "לפני 3 שניות")] | ||
[InlineData(-11, "לפני 11 שניות")] | ||
public void SecondsAgo(int seconds, string expected) | ||
{ | ||
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-2, "לפני שנתיים")] | ||
[InlineData(-1, "לפני שנה")] | ||
[InlineData(-3, "לפני 3 שנים")] | ||
[InlineData(-11, "לפני 11 שנה")] | ||
public void YearsAgo(int years, string expected) | ||
{ | ||
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Humanizer.Tests.Localisation.he | ||
{ | ||
public class TimeSpanHumanizeTests : AmbientCulture | ||
{ | ||
public TimeSpanHumanizeTests() : base("he") { } | ||
|
||
[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()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Humanizer.Localisation.Formatters | ||
{ | ||
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; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hahaha! Cool :)