From 4a31e75985bab82f415312e8c3af552a96a4d8bd Mon Sep 17 00:00:00 2001 From: Arne Noehre Date: Thu, 10 Apr 2014 20:01:09 +0200 Subject: [PATCH 1/5] T4 Template Fix / EnglishWordsConverter directly. GitHub Issue #169 --- src/Humanizer/FluentDate/In.SomeTimeFrom.tt | 3 ++- .../NumberToWords/EnglishNumberToWordsConverter.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Humanizer/FluentDate/In.SomeTimeFrom.tt b/src/Humanizer/FluentDate/In.SomeTimeFrom.tt index fad3f7551..a2f7731ed 100644 --- a/src/Humanizer/FluentDate/In.SomeTimeFrom.tt +++ b/src/Humanizer/FluentDate/In.SomeTimeFrom.tt @@ -28,10 +28,11 @@ namespace Humanizer var month = "Month" + plural; var year = "Year" + plural; + var converter= new Humanizer.Localisation.NumberToWords.EnglishNumberToWordsConverter(); #> /// /// - public static class <#= i.ToWords().Dehumanize() #> + public static class <#= converter.Convert(i).Dehumanize() #> { /// /// <#= i #> seconds from now diff --git a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs index c6a88f444..d1b157835 100644 --- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs @@ -3,7 +3,7 @@ namespace Humanizer.Localisation.NumberToWords { - internal class EnglishNumberToWordsConverter : INumberToWordsConverter + public class EnglishNumberToWordsConverter : INumberToWordsConverter { private static readonly string[] UnitsMap = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; private static readonly string[] TensMap = { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; From a302cb251f1b862ebb08e655cb1ff86e9375a2a4 Mon Sep 17 00:00:00 2001 From: Arne Noehre Date: Thu, 10 Apr 2014 20:29:50 +0200 Subject: [PATCH 2/5] Added PR to release notes. --- release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release_notes.md b/release_notes.md index d34c56089..2cae255c7 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,5 @@ ###In Development + - [#171](https://github.com/MehdiK/Humanizer/pull/171): T4-Template fix: Using EnglishNumberToWordsConverter instead of 'ToWords()' while dogfooding the template with the libary. [Commits](https://github.com/MehdiK/Humanizer/compare/v1.19.1...master) From 8eed198cfd4083682f59b7d26461be9e8579b24c Mon Sep 17 00:00:00 2001 From: Arne Noehre Date: Thu, 10 Apr 2014 21:07:11 +0200 Subject: [PATCH 3/5] Fixing tests failing on non-englich machines. --- src/Humanizer.Tests/DateHumanizeTests.cs | 7 ++++++- src/Humanizer.Tests/NumberToWordsTests.cs | 7 ++++++- src/Humanizer.Tests/ToQuantityTests.cs | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Humanizer.Tests/DateHumanizeTests.cs b/src/Humanizer.Tests/DateHumanizeTests.cs index 1eb3b3d50..f51c81cd1 100644 --- a/src/Humanizer.Tests/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/DateHumanizeTests.cs @@ -4,8 +4,13 @@ namespace Humanizer.Tests { - public class DateHumanizeTests + public class DateHumanizeTests : AmbientCulture { + public DateHumanizeTests() + : base("en-US") + { + } + [Theory] [InlineData(1, "one second ago")] [InlineData(10, "10 seconds ago")] diff --git a/src/Humanizer.Tests/NumberToWordsTests.cs b/src/Humanizer.Tests/NumberToWordsTests.cs index ea9468499..c0cd88527 100644 --- a/src/Humanizer.Tests/NumberToWordsTests.cs +++ b/src/Humanizer.Tests/NumberToWordsTests.cs @@ -3,8 +3,13 @@ namespace Humanizer.Tests { - public class NumberToWordsTests + public class NumberToWordsTests : AmbientCulture { + public NumberToWordsTests() + : base("en-US") + { + } + [InlineData(1, "one")] [InlineData(10, "ten")] [InlineData(11, "eleven")] diff --git a/src/Humanizer.Tests/ToQuantityTests.cs b/src/Humanizer.Tests/ToQuantityTests.cs index 1f1ac3085..9812b3d29 100644 --- a/src/Humanizer.Tests/ToQuantityTests.cs +++ b/src/Humanizer.Tests/ToQuantityTests.cs @@ -3,8 +3,13 @@ namespace Humanizer.Tests { - public class ToQuantityTests + public class ToQuantityTests : AmbientCulture { + public ToQuantityTests() + : base("en-US") + { + } + [Theory] [InlineData("case", 0, "0 cases")] [InlineData("case", 1, "1 case")] From 11bc665bf73e097e38993bf1ae03201076b89af1 Mon Sep 17 00:00:00 2001 From: Arne Noehre Date: Thu, 10 Apr 2014 21:09:04 +0200 Subject: [PATCH 4/5] Typo in release notes. --- release_notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release_notes.md b/release_notes.md index 2cae255c7..996175888 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,5 @@ ###In Development - - [#171](https://github.com/MehdiK/Humanizer/pull/171): T4-Template fix: Using EnglishNumberToWordsConverter instead of 'ToWords()' while dogfooding the template with the libary. + - [#171](https://github.com/MehdiK/Humanizer/pull/171): T4-Template fix: Using EnglishNumberToWordsConverter instead of 'ToWords()' while dogfooding the template with the library. [Commits](https://github.com/MehdiK/Humanizer/compare/v1.19.1...master) From c8420300b498b94fffb22ed3be211d0408a69bab Mon Sep 17 00:00:00 2001 From: Arne Noehre Date: Thu, 10 Apr 2014 21:19:57 +0200 Subject: [PATCH 5/5] API aprroval test fix after making 'EnglishNumberToWordsConverter' public. --- .../PublicApiApprovalTest.approve_public_api.approved.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt index 2b662786b..5ac70bb3c 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt @@ -163,6 +163,13 @@ public interface IFormatter string TimeSpanHumanize_Zero(); } +public class EnglishNumberToWordsConverter +{ + public EnglishNumberToWordsConverter() { } + public string Convert(int number) { } + public string ConvertToOrdinal(int number) { } +} + public interface INumberToWordsConverter { string Convert(int number);