Skip to content

Commit

Permalink
Merge pull request #1095 from hangy/register-ko
Browse files Browse the repository at this point in the history
Register Korean formatter
  • Loading branch information
clairernovotny committed Jul 3, 2021
2 parents 5c3b134 + ad1a1f2 commit e023645
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
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

0 comments on commit e023645

Please sign in to comment.