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

Adds Chinese localisation #357

Closed
wants to merge 5 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
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
###In Development
- [#357](https://github.com/MehdiK/Humanizer/pull/357): Adds Chinese localisation
- [#350](https://github.com/MehdiK/Humanizer/pull/350): Added missing values for nl

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.31.0...master)
Expand Down
8 changes: 7 additions & 1 deletion src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<Compile Include="Localisation\uz-Cyrl-UZ\DateHumanizeTests.cs" />
<Compile Include="Localisation\uz-Cyrl-UZ\NumberToWordsTests.cs" />
<Compile Include="Localisation\uz-Cyrl-UZ\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\uz-Latn-UZ\DateHumanizeTests.cs"/>
<Compile Include="Localisation\uz-Latn-UZ\DateHumanizeTests.cs" />
<Compile Include="Localisation\uz-Latn-UZ\NumberToWordsTests.cs" />
<Compile Include="Localisation\tr\DateHumanizeTests.cs" />
<Compile Include="Localisation\tr\NumberToWordsTests.cs" />
Expand All @@ -152,6 +152,12 @@
<Compile Include="Localisation\it\CollectionFormatterTests.cs" />
<Compile Include="Localisation\it\OrdinalizerTests.cs" />
<Compile Include="Localisation\it\NumberToWordsTests.cs" />
<Compile Include="Localisation\zh-CHS\DateHumanizeTests.cs" />
<Compile Include="Localisation\zh-CHS\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\zh-CHT\DateHumanizeTests.cs" />
<Compile Include="Localisation\zh-CHT\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\zh-CN\DateHumanizeTests.cs" />
<Compile Include="Localisation\zh-CN\TimeSpanHumanizeTests.cs" />
<Compile Include="ResourceKeyTests.cs" />
<Compile Include="RomanNumeralTests.cs" />
<Compile Include="StringExtensionsTests.cs" />
Expand Down
107 changes: 107 additions & 0 deletions src/Humanizer.Tests/Localisation/zh-CHS/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Humanizer.Localisation;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.zhCHS
{
public class DateHumanizeTests : AmbientCulture
{
public DateHumanizeTests() : base("zh-CHS") { }

[Theory]
[InlineData(1, "昨天")]
[InlineData(0, "今天")]
public void DaysAgo(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past);
}

[Theory]
[InlineData(1, "明天")]
[InlineData(0, "今天")]
public void DaysFromNow(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future);
}

[Theory]
[InlineData(2, "2 小时前")]
[InlineData(1, "1 小时前")]
public void HoursAgo(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past);
}

[Theory]
[InlineData(2, "2 小时后")]
[InlineData(1, "1 小时后")]
public void HoursFromNow(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future);
}

[Theory]
[InlineData(-2, "2 分钟前")]
[InlineData(-1, "1 分钟前")]
[InlineData(60, "1 小时前")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
}

[Theory]
[InlineData(2, "2 分钟后")]
[InlineData(1, "1 分钟后")]
public void MinutesFromNow(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future);
}

[Theory]
[InlineData(-2, "2 个月前")]
[InlineData(-1, "1 个月前")]
public void MonthsAgo(int months, string expected)
{
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past);
}

[Theory]
[InlineData(2, "2 个月后")]
[InlineData(1, "1 个月后")]
public void MonthsFromNow(int months, string expected)
{
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future);
}

[Theory]
[InlineData(-2, "2 秒钟前")]
[InlineData(-1, "1 秒钟前")]
public void SecondsAgo(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past);
}

[Theory]
[InlineData(2, "2 秒钟后")]
[InlineData(1, "1 秒钟后")]
public void SecondsFromNow(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future);
}

[Theory]
[InlineData(-2, "2 年前")]
[InlineData(-1, "去年")]
public void YearsAgo(int years, string expected)
{
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past);
}

[Theory]
[InlineData(2, "2 年后")]
[InlineData(1, "明年")]
public void YearsFromNow(int years, string expected)
{
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future);
}
}
}
70 changes: 70 additions & 0 deletions src/Humanizer.Tests/Localisation/zh-CHS/TimeSpanHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using Xunit;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.zhCHS
{
public class TimeSpanHumanizeTests : AmbientCulture
{
public TimeSpanHumanizeTests() : base("zh-CHS") { }

[Theory]
[InlineData(7, "1 周")]
[InlineData(14, "2 周")]
[InlineData(21, "3 周")]
[InlineData(77, "11 周")]
public void Weeks(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}


[Theory]
[InlineData(1, "1 天")]
[InlineData(2, "2 天")]
public void Days(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

[Theory]
[InlineData(1, "1 小时")]
[InlineData(2, "2 小时")]
public void Hours(int hours, string expected)
{
Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize());
}

[Theory]
[InlineData(1, "1 分")]
[InlineData(2, "2 分")]
public void Minutes(int minutes, string expected)
{
Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize());
}


[Theory]
[InlineData(1, "1 秒")]
[InlineData(2, "2 秒")]
public void Seconds(int seconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize());
}

[Theory]
[InlineData(1, "1 毫秒")]
[InlineData(2, "2 毫秒")]
public void Milliseconds(int milliseconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize());
}

[Fact]
public void NoTime()
{
// This one doesn't make a lot of sense but ... w/e
Assert.Equal("没有时间", TimeSpan.Zero.Humanize());
}
}
}
107 changes: 107 additions & 0 deletions src/Humanizer.Tests/Localisation/zh-CHT/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Humanizer.Localisation;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.zhCHT
{
public class DateHumanizeTests : AmbientCulture
{
public DateHumanizeTests() : base("zh-CHT") { }

[Theory]
[InlineData(1, "昨天")]
[InlineData(0, "今天")]
public void DaysAgo(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past);
}

[Theory]
[InlineData(1, "明天")]
[InlineData(0, "今天")]
public void DaysFromNow(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future);
}

[Theory]
[InlineData(2, "2 小時前")]
[InlineData(1, "1 小時前")]
public void HoursAgo(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past);
}

[Theory]
[InlineData(2, "2 小時後")]
[InlineData(1, "1 小時後")]
public void HoursFromNow(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future);
}

[Theory]
[InlineData(-2, "2 分鐘前")]
[InlineData(-1, "1 分鐘前")]
[InlineData(60, "1 小時前")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
}

[Theory]
[InlineData(2, "2 分鐘後")]
[InlineData(1, "1 分鐘後")]
public void MinutesFromNow(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future);
}

[Theory]
[InlineData(-2, "2 個月前")]
[InlineData(-1, "1 個月前")]
public void MonthsAgo(int months, string expected)
{
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past);
}

[Theory]
[InlineData(2, "2 個月後")]
[InlineData(1, "1 個月後")]
public void MonthsFromNow(int months, string expected)
{
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future);
}

[Theory]
[InlineData(-2, "2 秒鐘前")]
[InlineData(-1, "1 秒鐘前")]
public void SecondsAgo(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past);
}

[Theory]
[InlineData(2, "2 秒鐘後")]
[InlineData(1, "1 秒鐘後")]
public void SecondsFromNow(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future);
}

[Theory]
[InlineData(-2, "2 年前")]
[InlineData(-1, "去年")]
public void YearsAgo(int years, string expected)
{
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past);
}

[Theory]
[InlineData(2, "2 年後")]
[InlineData(1, "明年")]
public void YearsFromNow(int years, string expected)
{
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future);
}
}
}
70 changes: 70 additions & 0 deletions src/Humanizer.Tests/Localisation/zh-CHT/TimeSpanHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using Xunit;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.zhCHT
{
public class TimeSpanHumanizeTests : AmbientCulture
{
public TimeSpanHumanizeTests() : base("zh-CHT") { }

[Theory]
[InlineData(7, "1 周")]
[InlineData(14, "2 周")]
[InlineData(21, "3 周")]
[InlineData(77, "11 周")]
public void Weeks(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}


[Theory]
[InlineData(1, "1 天")]
[InlineData(2, "2 天")]
public void Days(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

[Theory]
[InlineData(1, "1 小時")]
[InlineData(2, "2 小時")]
public void Hours(int hours, string expected)
{
Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize());
}

[Theory]
[InlineData(1, "1 分")]
[InlineData(2, "2 分")]
public void Minutes(int minutes, string expected)
{
Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize());
}


[Theory]
[InlineData(1, "1 秒")]
[InlineData(2, "2 秒")]
public void Seconds(int seconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize());
}

[Theory]
[InlineData(1, "1 毫秒")]
[InlineData(2, "2 毫秒")]
public void Milliseconds(int milliseconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize());
}

[Fact]
public void NoTime()
{
// This one doesn't make a lot of sense but ... w/e
Assert.Equal("沒有時間", TimeSpan.Zero.Humanize());
}
}
}
Loading