-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from harouny/master
Add Arabic formatter and Arabic TimeSpan and Date localization for multiple units
- Loading branch information
Showing
7 changed files
with
273 additions
and
25 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
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.ar | ||
{ | ||
public class DateHumanizeTests : AmbientCulture | ||
{ | ||
public DateHumanizeTests() : base("ar") { } | ||
|
||
|
||
[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, "منذ دقيقتين")] | ||
[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, "منذ ثانيتين")] | ||
[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()); | ||
} | ||
|
||
[Fact] | ||
public void NotYet() | ||
{ | ||
Assert.Equal("ليس بعد", DateTime.UtcNow.AddDays(1).Humanize()); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Humanizer.Localisation | ||
{ | ||
internal class ArabicFormatter : DefaultFormatter | ||
{ | ||
private const string DualPostfix = "_Dual"; | ||
private const string PluralPostfix = "_Plural"; | ||
|
||
protected override string GetResourceKey(string resourceKey, int number) | ||
{ | ||
//In Arabic pluralization 2 entities gets a different word. | ||
if (number == 2) | ||
return resourceKey + DualPostfix; | ||
|
||
//In Arabic pluralization entities where the count is between 3 and 10 gets a different word. | ||
if (number >= 3 && number <= 10 ) | ||
return resourceKey + PluralPostfix; | ||
|
||
return resourceKey; | ||
} | ||
} | ||
} |
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