Skip to content
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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ PackageBuild/*
Build/*
src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.received.txt
*.tss
src/TestResults/*
src/TestResults/*
# Roslyn's metadata directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha! Cool :)

*.sln.ide/
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
<Compile Include="Localisation\es\NumberToWordsTests.cs" />
<Compile Include="Localisation\hu\DateHumanizeTests.cs" />
<Compile Include="Localisation\hu\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\he\DateHumanizeTests.cs" />
<Compile Include="Localisation\ar\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\nb-NO\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\pl\DateHumanizeTests.cs" />
<Compile Include="Localisation\pl\NumberToWordsTests.cs" />
Expand All @@ -102,7 +104,7 @@
<Compile Include="Localisation\sk\DateHumanizeTests.cs" />
<Compile Include="Localisation\ar\DateHumanizeTests.cs" />
<Compile Include="Localisation\ar\NumberToWordsTests.cs" />
<Compile Include="Localisation\ar\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\he\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\nb-NO\DateHumanizeTests.cs" />
<Compile Include="Localisation\de\DateHumanizeTests.cs" />
<Compile Include="Localisation\de\TimeSpanHumanizeTests.cs" />
Expand Down
72 changes: 72 additions & 0 deletions src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add From Now resources and tests too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop changing the library! :D
Of course, will do!

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
}
}
}
78 changes: 78 additions & 0 deletions src/Humanizer.Tests/Localisation/he/TimeSpanHumanizeTests.cs
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());
}
}
}
1 change: 1 addition & 0 deletions src/Humanizer/Configuration/Configurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down
2 changes: 2 additions & 0 deletions src/Humanizer/Humanizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Compile Include="DateTimeHumanizeStrategy\PrecisionDateTimeHumanizeStrategy.cs" />
<Compile Include="Localisation\NumberToWords\PolishNumberToWordsConverter.cs" />
<Compile Include="Localisation\NumberToWords\RussianNumberToWordsConverter.cs" />
<Compile Include="Localisation\Formatters\HebrewFormatter.cs" />
<Compile Include="Localisation\Tense.cs" />
<Compile Include="Localisation\NumberToWords\SpanishNumberToWordsConverter.cs" />
<Compile Include="TimeSpanHumanizeExtensions.cs" />
Expand Down Expand Up @@ -162,6 +163,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.bg.resx" />
<EmbeddedResource Include="Properties\Resources.he.resx" />
<EmbeddedResource Include="Properties\Resources.da.resx" />
<EmbeddedResource Include="Properties\Resources.hu.resx" />
<EmbeddedResource Include="Properties\Resources.pl.resx" />
Expand Down
22 changes: 22 additions & 0 deletions src/Humanizer/Localisation/Formatters/HebrewFormatter.cs
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;
}
}
}
Loading