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

Add resource file for Vietnamese language. #269

Merged
merged 4 commits into from
May 21, 2014
Merged
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,6 +1,7 @@
###In Development
- [#257](https://github.com/Mehdik/Humanizer/pull/257): Added German localisation for ToOrdinalWords and Ordinalize
- [#261](https://github.com/Mehdik/Humanizer/pull/261): Added future dates to Portuguese - Brazil
- [#269](https://github.com/MehdiK/Humanizer/pull/269): Added Vietnamese localisation

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.25.4...master)

Expand Down
3 changes: 3 additions & 0 deletions src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
<Compile Include="DateTimeHumanizePrecisionStrategyTests.cs" />
<Compile Include="Localisation\tr\DateHumanizeTests.cs" />
<Compile Include="Localisation\tr\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\vi\DateHumanizeTests.cs" />
<Compile Include="Localisation\vi\TimeSpanHumanizeTests.cs" />
<Compile Include="ResourceKeyTests.cs" />
<Compile Include="RomanNumeralTests.cs" />
<Compile Include="StringExtensionsTests.cs" />
Expand Down Expand Up @@ -171,6 +173,7 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
107 changes: 107 additions & 0 deletions src/Humanizer.Tests/Localisation/vi/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.vi
{
public class DateHumanizeTests : AmbientCulture
{
public DateHumanizeTests() : base("vi") { }

[Theory]
[InlineData(1, "cách đây một giây")]
[InlineData(10, "cách đây 10 giây")]
public void SecondsAgo(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past);
}

[Theory]
[InlineData(1, "một giây nữa")]
[InlineData(10, "10 giây nữa")]
public void SecondsFromNow(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future);
}

[Theory]
[InlineData(1, "cách đây một phút")]
[InlineData(10, "cách đây 10 phút")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
}

[Theory]
[InlineData(1, "một phút nữa")]
[InlineData(10, "10 phút nữa")]
public void MinutesFromNow(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future);
}

[Theory]
[InlineData(1, "cách đây một tiếng")]
[InlineData(10, "cách đây 10 tiếng")]
public void HoursAgo(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past);
}

[Theory]
[InlineData(1, "một tiếng nữa")]
[InlineData(10, "10 tiếng nữa")]
public void HoursFromNow(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future);
}

[Theory]
[InlineData(1, "hôm qua")]
[InlineData(10, "cách đây 10 ngày")]
public void DaysAgo(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past);
}

[Theory]
[InlineData(1, "ngày mai")]
[InlineData(10, "10 ngày nữa")]
public void DaysFromNow(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future);
}

[Theory]
[InlineData(1, "cách đây một tháng")]
[InlineData(10, "cách đây 10 tháng")]
public void MonthsAgo(int months, string expected)
{
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past);
}

[Theory]
[InlineData(1, "một tháng nữa")]
[InlineData(10, "10 tháng nữa")]
public void MonthsFromNow(int months, string expected)
{
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future);
}

[Theory]
[InlineData(1, "cách đây một năm")]
[InlineData(2, "cách đây 2 năm")]
public void YearsAgo(int years, string expected)
{
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past);
}

[Theory]
[InlineData(1, "một năm nữa")]
[InlineData(2, "2 năm nữa")]
public void YearsFromNow(int years, string expected)
{
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future);
}

}
}
114 changes: 114 additions & 0 deletions src/Humanizer.Tests/Localisation/vi/TimeSpanHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using Xunit;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.vi
{
public class TimeSpanHumanizeTests : AmbientCulture
{
public TimeSpanHumanizeTests() : base("vi") { }

[Theory]
[InlineData(14, "2 tuần")]
[InlineData(7, "1 tuần")]
public void Weeks(int days, string expected)
{
var actual = TimeSpan.FromDays(days).Humanize();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(6, "6 ngày")]
[InlineData(2, "2 ngày")]
[InlineData(1, "1 ngày")]
public void Days(int days, string expected)
{
var actual = TimeSpan.FromDays(days).Humanize();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(2, "2 giờ")]
[InlineData(1, "1 giờ")]
public void Hours(int hours, string expected)
{
var actual = TimeSpan.FromHours(hours).Humanize();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(2, "2 phút")]
[InlineData(1, "1 phút")]
public void Minutes(int minutes, string expected)
{
var actual = TimeSpan.FromMinutes(minutes).Humanize();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(135, "2 phút")]
[InlineData(60, "1 phút")]
[InlineData(2, "2 giây")]
[InlineData(1, "1 giây")]
public void Seconds(int seconds, string expected)
{
var actual = TimeSpan.FromSeconds(seconds).Humanize();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(2500, "2 giây")]
[InlineData(1400, "1 giây")]
[InlineData(2, "2 phần ngàn giây")]
[InlineData(1, "1 phần ngàn giây")]
public void Milliseconds(int ms, string expected)
{
var actual = TimeSpan.FromMilliseconds(ms).Humanize();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(0, 3, "không giờ")]
[InlineData(0, 2, "không giờ")]
[InlineData(10, 2, "10 phần ngàn giây")]
[InlineData(1400, 2, "1 giây, 400 phần ngàn giây")]
[InlineData(2500, 2, "2 giây, 500 phần ngàn giây")]
[InlineData(120000, 2, "2 phút")]
[InlineData(62000, 2, "1 phút, 2 giây")]
[InlineData(62020, 2, "1 phút, 2 giây")]
[InlineData(62020, 3, "1 phút, 2 giây, 20 phần ngàn giây")]
[InlineData(3600020, 4, "1 giờ, 20 phần ngàn giây")]
[InlineData(3600020, 3, "1 giờ, 20 phần ngàn giây")]
[InlineData(3600020, 2, "1 giờ, 20 phần ngàn giây")]
[InlineData(3600020, 1, "1 giờ")]
[InlineData(3603001, 2, "1 giờ, 3 giây")]
[InlineData(3603001, 3, "1 giờ, 3 giây, 1 phần ngàn giây")]
[InlineData(86400000, 3, "1 ngày")]
[InlineData(86400000, 2, "1 ngày")]
[InlineData(86400000, 1, "1 ngày")]
[InlineData(86401000, 1, "1 ngày")]
[InlineData(86401000, 2, "1 ngày, 1 giây")]
[InlineData(86401200, 2, "1 ngày, 1 giây")]
[InlineData(86401200, 3, "1 ngày, 1 giây, 200 phần ngàn giây")]
[InlineData(1296000000, 1, "2 tuần")]
[InlineData(1296000000, 2, "2 tuần, 1 ngày")]
[InlineData(1299600000, 2, "2 tuần, 1 ngày")]
[InlineData(1299600000, 3, "2 tuần, 1 ngày, 1 giờ")]
[InlineData(1299630020, 3, "2 tuần, 1 ngày, 1 giờ")]
[InlineData(1299630020, 4, "2 tuần, 1 ngày, 1 giờ, 30 giây")]
[InlineData(1299630020, 5, "2 tuần, 1 ngày, 1 giờ, 30 giây, 20 phần ngàn giây")]
public void TimeSpanWithPrecesion(int milliseconds, int precesion, string expected)
Copy link
Member

Choose a reason for hiding this comment

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

This trips everyone up. You don't need to unit test these: if you're using testing every time unit in isolation, the combination is tested under English tests and will work. I will take them out.

{
var actual = TimeSpan.FromMilliseconds(milliseconds).Humanize(precesion);
Assert.Equal(expected, actual);
}

[Fact]
public void NoTime()
{
var noTime = TimeSpan.Zero;
var actual = noTime.Humanize();
Assert.Equal("không giờ", actual);
}
}
}
3 changes: 2 additions & 1 deletion src/Humanizer/Humanizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<EmbeddedResource Include="Properties\Resources.sr-Latn.resx" />
<EmbeddedResource Include="Properties\Resources.sr.resx" />
<EmbeddedResource Include="Properties\Resources.sv.resx" />
<EmbeddedResource Include="Properties\Resources.vi.resx" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
Expand All @@ -204,4 +205,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Loading