-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from dmitry-gokun/master
Added optional Culture parameter to NumberToWords
- Loading branch information
Showing
24 changed files
with
273 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 14 additions & 27 deletions
41
src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,38 @@ | ||
namespace Humanizer.Localisation.NumberToWords | ||
using System.Globalization; | ||
|
||
namespace Humanizer.Localisation.NumberToWords | ||
{ | ||
internal class DefaultNumberToWordsConverter : INumberToWordsConverter | ||
internal class DefaultNumberToWordsConverter : GenderlessNumberToWordsConverter | ||
{ | ||
/// <summary> | ||
/// for Russian locale | ||
/// 1.ToWords(GrammaticalGender.Masculine) -> "один" | ||
/// 1.ToWords(GrammaticalGender.Feminine) -> "одна" | ||
/// </summary> | ||
/// <param name="number">Number to be turned to words</param> | ||
/// <param name="gender">The grammatical gender to use for output words</param> | ||
/// <returns></returns> | ||
public virtual string Convert(int number, GrammaticalGender gender) | ||
{ | ||
return Convert(number); | ||
} | ||
private readonly CultureInfo _culture; | ||
|
||
/// <summary> | ||
/// 3501.ToWords() -> "three thousand five hundred and one" | ||
/// Constructor. | ||
/// </summary> | ||
/// <param name="number">Number to be turned to words</param> | ||
/// <returns></returns> | ||
public virtual string Convert(int number) | ||
/// <param name="culture">Culture to use.</param> | ||
public DefaultNumberToWordsConverter(CultureInfo culture) | ||
{ | ||
return number.ToString(); | ||
_culture = culture; | ||
} | ||
|
||
/// <summary> | ||
/// for Brazilian Portuguese | ||
/// 1.ToOrdinalWords(GrammaticalGender.Masculine) -> "primeiro" | ||
/// 1.ToOrdinalWords(GrammaticalGender.Feminine) -> "primeira" | ||
/// 3501.ToWords() -> "three thousand five hundred and one" | ||
/// </summary> | ||
/// <param name="number">Number to be turned to words</param> | ||
/// <param name="gender">The grammatical gender to use for output words</param> | ||
/// <returns></returns> | ||
public virtual string ConvertToOrdinal(int number, GrammaticalGender gender) | ||
public override string Convert(int number) | ||
{ | ||
return ConvertToOrdinal(number); | ||
return number.ToString(_culture); | ||
} | ||
|
||
/// <summary> | ||
/// 1.ToOrdinalWords() -> "first" | ||
/// </summary> | ||
/// <param name="number">Number to be turned to ordinal words</param> | ||
/// <returns></returns> | ||
public virtual string ConvertToOrdinal(int number) | ||
public override string ConvertToOrdinal(int number) | ||
{ | ||
return number.ToString(); | ||
return number.ToString(_culture); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.