diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index d0659af4d..8e51a3c18 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -75,6 +75,7 @@ + @@ -87,6 +88,7 @@ + diff --git a/src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs new file mode 100644 index 000000000..16a375a3f --- /dev/null +++ b/src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs @@ -0,0 +1,168 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.sk +{ + public class DateTimeHumanizeTests : AmbientCulture + { + public DateTimeHumanizeTests() + : base("sk-SK") + { + } + + [Theory] + [InlineData(1, "o sekundu")] + [InlineData(2, "o 2 sekundy")] + [InlineData(3, "o 3 sekundy")] + [InlineData(4, "o 4 sekundy")] + [InlineData(5, "o 5 sekúnd")] + [InlineData(6, "o 6 sekúnd")] + [InlineData(10, "o 10 sekúnd")] + public void SecondsFromNow(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddSeconds(number).Humanize()); + } + + [Theory] + [InlineData(1, "o minútu")] + [InlineData(2, "o 2 minúty")] + [InlineData(3, "o 3 minúty")] + [InlineData(4, "o 4 minúty")] + [InlineData(5, "o 5 minút")] + [InlineData(6, "o 6 minút")] + [InlineData(10, "o 10 minút")] + public void MinutesFromNow(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMinutes(number).Humanize()); + } + + [Theory] + [InlineData(1, "o hodinu")] + [InlineData(2, "o 2 hodiny")] + [InlineData(3, "o 3 hodiny")] + [InlineData(4, "o 4 hodiny")] + [InlineData(5, "o 5 hodín")] + [InlineData(6, "o 6 hodín")] + [InlineData(10, "o 10 hodín")] + public void HoursFromNow(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddHours(number).Humanize()); + } + + [Theory] + [InlineData(1, "zajtra")] + [InlineData(2, "o 2 dni")] + [InlineData(3, "o 3 dni")] + [InlineData(4, "o 4 dni")] + [InlineData(9, "o 9 dní")] + [InlineData(10, "o 10 dní")] + public void DayFromNow(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddDays(number).Humanize()); + } + + [Theory] + [InlineData(1, "o mesiac")] + [InlineData(2, "o 2 mesiace")] + [InlineData(3, "o 3 mesiace")] + [InlineData(4, "o 4 mesiace")] + [InlineData(5, "o 5 mesiacov")] + [InlineData(6, "o 6 mesiacov")] + [InlineData(10, "o 10 mesiacov")] + public void MonthsFromNow(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMonths(number).Humanize()); + } + + [Theory] + [InlineData(1, "o rok")] + [InlineData(2, "o 2 roky")] + [InlineData(3, "o 3 roky")] + [InlineData(4, "o 4 roky")] + [InlineData(5, "o 5 rokov")] + [InlineData(6, "o 6 rokov")] + [InlineData(10, "o 10 rokov")] + public void YearsFromNow(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddYears(number).Humanize()); + } + + [Theory] + [InlineData(1, "pred sekundou")] + [InlineData(2, "pred 2 sekundami")] + [InlineData(3, "pred 3 sekundami")] + [InlineData(4, "pred 4 sekundami")] + [InlineData(5, "pred 5 sekundami")] + [InlineData(6, "pred 6 sekundami")] + [InlineData(10, "pred 10 sekundami")] + public void SecondsAgo(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddSeconds(-1*number).Humanize()); + } + + [Theory] + [InlineData(1, "pred minútou")] + [InlineData(2, "pred 2 minútami")] + [InlineData(3, "pred 3 minútami")] + [InlineData(4, "pred 4 minútami")] + [InlineData(5, "pred 5 minútami")] + [InlineData(6, "pred 6 minútami")] + [InlineData(10, "pred 10 minútami")] + public void MinutesAgo(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMinutes(-1*number).Humanize()); + } + + [Theory] + [InlineData(1, "pred hodinou")] + [InlineData(2, "pred 2 hodinami")] + [InlineData(3, "pred 3 hodinami")] + [InlineData(4, "pred 4 hodinami")] + [InlineData(5, "pred 5 hodinami")] + [InlineData(6, "pred 6 hodinami")] + [InlineData(10, "pred 10 hodinami")] + public void HoursAgo(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddHours(-1*number).Humanize()); + } + + [Theory] + [InlineData(1, "včera")] + [InlineData(2, "pred 2 dňami")] + [InlineData(3, "pred 3 dňami")] + [InlineData(4, "pred 4 dňami")] + [InlineData(9, "pred 9 dňami")] + [InlineData(10, "pred 10 dňami")] + public void DayAgo(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddDays(-1*number).Humanize()); + } + + [Theory] + [InlineData(1, "pred mesiacom")] + [InlineData(2, "pred 2 mesiacmi")] + [InlineData(3, "pred 3 mesiacmi")] + [InlineData(4, "pred 4 mesiacmi")] + [InlineData(5, "pred 5 mesiacmi")] + [InlineData(6, "pred 6 mesiacmi")] + [InlineData(10, "pred 10 mesiacmi")] + public void MonthsAgo(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMonths(-1*number).Humanize()); + } + + [Theory] + [InlineData(1, "pred rokom")] + [InlineData(2, "pred 2 rokmi")] + [InlineData(3, "pred 3 rokmi")] + [InlineData(4, "pred 4 rokmi")] + [InlineData(5, "pred 5 rokmi")] + [InlineData(6, "pred 6 rokmi")] + [InlineData(10, "pred 10 rokmi")] + public void YearsAgo(int number, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddYears(-1*number).Humanize()); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/sk/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/sk/TimeSpanHumanizeTests.cs new file mode 100644 index 000000000..4789958fe --- /dev/null +++ b/src/Humanizer.Tests/Localisation/sk/TimeSpanHumanizeTests.cs @@ -0,0 +1,92 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.sk +{ + public class TimeSpanHumanizeTests : AmbientCulture + { + public TimeSpanHumanizeTests() + : base("sk-SK") + { + } + + [Theory] + [InlineData(1, "1 milisekunda")] + [InlineData(2, "2 milisekundy")] + [InlineData(3, "3 milisekundy")] + [InlineData(4, "4 milisekundy")] + [InlineData(5, "5 milisekúnd")] + [InlineData(6, "6 milisekúnd")] + [InlineData(10, "10 milisekúnd")] + public void Miliseconds(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromMilliseconds(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 sekunda")] + [InlineData(2, "2 sekundy")] + [InlineData(3, "3 sekundy")] + [InlineData(4, "4 sekundy")] + [InlineData(5, "5 sekúnd")] + [InlineData(6, "6 sekúnd")] + [InlineData(10, "10 sekúnd")] + public void Seconds(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromSeconds(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 minúta")] + [InlineData(2, "2 minúty")] + [InlineData(3, "3 minúty")] + [InlineData(4, "4 minúty")] + [InlineData(5, "5 minút")] + [InlineData(6, "6 minút")] + [InlineData(10, "10 minút")] + public void Minutes(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromMinutes(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 hodina")] + [InlineData(2, "2 hodiny")] + [InlineData(3, "3 hodiny")] + [InlineData(4, "4 hodiny")] + [InlineData(5, "5 hodín")] + [InlineData(6, "6 hodín")] + [InlineData(10, "10 hodín")] + public void Hours(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromHours(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 deň")] + [InlineData(2, "2 dni")] + [InlineData(3, "3 dni")] + [InlineData(4, "4 dni")] + [InlineData(5, "5 dní")] + [InlineData(6, "6 dní")] + public void Days(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 týždeň")] + [InlineData(2, "2 týždne")] + [InlineData(3, "3 týždne")] + [InlineData(4, "4 týždne")] + [InlineData(5, "5 týždňov")] + [InlineData(6, "6 týždňov")] + public void Weeks(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(number * 7).Humanize()); + } + + + } +} diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index 463f8e889..d6f5b670b 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -16,6 +16,7 @@ public static class Configurator { "ro", () => new RomanianFormatter() }, { "ru", () => new RussianFormatter() }, { "ar", () => new ArabicFormatter() }, + { "sk", () => new SlovakFormatter() } }; /// diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index f45626c98..1a0a911f4 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -75,6 +75,7 @@ + @@ -157,12 +158,17 @@ - + + Designer + + + Resources.sk.Designer.cs + diff --git a/src/Humanizer/Localisation/SlovakFormatter.cs b/src/Humanizer/Localisation/SlovakFormatter.cs new file mode 100644 index 000000000..8b2419bbb --- /dev/null +++ b/src/Humanizer/Localisation/SlovakFormatter.cs @@ -0,0 +1,15 @@ +namespace Humanizer.Localisation +{ + internal class SlovakFormatter : DefaultFormatter + { + private const string PaucalPostfix = "_Paucal"; + + protected override string GetResourceKey(string resourceKey, int number) + { + if (number > 1 && number < 5) + return resourceKey + PaucalPostfix; + + return resourceKey; + } + } +} diff --git a/src/Humanizer/Properties/Resources.sk.resx b/src/Humanizer/Properties/Resources.sk.resx new file mode 100644 index 000000000..acebbfe4f --- /dev/null +++ b/src/Humanizer/Properties/Resources.sk.resx @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + pred sekundou + + + pred {0} sekundami + + + pred minútou + + + pred {0} minútami + + + pred hodinou + + + pred {0} hodinami + + + včera + + + pred {0} dňami + + + pred mesiacom + + + pred {0} mesiacmi + + + pred rokom + + + pred {0} rokmi + + + {0} dní + + + {0} hodín + + + {0} milisekúnd + + + {0} minút + + + {0} sekúnd + + + 1 deň + + + 1 hodina + + + 1 milisekunda + + + 1 minúta + + + 1 sekunda + + + žiadny čas + + + {0} týždňov + + + 1 týždeň + + + o {0} dní + + + o {0} hodín + + + o {0} minút + + + o {0} mesiacov + + + o {0} sekúnd + + + o {0} rokov + + + teraz + + + zajtra + + + o hodinu + + + o minútu + + + o mesiac + + + o sekundu + + + o rok + + + pred {0} dňami + + + o {0} dni + + + pred {0} hodinami + + + o {0} hodiny + + + pred {0} minútami + + + o {0} minúty + + + pred {0} mesiacmi + + + o {0} mesiace + + + pred {0} sekundami + + + o {0} sekundy + + + pred {0} rokmi + + + o {0} roky + + + {0} dni + + + {0} hodiny + + + {0} milisekundy + + + {0} minúty + + + {0} sekundy + + + {0} týždne + + \ No newline at end of file