Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the NumberToWords Converter to find the right converter by the language Name as well #174

Closed
wants to merge 9 commits into from
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
###In Development
- [#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.

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.19.1...master)

Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="Localisation\da\DateHumanizeTests.cs" />
<Compile Include="Localisation\da\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\nb-NO\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\NumerToWordsFactoryTests.cs" />
<Compile Include="Localisation\pl\DateHumanizeTests.cs" />
<Compile Include="Localisation\pl\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\ru-RU\TimeSpanHumanizeTests.cs" />
Expand Down
33 changes: 33 additions & 0 deletions src/Humanizer.Tests/Localisation/NumerToWordsFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests to verify the logic works for pt-PT and pt-BR.

{
[Fact]
public void CanGetRFCStandardLanguageSpecificFactory()
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove redundant spaces.

using (new AmbientCulture("pt-BR"))
{
string retorno = 1000000000.ToWords();
Assert.NotEqual("1000000000",retorno);
}
}

[Fact]
public void CanGetTwoLetterISOLanguageSpecificFactory()
{

using (new AmbientCulture("ar"))
{
string retorno = 1000000000.ToWords();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also inline the assertions.

Assert.NotEqual("1000000000", retorno);
}
}
}
}
1 change: 1 addition & 0 deletions src/Humanizer/Humanizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<AssemblyOriginatorKeyFile>Humanizer.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="Localisation\NumberToWords\BrazilianPortugueseNumberToWordsConverter.cs" />
<Compile Include="Localisation\NumberToWords\DefaultNumberToWordsConverter.cs" />
<Compile Include="Localisation\NumberToWords\FarsiNumberToWordsConverter.cs" />
<Compile Include="Localisation\NumberToWords\ArabicNumberToWordsConverter.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Humanizer.Localisation.NumberToWords
{
internal class BrazilianPortugueseNumberToWordsConverter : DefaultNumberToWordsConverter
{
public override string Convert(int number)
{
return "not implemented";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will upset Brazilian users I believe. We need to implement this first.

}
}
}
7 changes: 6 additions & 1 deletion src/Humanizer/NumberToWordsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public static class NumberToWordsExtension
{
{ "en", () => new EnglishNumberToWordsConverter() },
{ "ar", () => new ArabicNumberToWordsConverter() },
{ "fa", () => new FarsiNumberToWordsConverter() }
{ "fa", () => new FarsiNumberToWordsConverter() },
{ "pt-BR", () => new BrazilianPortugueseNumberToWordsConverter() },
};

/// <summary>
Expand All @@ -33,6 +34,10 @@ private static INumberToWordsConverter Converter
get
{
Func<INumberToWordsConverter> converterFactory;

if (ConverterFactories.TryGetValue(CultureInfo.CurrentUICulture.Name, out converterFactory))
return converterFactory();

if (ConverterFactories.TryGetValue(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, out converterFactory))
return converterFactory();

Expand Down