Skip to content

Commit

Permalink
Merge pull request #1 from Humanizr/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
mr-aboutin authored Sep 28, 2020
2 parents fca597a + 6832282 commit 5de22ed
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Here is a checklist you should tick through before submitting a pull request:
- [ ] Implementation is clean
- [ ] Code adheres to the existing coding standards; e.g. no curlies for one-line blocks, no redundant empty lines between methods or code blocks, spaces rather than tabs, etc.
- [ ] No ReSharper warnings
- [ ] No Code Analysis warnings
- [ ] There is proper unit test coverage
- [ ] If the code is copied from StackOverflow (or a blog or OSS) full disclosure is included. That includes required license files and/or file headers explaining where the code came from with proper attribution
- [ ] There are very few or no comments (because comments shouldn't be needed if you write clean code)
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ Normally you would call `Singularize` on a plural word but if you're unsure abou
The overload of `Singularize` with `plurality` argument is obsolete and was removed in version 2.0.

## <a id="adding-words">Adding Words</a>
Sometimes, you may need to add a rule from the singularization/pluralization vocabulary (the examples below are already in the `DefaultVocabluary` used by `Inflector`):
Sometimes, you may need to add a rule from the singularization/pluralization vocabulary (the examples below are already in the `DefaultVocabulary` used by `Inflector`):

```C#
// Adds a word to the vocabulary which cannot easily be pluralized/singularized by RegEx.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Humanizer.Localisation;

using Xunit;

namespace Humanizer.Tests.Localisation.frBE
Expand All @@ -9,13 +11,13 @@ public class TimeSpanHumanizeTests

[Theory]
[Trait("Translation", "Google")]
[InlineData(366, "1 année")]
[InlineData(366, "1 an")]
[InlineData(731, "2 ans")]
[InlineData(1096, "3 ans")]
[InlineData(4018, "11 ans")]
public void Years(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: TimeUnit.Year));
}

[Theory]
Expand All @@ -26,7 +28,7 @@ public void Years(int days, string expected)
[InlineData(335, "11 mois")]
public void Months(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: TimeUnit.Year));
}

[Theory]
Expand Down Expand Up @@ -83,20 +85,28 @@ public void Milliseconds(int ms, string expected)
Assert.Equal(expected, actual);
}

[Fact]
public void NoTime()
[Theory]
[InlineData(TimeUnit.Year, "0 an")]
[InlineData(TimeUnit.Month, "0 mois")]
[InlineData(TimeUnit.Week, "0 semaine")]
[InlineData(TimeUnit.Day, "0 jour")]
[InlineData(TimeUnit.Hour, "0 heure")]
[InlineData(TimeUnit.Minute, "0 minute")]
[InlineData(TimeUnit.Second, "0 seconde")]
[InlineData(TimeUnit.Millisecond, "0 milliseconde")]
public void NoTime(TimeUnit minUnit, string expected)
{
var noTime = TimeSpan.Zero;
var actual = noTime.Humanize();
Assert.Equal("0 millisecondes", actual);
var actual = noTime.Humanize(minUnit: minUnit);
Assert.Equal(expected, actual);
}

[Fact]
public void NoTimeToWords()
{
var noTime = TimeSpan.Zero;
var actual = noTime.Humanize(toWords: true);
Assert.Equal("pas de temps", actual);
Assert.Equal("temps nul", actual);
}
}
}
30 changes: 20 additions & 10 deletions src/Humanizer.Tests.Shared/Localisation/fr/TimeSpanHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Humanizer.Localisation;

using Xunit;

namespace Humanizer.Tests.Localisation.fr
Expand All @@ -7,15 +9,15 @@ namespace Humanizer.Tests.Localisation.fr
public class TimeSpanHumanizeTests
{

[InlineData(366, "1 année")]
[Theory]
[Trait("Translation", "Google")]
[InlineData(366, "1 an")]
[InlineData(731, "2 ans")]
[InlineData(1096, "3 ans")]
[InlineData(4018, "11 ans")]
[Theory]
[Trait("Translation", "Google")]
public void Years(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: TimeUnit.Year));
}

[Theory]
Expand All @@ -26,7 +28,7 @@ public void Years(int days, string expected)
[InlineData(335, "11 mois")]
public void Months(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: TimeUnit.Year));
}

[Theory]
Expand Down Expand Up @@ -83,20 +85,28 @@ public void Milliseconds(int ms, string expected)
Assert.Equal(expected, actual);
}

[Fact]
public void NoTime()
[Theory]
[InlineData(TimeUnit.Year, "0 an")]
[InlineData(TimeUnit.Month, "0 mois")]
[InlineData(TimeUnit.Week, "0 semaine")]
[InlineData(TimeUnit.Day, "0 jour")]
[InlineData(TimeUnit.Hour, "0 heure")]
[InlineData(TimeUnit.Minute, "0 minute")]
[InlineData(TimeUnit.Second, "0 seconde")]
[InlineData(TimeUnit.Millisecond, "0 milliseconde")]
public void NoTime(TimeUnit minUnit, string expected)
{
var noTime = TimeSpan.Zero;
var actual = noTime.Humanize();
Assert.Equal("0 millisecondes", actual);
var actual = noTime.Humanize(minUnit: minUnit);
Assert.Equal(expected, actual);
}

[Fact]
public void NoTimeToWords()
{
var noTime = TimeSpan.Zero;
var actual = noTime.Humanize(toWords: true);
Assert.Equal("pas de temps", actual);
Assert.Equal("temps nul", actual);
}
}
}
5 changes: 5 additions & 0 deletions src/Humanizer/Localisation/Formatters/FrenchFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ protected override string GetResourceKey(string resourceKey, int number)
return resourceKey + DualPostfix;
}

if (number == 0 && resourceKey.StartsWith("TimeSpanHumanize_Multiple"))
{
return resourceKey + "_Singular";
}

return resourceKey;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Humanizer/Properties/Resources.fr-BE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<value>1 semaine</value>
</data>
<data name="TimeSpanHumanize_Zero" xml:space="preserve">
<value>pas de temps</value>
<value>temps nul</value>
</data>
<data name="TimeSpanHumanize_MultipleMonths" xml:space="preserve">
<value>{0} mois</value>
Expand All @@ -241,7 +241,7 @@
<value>1 mois</value>
</data>
<data name="TimeSpanHumanize_SingleYear" xml:space="preserve">
<value>1 année</value>
<value>1 an</value>
</data>
<data name="DateHumanize_MultipleDaysAgo_Dual" xml:space="preserve">
<value>avant-hier</value>
Expand Down
28 changes: 26 additions & 2 deletions src/Humanizer/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<value>1 semaine</value>
</data>
<data name="TimeSpanHumanize_Zero" xml:space="preserve">
<value>pas de temps</value>
<value>temps nul</value>
</data>
<data name="DateHumanize_Never" xml:space="preserve">
<value>jamais</value>
Expand All @@ -244,12 +244,36 @@
<value>1 mois</value>
</data>
<data name="TimeSpanHumanize_SingleYear" xml:space="preserve">
<value>1 année</value>
<value>1 an</value>
</data>
<data name="DateHumanize_MultipleDaysAgo_Dual" xml:space="preserve">
<value>avant-hier</value>
</data>
<data name="DateHumanize_MultipleDaysFromNow_Dual" xml:space="preserve">
<value>après-demain</value>
</data>
<data name="TimeSpanHumanize_MultipleYears_Singular" xml:space="preserve">
<value>{0} an</value>
</data>
<data name="TimeSpanHumanize_MultipleMonths_Singular" xml:space="preserve">
<value>{0} mois</value>
</data>
<data name="TimeSpanHumanize_MultipleWeeks_Singular" xml:space="preserve">
<value>{0} semaine</value>
</data>
<data name="TimeSpanHumanize_MultipleDays_Singular" xml:space="preserve">
<value>{0} jour</value>
</data>
<data name="TimeSpanHumanize_MultipleHours_Singular" xml:space="preserve">
<value>{0} heure</value>
</data>
<data name="TimeSpanHumanize_MultipleMinutes_Singular" xml:space="preserve">
<value>{0} minute</value>
</data>
<data name="TimeSpanHumanize_MultipleSeconds_Singular" xml:space="preserve">
<value>{0} seconde</value>
</data>
<data name="TimeSpanHumanize_MultipleMilliseconds_Singular" xml:space="preserve">
<value>{0} milliseconde</value>
</data>
</root>

0 comments on commit 5de22ed

Please sign in to comment.