From 19c280cccbae645dd0a97b498639b78a2b93d2a6 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Sat, 4 Jan 2014 21:05:41 -0800 Subject: [PATCH] Added missing spanish translations and tests Added missing tests for humanizing dates in spanish and fixed typo. Added tests and translations for timestamps --- src/Humanizer.Tests/Humanizer.Tests.csproj | 2 + .../Localisation/es/DateHumanizeTests.cs | 77 +++++++++++++++ .../Localisation/es/TimeSpanTests.cs | 95 +++++++++++++++++++ src/Humanizer/Properties/Resources.es.resx | 45 ++++++++- 4 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 src/Humanizer.Tests/Localisation/es/DateHumanizeTests.cs create mode 100644 src/Humanizer.Tests/Localisation/es/TimeSpanTests.cs diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index f7828b81a..9e9be0aa4 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -72,6 +72,8 @@ + + diff --git a/src/Humanizer.Tests/Localisation/es/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/es/DateHumanizeTests.cs new file mode 100644 index 000000000..529a376b6 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/es/DateHumanizeTests.cs @@ -0,0 +1,77 @@ +using System; +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.es +{ + public class DateHumanizeTests : AmbientCulture + { + public DateHumanizeTests() : base("es-ES") { } + + [Theory] + [InlineData(-10, "hace 10 días")] + [InlineData(-3, "hace 3 días")] + [InlineData(-2, "hace 2 días")] + [InlineData(-1, "ayer")] + public void DaysAgo(int days, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + } + + [Theory] + [InlineData(-10, "hace 10 horas")] + [InlineData(-3, "hace 3 horas")] + [InlineData(-2, "hace 2 horas")] + [InlineData(-1, "hace una hora")] + public void HoursAgo(int hours, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + } + + [Theory] + [InlineData(-10, "hace 10 minutos")] + [InlineData(-3, "hace 3 minutos")] + [InlineData(-2, "hace 2 minutos")] + [InlineData(-1, "hace un minuto")] + public void MinutesAgo(int minutes, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + } + + [Theory] + [InlineData(-10, "hace 10 meses")] + [InlineData(-3, "hace 3 meses")] + [InlineData(-2, "hace 2 meses")] + [InlineData(-1, "hace un mes")] + public void MonthsAgo(int months, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + } + + [Theory] + [InlineData(-10, "hace 10 segundos")] + [InlineData(-3, "hace 3 segundos")] + [InlineData(-2, "hace 2 segundos")] + [InlineData(-1, "hace un segundo")] + public void SecondsAgo(int seconds, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + } + + [Theory] + [InlineData(-10, "hace 10 años")] + [InlineData(-3, "hace 3 años")] + [InlineData(-2, "hace 2 años")] + [InlineData(-1, "hace un año")] + public void YearsAgo(int years, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + } + + [Fact] + public void NotYet() + { + Assert.Equal("aún no", DateTime.UtcNow.AddDays(1).Humanize()); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/es/TimeSpanTests.cs b/src/Humanizer.Tests/Localisation/es/TimeSpanTests.cs new file mode 100644 index 000000000..13fdbc58c --- /dev/null +++ b/src/Humanizer.Tests/Localisation/es/TimeSpanTests.cs @@ -0,0 +1,95 @@ +using System; +using Xunit; + +namespace Humanizer.Tests.Localisation.es +{ + public class TimeSpanHumanizeExtensionsTests : AmbientCulture + { + public TimeSpanHumanizeExtensionsTests() : base("es-ES") { } + + [Fact] + public void TwoWeeks() + { + Assert.Equal("2 semanas", TimeSpan.FromDays(14).Humanize()); + } + + [Fact] + public void OneWeek() + { + Assert.Equal("una semana", TimeSpan.FromDays(7).Humanize()); + } + + [Fact] + public void SixDays() + { + Assert.Equal("6 días", TimeSpan.FromDays(6).Humanize()); + } + + [Fact] + public void TwoDays() + { + Assert.Equal("2 días", TimeSpan.FromDays(2).Humanize()); + } + + [Fact] + public void OneDay() + { + Assert.Equal("un día", TimeSpan.FromDays(1).Humanize()); + } + + [Fact] + public void TwoHours() + { + Assert.Equal("2 horas", TimeSpan.FromHours(2).Humanize()); + } + + [Fact] + public void OneHour() + { + Assert.Equal("una hora", TimeSpan.FromHours(1).Humanize()); + } + + [Fact] + public void TwoMinutes() + { + Assert.Equal("2 minutos", TimeSpan.FromMinutes(2).Humanize()); + } + + [Fact] + public void OneMinute() + { + Assert.Equal("un minuto", TimeSpan.FromMinutes(1).Humanize()); + } + + [Fact] + public void TwoSeconds() + { + Assert.Equal("2 segundos", TimeSpan.FromSeconds(2).Humanize()); + } + + [Fact] + public void OneSecond() + { + Assert.Equal("un segundo", TimeSpan.FromSeconds(1).Humanize()); + } + + [Fact] + public void TwoMilliseconds() + { + Assert.Equal("2 milisegundos", TimeSpan.FromMilliseconds(2).Humanize()); + } + + [Fact] + public void OneMillisecond() + { + Assert.Equal("un milisegundo", TimeSpan.FromMilliseconds(1).Humanize()); + } + + [Fact] + public void NoTime() + { + // This one doesn't make a lot of sense but ... w/e + Assert.Equal("no hay tiempo", TimeSpan.Zero.Humanize()); + } + } +} \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.es.resx b/src/Humanizer/Properties/Resources.es.resx index b1fac1767..4d72c17ca 100644 --- a/src/Humanizer/Properties/Resources.es.resx +++ b/src/Humanizer/Properties/Resources.es.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - todavía no + aún no hace un segundo @@ -145,7 +145,7 @@ hace {0} días - hace una mes + hace un mes hace {0} meses @@ -156,4 +156,43 @@ hace {0} años - + + {0} días + + + {0} horas + + + {0} milisegundos + + + {0} minutos + + + {0} segundos + + + {0} semanas + + + un día + + + una hora + + + un milisegundo + + + un minuto + + + un segundo + + + una semana + + + no hay tiempo + + \ No newline at end of file