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

Register Korean formatter #1095

Merged
merged 1 commit into from Jul 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -111,6 +111,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ja\DateHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ja\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ja\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ko-KR\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ku\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ku\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\mt\DateHumanizeTests.cs" />
Expand Down
@@ -0,0 +1,98 @@
using System;
using Xunit;

namespace Humanizer.Tests.Localisation.koKR
{
[UseCulture("ko-KR")]
public class TimeSpanHumanizeTests
{
[Theory]
[Trait("Translation", "Google")]
[InlineData(366, "1년")]
[InlineData(731, "2년")]
[InlineData(1096, "3년")]
[InlineData(4018, "11년")]
public void Years(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
}

[Theory]
[Trait("Translation", "Google")]
[InlineData(31, "1개월")]
[InlineData(61, "2개월")]
[InlineData(92, "3개월")]
[InlineData(335, "11개월")]
public void Months(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
}

[Theory]
[Trait("Translation", "Google")]
[InlineData(7, "1주")]
[InlineData(14, "2주")]
public void Weeks(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

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

[Theory]
[Trait("Translation", "Google")]
[InlineData(1, "1시간")]
[InlineData(2, "2시간")]
public void Hours(int hours, string expected)
{
Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize());
}

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

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

[Theory]
[Trait("Translation", "Google")]
[InlineData(1, "1밀리초")]
[InlineData(2, "2밀리초")]
public void Milliseconds(int milliseconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize());
}

[Fact]
[Trait("Translation", "Google")]
public void NoTime()
{
Assert.Equal("0밀리초", TimeSpan.Zero.Humanize());
}

[Fact]
public void NoTimeToWords()
{
Assert.Equal("방금", TimeSpan.Zero.Humanize(toWords: true));
}
}
}
1 change: 1 addition & 0 deletions src/Humanizer/Configuration/FormatterRegistry.cs
Expand Up @@ -41,6 +41,7 @@ public FormatterRegistry() : base(new DefaultFormatter("en-US"))
RegisterDefaultFormatter("hy");
RegisterDefaultFormatter("id");
RegisterDefaultFormatter("ja");
RegisterDefaultFormatter("ko-KR");
Register("mt", new MalteseFormatter("mt"));
RegisterDefaultFormatter("nb");
RegisterDefaultFormatter("nb-NO");
Expand Down