From 1d4035bf72830445fe0c56780dff88d59b42f8f1 Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Thu, 10 Apr 2014 19:45:04 -0400 Subject: [PATCH 01/10] Changed the NumberToWords Converter to find the right converter by the language Name aswell. This is needed for languages that can be ambiguous in Two Letter ISO Code (pt-BR, pt-PT both have 'pt' Two Letter ISO code). --- src/Humanizer.Tests/Humanizer.Tests.csproj | 1 + .../Localisation/NumerToWordsFactoryTests.cs | 33 +++++++++++++++++++ src/Humanizer/Humanizer.csproj | 1 + ...azilianPortugueseNumberToWordsConverter.cs | 12 +++++++ src/Humanizer/NumberToWordsExtension.cs | 8 +++-- 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs create mode 100644 src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index b36032eae..84a9146df 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -88,6 +88,7 @@ + diff --git a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs new file mode 100644 index 000000000..58c967a99 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace Humanizer.Tests.Localisation +{ + public class NumerToWordsFactoryTests + { + [Fact] + public void CanGetRFCStandardLanguageSpecificFactory() + { + + using (new AmbientCulture("pt-BR")) + { + string retorno = 1000000000.ToWords(); + Assert.NotEqual("one billion",retorno); + } + } + + [Fact] + public void CanGetTwoLetterISOLanguageSpecificFactory() + { + + using (new AmbientCulture("ar")) + { + string retorno = 1000000000.ToWords(); + Assert.NotEqual("one billion", retorno); + } + } + } +} diff --git a/src/Humanizer/Humanizer.csproj b/src/Humanizer/Humanizer.csproj index 42f8ae754..8bfdef92a 100644 --- a/src/Humanizer/Humanizer.csproj +++ b/src/Humanizer/Humanizer.csproj @@ -65,6 +65,7 @@ Humanizer.snk + diff --git a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs new file mode 100644 index 000000000..9236388e6 --- /dev/null +++ b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs @@ -0,0 +1,12 @@ +using System; + +namespace Humanizer.Localisation.NumberToWords +{ + internal class BrazilianPortugueseNumberToWordsConverter : DefaultNumberToWordsConverter + { + public override string Convert(int number) + { + return "not implemented"; + } + } +} \ No newline at end of file diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index 3c980fdf4..c9d979048 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -1,9 +1,6 @@ -using Humanizer.Localisation.NumberToWords; -using System; using System.Collections.Generic; using System.Globalization; -namespace Humanizer { /// /// Transform a number into words; e.g. 1 => one /// @@ -16,6 +13,7 @@ public static class NumberToWordsExtension { { "fa", () => new FarsiNumberToWordsConverter() }, { "es", () => new SpanishNumberToWordsConverter() }, { "pl", () => new PolishNumberToWordsConverter() } + { "pt-BR", () => new BrazilianPortugueseNumberToWordsConverter() }, }; /// @@ -43,6 +41,10 @@ private static INumberToWordsConverter Converter get { Func converterFactory; + + if (ConverterFactories.TryGetValue(CultureInfo.CurrentUICulture.Name, out converterFactory)) + return converterFactory(); + if (ConverterFactories.TryGetValue(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, out converterFactory)) return converterFactory(); From cb02f868ea773f1dd751c6b3fbd60aca3bb6d140 Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Thu, 10 Apr 2014 20:29:19 -0400 Subject: [PATCH 02/10] Updated the test to show the Converter did not get the default NumberToWordsConverter --- src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs index 58c967a99..182afa8b0 100644 --- a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs +++ b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs @@ -15,7 +15,7 @@ public void CanGetRFCStandardLanguageSpecificFactory() using (new AmbientCulture("pt-BR")) { string retorno = 1000000000.ToWords(); - Assert.NotEqual("one billion",retorno); + Assert.NotEqual("1000000000",retorno); } } @@ -26,7 +26,7 @@ public void CanGetTwoLetterISOLanguageSpecificFactory() using (new AmbientCulture("ar")) { string retorno = 1000000000.ToWords(); - Assert.NotEqual("one billion", retorno); + Assert.NotEqual("1000000000", retorno); } } } From ec3da202207659503ba3c20eccf184aff17ef2ad Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Thu, 10 Apr 2014 19:45:04 -0400 Subject: [PATCH 03/10] Changed the NumberToWords Converter to find the right converter by the language Name aswell. This is needed for languages that can be ambiguous in Two Letter ISO Code (pt-BR, pt-PT both have 'pt' Two Letter ISO code). --- .../Localisation/NumerToWordsFactoryTests.cs | 16 ++++++++++++++++ src/Humanizer/NumberToWordsExtension.cs | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs index 182afa8b0..2c59027d8 100644 --- a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs +++ b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs @@ -30,4 +30,20 @@ public void CanGetTwoLetterISOLanguageSpecificFactory() } } } +} + Assert.NotEqual("one billion",retorno); + } + } + + [Fact] + public void CanGetTwoLetterISOLanguageSpecificFactory() + { + + using (new AmbientCulture("ar")) + { + string retorno = 1000000000.ToWords(); + Assert.NotEqual("one billion", retorno); + } + } + } } diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index c9d979048..abe86c26f 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -12,8 +12,8 @@ public static class NumberToWordsExtension { { "ar", () => new ArabicNumberToWordsConverter() }, { "fa", () => new FarsiNumberToWordsConverter() }, { "es", () => new SpanishNumberToWordsConverter() }, - { "pl", () => new PolishNumberToWordsConverter() } - { "pt-BR", () => new BrazilianPortugueseNumberToWordsConverter() }, + { "pl", () => new PolishNumberToWordsConverter() }, + { "pt-BR", () => new BrazilianPortugueseNumberToWordsConverter() } }; /// From 865a77450dd40956ca5fce79d0cc3c979645fb67 Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Thu, 10 Apr 2014 20:06:02 -0400 Subject: [PATCH 04/10] release notes for Pull Request #174 --- release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release_notes.md b/release_notes.md index 314c35d10..a75c73fd2 100644 --- a/release_notes.md +++ b/release_notes.md @@ -4,6 +4,7 @@ ###v1.20.2 - 2014-04-11 - [#171](https://github.com/MehdiK/Humanizer/pull/171): T4-Template fix: Using EnglishNumberToWordsConverter instead of 'ToWords()' while dogfooding the template with the library. + - [#174](https://github.com/MehdiK/Humanizer/pull/174): Changed the NumberToWords Converter to find the right converter by the language Name as well. - [#165](https://github.com/MehdiK/Humanizer/pull/165): Added precision based `DateTime.Humanize` strategy - [#155](https://github.com/MehdiK/Humanizer/pull/155): French and Belgian French localisation - [#151](https://github.com/MehdiK/Humanizer/pull/151): Added Spanish ToWords Translations From d3e17d5575163f6867565965cff4473ec75e3a20 Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Thu, 10 Apr 2014 20:29:19 -0400 Subject: [PATCH 05/10] Updated the test to show the Converter did not get the default NumberToWordsConverter --- .../Localisation/NumerToWordsFactoryTests.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs index 2c59027d8..415141e35 100644 --- a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs +++ b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs @@ -29,11 +29,6 @@ public void CanGetTwoLetterISOLanguageSpecificFactory() Assert.NotEqual("1000000000", retorno); } } - } -} - Assert.NotEqual("one billion",retorno); - } - } [Fact] public void CanGetTwoLetterISOLanguageSpecificFactory() @@ -42,7 +37,7 @@ public void CanGetTwoLetterISOLanguageSpecificFactory() using (new AmbientCulture("ar")) { string retorno = 1000000000.ToWords(); - Assert.NotEqual("one billion", retorno); + Assert.NotEqual("1000000000", retorno); } } } From cc2ab95a87ff429731ccd6b6f0faaf2cb7f2aa5d Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Fri, 11 Apr 2014 07:19:00 -0400 Subject: [PATCH 06/10] Added an extra test to show it can correctly resolve pt-BR and pt-PT factories. Better NumerToWordsFactoryTests formatting. --- .../Localisation/NumerToWordsFactoryTests.cs | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs index 415141e35..cbf3f3fab 100644 --- a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs +++ b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs @@ -1,33 +1,49 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; +using Xunit; +using Xunit.Extensions; namespace Humanizer.Tests.Localisation { public class NumerToWordsFactoryTests { - [Fact] - public void CanGetRFCStandardLanguageSpecificFactory() + [Theory] + [InlineData("1000000000", 1000000000)] + public void CanGetTwoLetterISOLanguageSpecificFactory(string notExpected, int number) { + using (new AmbientCulture("ar")) + { + string result = number.ToWords(); + Assert.NotEqual(notExpected, result); + } + } + [Theory] + [InlineData("1000000000", 1000000000)] + public void CanGetRFCStandardLanguageSpecificFactory(string notExpected, int number) + { using (new AmbientCulture("pt-BR")) { - string retorno = 1000000000.ToWords(); - Assert.NotEqual("1000000000",retorno); + string result = number.ToWords(); + Assert.NotEqual(notExpected, result); } } - [Fact] - public void CanGetTwoLetterISOLanguageSpecificFactory() + [Theory] + [InlineData(1000000000)] + public void CanGetCorrectRFCStandardLanguageSpecificFactory(int number) { + string resultPtBR; + using (new AmbientCulture("pt-BR")) + { + resultPtBR = number.ToWords(); + } - using (new AmbientCulture("ar")) + string resultPtPT; + using (new AmbientCulture("pt-PT")) { - string retorno = 1000000000.ToWords(); - Assert.NotEqual("1000000000", retorno); + resultPtPT = number.ToWords(); } + + Assert.NotEqual(resultPtBR, resultPtPT); } [Fact] From 933d18313e96b029a668b2b1653b8bc5d8cb9411 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Fri, 11 Apr 2014 20:29:49 +0430 Subject: [PATCH 07/10] some tidyup --- src/Humanizer.Tests/Humanizer.Tests.csproj | 2 +- .../Localisation/NumberToWordsFactoryTests.cs | 46 ++++++++++++++ .../Localisation/NumerToWordsFactoryTests.cs | 60 ------------------- src/Humanizer/NumberToWordsExtension.cs | 4 ++ 4 files changed, 51 insertions(+), 61 deletions(-) create mode 100644 src/Humanizer.Tests/Localisation/NumberToWordsFactoryTests.cs delete mode 100644 src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 84a9146df..4a007008c 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -88,7 +88,7 @@ - + diff --git a/src/Humanizer.Tests/Localisation/NumberToWordsFactoryTests.cs b/src/Humanizer.Tests/Localisation/NumberToWordsFactoryTests.cs new file mode 100644 index 000000000..f97b7b668 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/NumberToWordsFactoryTests.cs @@ -0,0 +1,46 @@ +using Xunit; + +namespace Humanizer.Tests.Localisation +{ + public class NumberToWordsFactoryTests + { + [Fact] + public void CanGetTwoLetterIsoLanguageSpecificFactory() + { + using (new AmbientCulture("ar")) + { + string result = 1000000000.ToWords(); + Assert.NotEqual("1000000000", result); + } + } + + [Fact] + public void CanGetRfcStandardLanguageSpecificFactory() + { + using (new AmbientCulture("pt-BR")) + { + string result = 1000000000.ToWords(); + Assert.NotEqual("1000000000", result); + } + } + + [Fact] + public void CanGetCorrectRfcStandardLanguageSpecificFactory() + { + string resultPtBr; + const int number = 1000000000; + using (new AmbientCulture("pt-BR")) + { + resultPtBr = number.ToWords(); + } + + string resultPtPt; + using (new AmbientCulture("pt-PT")) + { + resultPtPt = number.ToWords(); + } + + Assert.NotEqual(resultPtBr, resultPtPt); + } + } +} diff --git a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs b/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs deleted file mode 100644 index cbf3f3fab..000000000 --- a/src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Xunit; -using Xunit.Extensions; - -namespace Humanizer.Tests.Localisation -{ - public class NumerToWordsFactoryTests - { - [Theory] - [InlineData("1000000000", 1000000000)] - public void CanGetTwoLetterISOLanguageSpecificFactory(string notExpected, int number) - { - using (new AmbientCulture("ar")) - { - string result = number.ToWords(); - Assert.NotEqual(notExpected, result); - } - } - - [Theory] - [InlineData("1000000000", 1000000000)] - public void CanGetRFCStandardLanguageSpecificFactory(string notExpected, int number) - { - using (new AmbientCulture("pt-BR")) - { - string result = number.ToWords(); - Assert.NotEqual(notExpected, result); - } - } - - [Theory] - [InlineData(1000000000)] - public void CanGetCorrectRFCStandardLanguageSpecificFactory(int number) - { - string resultPtBR; - using (new AmbientCulture("pt-BR")) - { - resultPtBR = number.ToWords(); - } - - string resultPtPT; - using (new AmbientCulture("pt-PT")) - { - resultPtPT = number.ToWords(); - } - - Assert.NotEqual(resultPtBR, resultPtPT); - } - - [Fact] - public void CanGetTwoLetterISOLanguageSpecificFactory() - { - - using (new AmbientCulture("ar")) - { - string retorno = 1000000000.ToWords(); - Assert.NotEqual("1000000000", retorno); - } - } - } -} diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index abe86c26f..371e33d6d 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -1,6 +1,10 @@ +using System; using System.Collections.Generic; using System.Globalization; +using Humanizer.Localisation.NumberToWords; +namespace Humanizer +{ /// /// Transform a number into words; e.g. 1 => one /// From 6a4e191642a11751d8a3114d928fe437586b7c0e Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Sat, 12 Apr 2014 00:51:40 -0400 Subject: [PATCH 08/10] Added pt-BR NumberToWords localisation --- src/Humanizer.Tests/Humanizer.Tests.csproj | 1 + .../Localisation/pt-BR/NumberToWordsTests.cs | 47 ++++++++++ ...azilianPortugueseNumberToWordsConverter.cs | 92 ++++++++++++++++++- 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/Humanizer.Tests/Localisation/pt-BR/NumberToWordsTests.cs diff --git a/src/Humanizer.Tests/Humanizer.Tests.csproj b/src/Humanizer.Tests/Humanizer.Tests.csproj index 4a007008c..0f2ef0d8e 100644 --- a/src/Humanizer.Tests/Humanizer.Tests.csproj +++ b/src/Humanizer.Tests/Humanizer.Tests.csproj @@ -92,6 +92,7 @@ + diff --git a/src/Humanizer.Tests/Localisation/pt-BR/NumberToWordsTests.cs b/src/Humanizer.Tests/Localisation/pt-BR/NumberToWordsTests.cs new file mode 100644 index 000000000..4ede90565 --- /dev/null +++ b/src/Humanizer.Tests/Localisation/pt-BR/NumberToWordsTests.cs @@ -0,0 +1,47 @@ +using Xunit; +using Xunit.Extensions; + +namespace Humanizer.Tests.Localisation.ptBR +{ + public class NumberToWordsTests : AmbientCulture + { + public NumberToWordsTests() : base("pt-BR") { } + + [Theory] + [InlineData(1, "um")] + [InlineData(10, "dez")] + [InlineData(11, "onze")] + [InlineData(122, "cento e vinte e dois")] + [InlineData(3501, "três mil quinhentos e um")] + [InlineData(100, "cem")] + [InlineData(1000, "mil")] + [InlineData(100000, "cem mil")] + [InlineData(1000000, "um milhão")] + [InlineData(10000000, "dez milhões")] + [InlineData(100000000, "cem milhões")] + [InlineData(1000000000, "um bilhão")] + [InlineData(111, "cento e onze")] + [InlineData(1111, "mil cento e onze")] + [InlineData(111111, "cento e onze mil cento e onze")] + [InlineData(1111111, "um milhão cento e onze mil cento e onze")] + [InlineData(11111111, "onze milhões cento e onze mil cento e onze")] + [InlineData(111111111, "cento e onze milhões cento e onze mil cento e onze")] + [InlineData(1111111111, "um bilhão cento e onze milhões cento e onze mil cento e onze")] + [InlineData(123, "cento e vinte e três")] + [InlineData(1234, "mil duzentos e trinta e quatro")] + [InlineData(8100, "oito mil e cem")] + [InlineData(12345, "doze mil trezentos e quarenta e cinco")] + [InlineData(123456, "cento e vinte e três mil quatrocentos e cinquenta e seis")] + [InlineData(1234567, "um milhão duzentos e trinta e quatro mil quinhentos e sessenta e sete")] + [InlineData(12345678, "doze milhões trezentos e quarenta e cinco mil seiscentos e setenta e oito")] + [InlineData(123456789, "cento e vinte e três milhões quatrocentos e cinquenta e seis mil setecentos e oitenta e nove")] + [InlineData(1234567890, "um bilhão duzentos e trinta e quatro milhões quinhentos e sessenta e sete mil oitocentos e noventa")] + [InlineData(1999, "mil novecentos e noventa e nove")] + [InlineData(2014, "dois mil e quatorze")] + [InlineData(2048, "dois mil e quarenta e oito")] + public void ToWordsPortuguese(int number, string expected) + { + Assert.Equal(expected, number.ToWords()); + } + } +} diff --git a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs index 9236388e6..b3567f40c 100644 --- a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs @@ -1,12 +1,100 @@ -using System; +using Humanizer.Localisation.NumberToWords; +using System; +using System.Collections.Generic; namespace Humanizer.Localisation.NumberToWords { internal class BrazilianPortugueseNumberToWordsConverter : DefaultNumberToWordsConverter { + private static readonly string[] portugueseUnitsMap = { "zero", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", "dezoito", "dezenove" }; + private static readonly string[] portugueseTensMap = { "zero", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa" }; + private static readonly string[] portugueseHundredsMap = { "zero", "cento", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos" }; + public override string Convert(int number) { - return "not implemented"; + if (number == 0) + return "zero"; + + if (number < 0) + return string.Format("menos {0}", Convert(Math.Abs(number))); + + var parts = new List(); + + if ((number / 1000000000) > 0) + { + if (number / 1000000000 > 2) + { + parts.Add(string.Format("{0} bilhões", Convert(number / 1000000000))); + } + else + { + parts.Add(string.Format("{0} bilhão", Convert(number / 1000000000))); + } + number %= 1000000000; + } + + if ((number / 1000000) > 0) + { + if (number / 1000000 > 2) + { + parts.Add(string.Format("{0} milhões", Convert(number / 1000000))); + } + else + { + parts.Add(string.Format("{0} milhão", Convert(number / 1000000))); + } + number %= 1000000; + } + + if ((number / 1000) > 0) + { + if (number / 1000 == 1) + parts.Add("mil"); + else + parts.Add(string.Format("{0} mil", Convert(number / 1000))); + + number %= 1000; + } + + if ((number / 100) > 0) + { + if (number == 100) + { + if (parts.Count > 0) + { + parts.Add("e cem"); + } + else + { + parts.Add("cem"); + } + } + else + { + parts.Add(portugueseHundredsMap[(number / 100)]); + } + + number %= 100; + } + + if (number > 0) + { + if (parts.Count != 0) + parts.Add("e"); + + if (number < 20) + parts.Add(portugueseUnitsMap[number]); + else + { + var lastPart = portugueseTensMap[number / 10]; + if ((number % 10) > 0) + lastPart += string.Format(" e {0}", portugueseUnitsMap[number % 10]); + + parts.Add(lastPart); + } + } + + return string.Join(" ", parts.ToArray()); } } } \ No newline at end of file From d345af428932f29568ed62a3d833079173f11af5 Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Sat, 12 Apr 2014 00:55:40 -0400 Subject: [PATCH 09/10] release notes added for PR #194 --- release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release_notes.md b/release_notes.md index a75c73fd2..f10692ce0 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,7 @@ ###In Development - [#186](https://github.com/Mehdik/Humanizer/pull/186): Refactored 'ToOrdinalWords` to use existing `NumberToWordsExtension` to prepare for Ordinal localization. + - [#194](https://github.com/MehdiK/Humanizer/pull/194): Added pt-BR NumberToWords localisation + [Commits](https://github.com/MehdiK/Humanizer/compare/v1.20.2...master) ###v1.20.2 - 2014-04-11 From 574a5313bd6c9bfbdb4c0da0a3746c9c0b9f3a90 Mon Sep 17 00:00:00 2001 From: Mahmoud Ali Date: Sat, 12 Apr 2014 00:57:08 -0400 Subject: [PATCH 10/10] removed closed PR #174 from release notes --- release_notes.md | 1 - 1 file changed, 1 deletion(-) diff --git a/release_notes.md b/release_notes.md index f10692ce0..fbf856b45 100644 --- a/release_notes.md +++ b/release_notes.md @@ -6,7 +6,6 @@ ###v1.20.2 - 2014-04-11 - [#171](https://github.com/MehdiK/Humanizer/pull/171): T4-Template fix: Using EnglishNumberToWordsConverter instead of 'ToWords()' while dogfooding the template with the library. - - [#174](https://github.com/MehdiK/Humanizer/pull/174): Changed the NumberToWords Converter to find the right converter by the language Name as well. - [#165](https://github.com/MehdiK/Humanizer/pull/165): Added precision based `DateTime.Humanize` strategy - [#155](https://github.com/MehdiK/Humanizer/pull/155): French and Belgian French localisation - [#151](https://github.com/MehdiK/Humanizer/pull/151): Added Spanish ToWords Translations