From ee108b1062dd116c47bbe9b27146b45c7da439f4 Mon Sep 17 00:00:00 2001 From: Adriano Marcondes Machado Date: Mon, 6 Jan 2014 16:01:25 -0200 Subject: [PATCH 1/2] Added pt-BR language support. --- .../Localisation/ar/TimeSpanTests.cs | 3 +- .../Localisation/pt-BR/DateHumanizeTests.cs | 77 +++++++ .../Localisation/pt-BR/TimeSpanTests.cs | 95 +++++++++ src/Humanizer/Humanizer.csproj | 1 + src/Humanizer/Properties/Resources.pt-BR.resx | 198 ++++++++++++++++++ 5 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs create mode 100644 src/Humanizer.Tests/Localisation/pt-BR/TimeSpanTests.cs create mode 100644 src/Humanizer/Properties/Resources.pt-BR.resx diff --git a/src/Humanizer.Tests/Localisation/ar/TimeSpanTests.cs b/src/Humanizer.Tests/Localisation/ar/TimeSpanTests.cs index f86fbb301..b251674b3 100644 --- a/src/Humanizer.Tests/Localisation/ar/TimeSpanTests.cs +++ b/src/Humanizer.Tests/Localisation/ar/TimeSpanTests.cs @@ -1,11 +1,12 @@ using System; +using Humanizer.Tests; using Xunit; namespace Humanizer.Tests.Localisation.ar { public class TimeSpanHumanizeExtensionsTests : AmbientCulture { - public TimeSpanHumanizeExtensionsTests() : base("ar") { } + public TimeSpanHumanizeExtensionsTests() : base("ar") { } [Fact] public void OneWeek() diff --git a/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs new file mode 100644 index 000000000..a9a37eae6 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs @@ -0,0 +1,77 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.ptBR +{ + public class DateHumanizeTests : AmbientCulture + { + public DateHumanizeTests() : base("pt-BR") { } + + [Theory] + [InlineData(-10, "10 dias atrás")] + [InlineData(-3, "3 dias atrás")] + [InlineData(-2, "2 dias atrás")] + [InlineData(-1, "ontem")] + public void DaysAgo(int days, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + } + + [Theory] + [InlineData(-10, "10 horas atrás")] + [InlineData(-3, "3 horas atrás")] + [InlineData(-2, "2 horas atrás")] + [InlineData(-1, "uma hora atrás")] + public void HoursAgo(int hours, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + } + + [Theory] + [InlineData(-10, "10 minutos atrás")] + [InlineData(-3, "3 minutos atrás")] + [InlineData(-2, "2 minutos atrás")] + [InlineData(-1, "um minuto atrás")] + public void MinutesAgo(int minutes, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + } + + [Theory] + [InlineData(-10, "10 meses atrás")] + [InlineData(-3, "3 meses atrás")] + [InlineData(-2, "2 meses atrás")] + [InlineData(-1, "um mês atrás")] + public void MonthsAgo(int months, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + } + + [Theory] + [InlineData(-10, "10 segundos atrás")] + [InlineData(-3, "3 segundos atrás")] + [InlineData(-2, "2 segundos atrás")] + [InlineData(-1, "um segundo atrás")] + public void SecondsAgo(int seconds, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + } + + [Theory] + [InlineData(-10, "10 anos atrás")] + [InlineData(-3, "3 anos atrás")] + [InlineData(-2, "2 anos atrás")] + [InlineData(-1, "um ano atrás")] + public void YearsAgo(int years, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + } + + [Fact] + public void NotYet() + { + Assert.Equal("ainda não", DateTime.UtcNow.AddDays(1).Humanize()); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/pt-BR/TimeSpanTests.cs b/src/Humanizer.Tests/Localisation/pt-BR/TimeSpanTests.cs new file mode 100644 index 000000000..c41cb67f0 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/pt-BR/TimeSpanTests.cs @@ -0,0 +1,95 @@ +using System; +using Xunit; + +namespace Humanizer.Tests.Localisation.ptBR +{ + public class TimeSpanHumanizeExtensionsTests : AmbientCulture + { + public TimeSpanHumanizeExtensionsTests() : base("pt-BR") { } + + [Fact] + public void TwoWeeks() + { + Assert.Equal("2 semanas", TimeSpan.FromDays(14).Humanize()); + } + + [Fact] + public void OneWeek() + { + Assert.Equal("1 semana", TimeSpan.FromDays(7).Humanize()); + } + + [Fact] + public void SixDays() + { + Assert.Equal("6 dias", TimeSpan.FromDays(6).Humanize()); + } + + [Fact] + public void TwoDays() + { + Assert.Equal("2 dias", TimeSpan.FromDays(2).Humanize()); + } + + [Fact] + public void OneDay() + { + Assert.Equal("1 dia", TimeSpan.FromDays(1).Humanize()); + } + + [Fact] + public void TwoHours() + { + Assert.Equal("2 horas", TimeSpan.FromHours(2).Humanize()); + } + + [Fact] + public void OneHour() + { + Assert.Equal("1 hora", TimeSpan.FromHours(1).Humanize()); + } + + [Fact] + public void TwoMinutes() + { + Assert.Equal("2 minutos", TimeSpan.FromMinutes(2).Humanize()); + } + + [Fact] + public void OneMinute() + { + Assert.Equal("1 minuto", TimeSpan.FromMinutes(1).Humanize()); + } + + [Fact] + public void TwoSeconds() + { + Assert.Equal("2 segundos", TimeSpan.FromSeconds(2).Humanize()); + } + + [Fact] + public void OneSecond() + { + Assert.Equal("1 segundo", TimeSpan.FromSeconds(1).Humanize()); + } + + [Fact] + public void TwoMilliseconds() + { + Assert.Equal("2 milisegundos", TimeSpan.FromMilliseconds(2).Humanize()); + } + + [Fact] + public void OneMillisecond() + { + Assert.Equal("1 milisegundo", TimeSpan.FromMilliseconds(1).Humanize()); + } + + [Fact] + public void NoTime() + { + // This one doesn't make a lot of sense but ... w/e + Assert.Equal("sem horário", TimeSpan.Zero.Humanize()); + } + } +} \ No newline at end of file diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index e62b5864e..396bf7d5a 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -166,6 +166,7 @@ Designer + diff --git a/src/Humanizer/Properties/Resources.pt-BR.resx b/src/Humanizer/Properties/Resources.pt-BR.resx new file mode 100644 index 000000000..a27080345 --- /dev/null +++ b/src/Humanizer/Properties/Resources.pt-BR.resx @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + ainda não + + + um segundo atrás + + + {0} segundos atrás + + + um minuto atrás + + + {0} minutos atrás + + + uma hora atrás + + + {0} horas atrás + + + ontem + + + {0} dias atrás + + + um mês atrás + + + {0} meses atrás + + + um ano atrás + + + {0} anos atrás + + + {0} dias + + + {0} horas + + + {0} milisegundos + + + {0} minutos + + + {0} segundos + + + 1 dia + + + 1 hora + + + 1 milisegundo + + + 1 minuto + + + 1 segundo + + + sem horário + + + {0} semanas + + + 1 semana + + From 8bc88235a3b68219633b21b54e68075032ff57f1 Mon Sep 17 00:00:00 2001 From: Adriano Marcondes Machado Date: Mon, 6 Jan 2014 16:01:50 -0200 Subject: [PATCH 2/2] Fixed failing tests when computer locale is not en-US. --- src/Humanizer.Tests/{Localisation => }/AmbientCulture.cs | 2 +- src/Humanizer.Tests/Humanizer.Tests.csproj | 4 +++- src/Humanizer.Tests/TimeSpanHumanizeExtensionsTests.cs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) rename src/Humanizer.Tests/{Localisation => }/AmbientCulture.cs (93%) diff --git a/src/Humanizer.Tests/Localisation/AmbientCulture.cs b/src/Humanizer.Tests/AmbientCulture.cs similarity index 93% rename from src/Humanizer.Tests/Localisation/AmbientCulture.cs rename to src/Humanizer.Tests/AmbientCulture.cs index 5231a349d..e2383e00c 100644 --- a/src/Humanizer.Tests/Localisation/AmbientCulture.cs +++ b/src/Humanizer.Tests/AmbientCulture.cs @@ -2,7 +2,7 @@ using System.Globalization; using System.Threading; -namespace Humanizer.Tests.Localisation +namespace Humanizer.Tests { public class AmbientCulture : IDisposable { diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index aaa08543a..619f7f90b 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -75,6 +75,8 @@ + + @@ -88,7 +90,7 @@ - + diff --git a/src/Humanizer.Tests/TimeSpanHumanizeExtensionsTests.cs b/src/Humanizer.Tests/TimeSpanHumanizeExtensionsTests.cs index b2a7b4cec..4ad659607 100644 --- a/src/Humanizer.Tests/TimeSpanHumanizeExtensionsTests.cs +++ b/src/Humanizer.Tests/TimeSpanHumanizeExtensionsTests.cs @@ -3,8 +3,10 @@ namespace Humanizer.Tests { - public class TimeSpanHumanizeExtensionsTests + public class TimeSpanHumanizeExtensionsTests : AmbientCulture { + public TimeSpanHumanizeExtensionsTests() : base("en-US") { } + [Fact] public void TwoWeeks() {