From dc2920e46dac1036cbbe2173aeb3a6bd2661f296 Mon Sep 17 00:00:00 2001 From: Marcin Nowacki Date: Wed, 9 Apr 2014 14:46:51 +0200 Subject: [PATCH 1/4] Polish localization (strings, formatter, tests) --- src/Humanizer.Tests/Humanizer.Tests.csproj | 2 + .../Localisation/pl/DateHumanizeTests.cs | 168 ++++++++++ .../Localisation/pl/TimeSpanHumanizeTests.cs | 90 ++++++ src/Humanizer/Configuration/Configurator.cs | 7 +- src/Humanizer/Humanizer.csproj | 4 + src/Humanizer/Localisation/PolishFormatter.cs | 20 ++ src/Humanizer/Properties/Resources.pl.resx | 288 ++++++++++++++++++ 7 files changed, 576 insertions(+), 3 deletions(-) create mode 100644 src/Humanizer.Tests/Localisation/pl/DateHumanizeTests.cs create mode 100644 src/Humanizer.Tests/Localisation/pl/TimeSpanHumanizeTests.cs create mode 100644 src/Humanizer/Localisation/PolishFormatter.cs create mode 100644 src/Humanizer/Properties/Resources.pl.resx diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 444ac46d6..53df8c0c5 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -78,6 +78,8 @@ + + diff --git a/src/Humanizer.Tests/Localisation/pl/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/pl/DateHumanizeTests.cs new file mode 100644 index 000000000..0ca929fcb --- /dev/null +++ b/src/Humanizer.Tests/Localisation/pl/DateHumanizeTests.cs @@ -0,0 +1,168 @@ +using Humanizer.Localisation; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.pl +{ + public class DateHumanizeTests : AmbientCulture + { + public DateHumanizeTests() + : base("pl") + { + } + + [Theory] + [InlineData(1, "za sekundę")] + [InlineData(2, "za 2 sekundy")] + [InlineData(3, "za 3 sekundy")] + [InlineData(4, "za 4 sekundy")] + [InlineData(5, "za 5 sekund")] + [InlineData(6, "za 6 sekund")] + [InlineData(10, "za 10 sekund")] + public void SecondsFromNow(int seconds, string expected) + { + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); + } + + [Theory] + [InlineData(1, "za minutę")] + [InlineData(2, "za 2 minuty")] + [InlineData(3, "za 3 minuty")] + [InlineData(4, "za 4 minuty")] + [InlineData(5, "za 5 minut")] + [InlineData(6, "za 6 minut")] + [InlineData(10, "za 10 minut")] + public void MinutesFromNow(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); + } + + [Theory] + [InlineData(1, "za godzinę")] + [InlineData(2, "za 2 godziny")] + [InlineData(3, "za 3 godziny")] + [InlineData(4, "za 4 godziny")] + [InlineData(5, "za 5 godzin")] + [InlineData(6, "za 6 godzin")] + [InlineData(10, "za 10 godzin")] + public void HoursFromNow(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); + } + + [Theory] + [InlineData(1, "jutro")] + [InlineData(2, "za 2 dni")] + [InlineData(3, "za 3 dni")] + [InlineData(4, "za 4 dni")] + [InlineData(5, "za 5 dni")] + [InlineData(6, "za 6 dni")] + [InlineData(10, "za 10 dni")] + public void DayFromNow(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); + } + + [Theory] + [InlineData(1, "za miesiąc")] + [InlineData(2, "za 2 miesiące")] + [InlineData(3, "za 3 miesiące")] + [InlineData(4, "za 4 miesiące")] + [InlineData(5, "za 5 miesięcy")] + [InlineData(6, "za 6 miesięcy")] + [InlineData(10, "za 10 miesięcy")] + public void MonthsFromNow(int months, string expected) + { + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); + } + + [Theory] + [InlineData(1, "za rok")] + [InlineData(2, "za 2 lata")] + [InlineData(3, "za 3 lata")] + [InlineData(4, "za 4 lata")] + [InlineData(5, "za 5 lat")] + [InlineData(6, "za 6 lat")] + [InlineData(10, "za 10 lat")] + public void YearsFromNow(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); + } + + [Theory] + [InlineData(1, "przed sekundą")] + [InlineData(2, "przed 2 sekundami")] + [InlineData(3, "przed 3 sekundami")] + [InlineData(4, "przed 4 sekundami")] + [InlineData(5, "przed 5 sekundami")] + [InlineData(6, "przed 6 sekundami")] + [InlineData(10, "przed 10 sekundami")] + public void SecondsAgo(int seconds, string expected) + { + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); + } + + [Theory] + [InlineData(1, "przed minutą")] + [InlineData(2, "przed 2 minutami")] + [InlineData(3, "przed 3 minutami")] + [InlineData(4, "przed 4 minutami")] + [InlineData(5, "przed 5 minutami")] + [InlineData(6, "przed 6 minutami")] + [InlineData(10, "przed 10 minutami")] + public void MinutesAgo(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); + } + + [Theory] + [InlineData(1, "przed godziną")] + [InlineData(2, "przed 2 godzinami")] + [InlineData(3, "przed 3 godzinami")] + [InlineData(4, "przed 4 godzinami")] + [InlineData(5, "przed 5 godzinami")] + [InlineData(6, "przed 6 godzinami")] + [InlineData(10, "przed 10 godzinami")] + public void HoursAgo(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); + } + + [Theory] + [InlineData(1, "wczoraj")] + [InlineData(2, "przed 2 dniami")] + [InlineData(3, "przed 3 dniami")] + [InlineData(4, "przed 4 dniami")] + [InlineData(9, "przed 9 dniami")] + [InlineData(10, "przed 10 dniami")] + public void DayAgo(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); + } + + [Theory] + [InlineData(1, "przed miesiącem")] + [InlineData(2, "przed 2 miesiącami")] + [InlineData(3, "przed 3 miesiącami")] + [InlineData(4, "przed 4 miesiącami")] + [InlineData(5, "przed 5 miesiącami")] + [InlineData(6, "przed 6 miesiącami")] + [InlineData(10, "przed 10 miesiącami")] + public void MonthsAgo(int months, string expected) + { + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); + } + + [Theory] + [InlineData(1, "przed rokiem")] + [InlineData(2, "przed 2 laty")] + [InlineData(3, "przed 3 laty")] + [InlineData(4, "przed 4 laty")] + [InlineData(5, "przed 5 laty")] + [InlineData(6, "przed 6 laty")] + [InlineData(10, "przed 10 laty")] + public void YearsAgo(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/pl/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests/Localisation/pl/TimeSpanHumanizeTests.cs new file mode 100644 index 000000000..d535fe868 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/pl/TimeSpanHumanizeTests.cs @@ -0,0 +1,90 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.pl +{ + public class TimeSpanHumanizeTests : AmbientCulture + { + public TimeSpanHumanizeTests() + : base("pl") + { + } + + [Theory] + [InlineData(1, "1 milisekunda")] + [InlineData(2, "2 milisekundy")] + [InlineData(3, "3 milisekundy")] + [InlineData(4, "4 milisekundy")] + [InlineData(5, "5 milisekund")] + [InlineData(6, "6 milisekund")] + [InlineData(10, "10 milisekund")] + public void Milliseconds(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 sekund")] + [InlineData(6, "6 sekund")] + [InlineData(10, "10 sekund")] + public void Seconds(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromSeconds(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 minuta")] + [InlineData(2, "2 minuty")] + [InlineData(3, "3 minuty")] + [InlineData(4, "4 minuty")] + [InlineData(5, "5 minut")] + [InlineData(6, "6 minut")] + [InlineData(10, "10 minut")] + public void Minutes(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromMinutes(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 godzina")] + [InlineData(2, "2 godziny")] + [InlineData(3, "3 godziny")] + [InlineData(4, "4 godziny")] + [InlineData(5, "5 godzin")] + [InlineData(6, "6 godzin")] + [InlineData(10, "10 godzin")] + public void Hours(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromHours(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 dzień")] + [InlineData(2, "2 dni")] + [InlineData(3, "3 dni")] + [InlineData(4, "4 dni")] + [InlineData(5, "5 dni")] + [InlineData(6, "6 dni")] + public void Days(int number, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(number).Humanize()); + } + + [Theory] + [InlineData(1, "1 tydzień")] + [InlineData(2, "2 tygodnie")] + [InlineData(3, "3 tygodnie")] + [InlineData(4, "4 tygodnie")] + [InlineData(5, "5 tygodni")] + [InlineData(6, "6 tygodni")] + 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 2eae49b54..90bb71b53 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -1,7 +1,7 @@ +using Humanizer.Localisation; using System; using System.Collections.Generic; using System.Globalization; -using Humanizer.Localisation; namespace Humanizer.Configuration { @@ -10,14 +10,15 @@ namespace Humanizer.Configuration /// public static class Configurator { - private static readonly IDictionary> FormatterFactories = + private static readonly IDictionary> FormatterFactories = new Dictionary>(StringComparer.OrdinalIgnoreCase) { { "ro", () => new RomanianFormatter() }, { "ru", () => new RussianFormatter() }, { "ar", () => new ArabicFormatter() }, { "sk", () => new CzechSlovakFormatter() }, - { "cs", () => new CzechSlovakFormatter() } + { "cs", () => new CzechSlovakFormatter() }, + { "pl", () => new PolishFormatter() } }; /// diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index d9f49bf8b..2dcc22caa 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -71,6 +71,7 @@ + @@ -145,6 +146,9 @@ + + Designer + diff --git a/src/Humanizer/Localisation/PolishFormatter.cs b/src/Humanizer/Localisation/PolishFormatter.cs new file mode 100644 index 000000000..3b540dbee --- /dev/null +++ b/src/Humanizer/Localisation/PolishFormatter.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Humanizer.Localisation +{ + internal class PolishFormatter : 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.pl.resx b/src/Humanizer/Properties/Resources.pl.resx new file mode 100644 index 000000000..44db8f0cd --- /dev/null +++ b/src/Humanizer/Properties/Resources.pl.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 + + + przed sekundą + + + przed {0} sekundami + + + przed minutą + + + przed {0} minutami + + + przed godziną + + + przed {0} godzinami + + + wczoraj + + + przed {0} dniami + + + przed miesiącem + + + przed {0} miesiącami + + + przed rokiem + + + przed {0} laty + + + {0} dni + + + {0} godzin + + + {0} milisekund + + + {0} minut + + + {0} sekund + + + 1 dzień + + + 1 godzina + + + 1 milisekunda + + + 1 minuta + + + 1 sekunda + + + brak czasu + + + {0} tygodni + + + 1 tydzień + + + za {0} dni + + + za {0} godzin + + + za {0} minut + + + za {0} miesięcy + + + za {0} sekund + + + za {0} lat + + + teraz + + + jutro + + + za godzinę + + + za minutę + + + za miesiąc + + + za sekundę + + + za rok + + + przed {0} dniami + + + za {0} dni + + + przed {0} godzinami + + + za {0} godziny + + + przed {0} minutami + + + za {0} minuty + + + przed {0} miesiącami + + + za {0} miesiące + + + przed {0} sekundami + + + za {0} sekundy + + + przed {0} laty + + + za {0} lata + + + {0} dni + + + {0} godziny + + + {0} milisekundy + + + {0} minuty + + + {0} sekundy + + + {0} tygodnie + + \ No newline at end of file From 8aafc81a58144adeba10720413d3d4594ce5a048 Mon Sep 17 00:00:00 2001 From: Marcin Nowacki Date: Wed, 9 Apr 2014 15:01:23 +0200 Subject: [PATCH 2/4] No Designers for the resx files --- src/Humanizer/Humanizer.csproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 2dcc22caa..c3347de62 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -146,9 +146,7 @@ - - Designer - + From 5f6c0d7b9ed697f1122e0cb73fc7e356a5bb823e Mon Sep 17 00:00:00 2001 From: Marcin Nowacki Date: Wed, 9 Apr 2014 15:18:43 +0200 Subject: [PATCH 3/4] Polish as part of Czech & Slovak formatter. --- src/Humanizer/Configuration/Configurator.cs | 6 +++--- src/Humanizer/Humanizer.csproj | 3 +-- ...atter.cs => CzechSlovakPolishFormatter.cs} | 2 +- src/Humanizer/Localisation/PolishFormatter.cs | 20 ------------------- 4 files changed, 5 insertions(+), 26 deletions(-) rename src/Humanizer/Localisation/{CzechSlovakFormatter.cs => CzechSlovakPolishFormatter.cs} (84%) delete mode 100644 src/Humanizer/Localisation/PolishFormatter.cs diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index 90bb71b53..fa95d690c 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -16,9 +16,9 @@ public static class Configurator { "ro", () => new RomanianFormatter() }, { "ru", () => new RussianFormatter() }, { "ar", () => new ArabicFormatter() }, - { "sk", () => new CzechSlovakFormatter() }, - { "cs", () => new CzechSlovakFormatter() }, - { "pl", () => new PolishFormatter() } + { "sk", () => new CzechSlovakPolishFormatter() }, + { "cs", () => new CzechSlovakPolishFormatter() }, + { "pl", () => new CzechSlovakPolishFormatter() } }; /// diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index c3347de62..1d9ce37ea 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -70,8 +70,7 @@ - - + diff --git a/src/Humanizer/Localisation/CzechSlovakFormatter.cs b/src/Humanizer/Localisation/CzechSlovakPolishFormatter.cs similarity index 84% rename from src/Humanizer/Localisation/CzechSlovakFormatter.cs rename to src/Humanizer/Localisation/CzechSlovakPolishFormatter.cs index 4e5471312..17f6b348a 100644 --- a/src/Humanizer/Localisation/CzechSlovakFormatter.cs +++ b/src/Humanizer/Localisation/CzechSlovakPolishFormatter.cs @@ -1,6 +1,6 @@ namespace Humanizer.Localisation { - internal class CzechSlovakFormatter : DefaultFormatter + internal class CzechSlovakPolishFormatter : DefaultFormatter { private const string PaucalPostfix = "_Paucal"; diff --git a/src/Humanizer/Localisation/PolishFormatter.cs b/src/Humanizer/Localisation/PolishFormatter.cs deleted file mode 100644 index 3b540dbee..000000000 --- a/src/Humanizer/Localisation/PolishFormatter.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Humanizer.Localisation -{ - internal class PolishFormatter : DefaultFormatter - { - private const string PaucalPostfix = "_Paucal"; - - protected override string GetResourceKey(string resourceKey, int number) - { - if (number > 1 && number < 5) - return resourceKey + PaucalPostfix; - - return resourceKey; - } - } -} From 6f40d682e02db30406d1341d309a152be5d0c18d Mon Sep 17 00:00:00 2001 From: Marcin Nowacki Date: Wed, 9 Apr 2014 15:19:49 +0200 Subject: [PATCH 4/4] Added PR to the release notes --- release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release_notes.md b/release_notes.md index 3bc2f4b6d..f83fd3790 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,7 @@ ###In Development +- [#140](https://github.com/MehdiK/Humanizer/pull/140): Polish localization (strings, formatter, tests) + [Commits](https://github.com/MehdiK/Humanizer/compare/v1.17.1...master) ###v1.17.1 - 2014-04-06