diff --git a/release_notes.md b/release_notes.md index 75fd863d6..8be84dad4 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,6 +1,7 @@ ###In Development - [#137](https://github.com/MehdiK/Humanizer/pull/137): Fixed grammar error in `nb-NO` resource file & added missing Norwegian resource strings (mainly `DateHumanize_*FromNow`) - [#135](https://github.com/MehdiK/Humanizer/pull/135): Added Swedish localization (strings, tests) + - [#140](https://github.com/MehdiK/Humanizer/pull/140): Added Polish localization (strings, formatter, tests) [Commits](https://github.com/MehdiK/Humanizer/compare/v1.17.1...master) diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 745a903d3..8320b7508 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -79,6 +79,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..fa95d690c 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() } + { "sk", () => new CzechSlovakPolishFormatter() }, + { "cs", () => new CzechSlovakPolishFormatter() }, + { "pl", () => new CzechSlovakPolishFormatter() } }; /// diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index eeebc22c6..9a25522ea 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -70,7 +70,7 @@ - + @@ -145,6 +145,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/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