Implemented language support for humanize. #70
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.
Humanize now has language support on function
func Time(then time.Time) string
andfunc Ordinal(x int) string
. The language files are located on/locals
folder.Local files
JSON files are pretty easy to understand. I've written the English version and the Turkish version. Magnitudes and Indicators are pretty easy to understand.
Ordinals
The hardest part to understand is the ordinals array of arrays. Ordinals array first contains a rule. This rule's first array string starts with % character. After the % character, a number or . (dot) is placed. Dot means the rule applies for all numbers' ordinals. If a number is given, there must be another positive number smaller than first number after the rule identifier separated by a whitespace.
This is means, apply rule for all numbers which is equal to 5 modulo 10.. The second string on the
array must be the ordinal suffix.
But we know that also 11 = 1 mod 10 so the rules can be overwritten. If a rule matches the number, output is not returned. Parser continues to check other rules.
This ruleset first thinks ordinal for 11 must be st. After that it checks the second rule and overwrites st by th. Finally the extension rules are introduced. An extension rule is the boolean OR of the rules. Rule parser does not contain any AND or NOT gates because I did not know any other language that uses ordinals in format [number][ordinal suffix]. If they exist, please make an issue.
This is equal to saying [["%10 4", "th"], ["%10 5", "th"], ["%10 6", "th"]] in a more organized way.