-
Notifications
You must be signed in to change notification settings - Fork 966
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
Added optional Culture parameter to NumberToWords #300
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
530b2f5
Added option Culture parameter to DateTime.Humanize
adea66c
Fixed formatting
3dde23d
Reverted changes to DateHumanize (testing with both implicit & explic…
abbc23e
Added a test for getting culture-specific resource with explicitly sp…
0788a38
Fixed method's comment
ed4121c
Only using optional "Culture" parameter for public methods
1f8ad39
+ unit tests for DateTime.Humanize with explicit culure
3bb7fec
Updated readme to reflect new "culture" parameter for DateTime.Humanize
464e7b4
Updated release_notes to reflect new "culture" parameter for DateTime…
70f8f72
Added optional Culture parameter to TimeSpan.Humanize
c8bcd87
1) Made Date/Time formatters to own "culture";
385164d
Merge remote-tracking branch 'remotes/upstream/master'
2390f50
NumberToWords: added support for the explicit culture
1e343d5
Fixed NumberToWords sample
3d43f8e
Using real "Culture" object with NumberToWords converters
4d4270c
Small fixes during code review
7ccfd20
Fixed comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 sealed class DefaultNumberToWordsConverter : GenderlessNumberToWordsConverter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you make this class sealed? P.S. In fact I've never found a legitimate case to create a sealed class. |
||
{ | ||
/// <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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example is not correct, either it should be
new CultureInfo("en")
or the result"одинадцать"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, i've fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
С двумя "н"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hazzik as i said, i've fixed sample. and there is no typo you mentioned. in fact, it only existed in @mexx 's comment :)