-
Notifications
You must be signed in to change notification settings - Fork 233
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
Preliminary i18n support #13
base: master
Are you sure you want to change the base?
Conversation
// commas after every three orders of magnitude. | ||
// | ||
// e.g. Comma(834142) -> 834,142 | ||
func (h *EnglishHumanizer) Comma(v int64) string { |
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.
Of course, the choice of a comma is English-centric. The more general concept is the "decimal mark" or "decimal separator". Many locales use a period instead. From there it gets even weirder.
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.
IMHO, not breaking compatibility is critical. But we could add i18n-friendly func aliases :
func (h *EnglishHumanizer) Comma(v int64) string {
return h.DecimalSeparator(v)
}
func (h *EnglishHumanizer) DecimalSeparator(v int64) string {
Then you'd also need specialized code for Indian commas which starts
getting weird at lakh and then gets even weirder at maha-sankh just because
why not (unless you're using the vedic system or someone just disagrees
with you). This is just a counter example I've had to deal with directly.
Who knows what other people do.
Ideally there'd be language and culture specific time groupings as well
(which would imply different word ordering). The code makes it not too bad
to do that in your own code, but having some of those canned would lead to
an endless stream of regional preferences. I probably should've just stuck
with the SI stuff. :)
…On Thu, Mar 2, 2017 at 3:24 PM Jean-François Bustarret < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In comma.go
<#13 (comment)>:
> @@ -32,12 +28,28 @@ func Comma(v int64) string {
j--
}
parts[j] = strconv.Itoa(int(v))
- return sign + strings.Join(parts[j:len(parts)], ",")
+ return sign + strings.Join(parts[j:len(parts)], separator)
+}
+
+// Comma produces a string form of the given number in base 10 with
+// commas after every three orders of magnitude.
+//
+// e.g. Comma(834142) -> 834,142
+func (h *EnglishHumanizer) Comma(v int64) string {
IMHO, not breaking compatibility is critical. But we could add
i18n-friendly func aliases :
func (h *EnglishHumanizer) Comma(v int64) string {
return h.DecimalSeparator(v)
}
func (h *EnglishHumanizer) DecimalSeparator(v int64) string {
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#13 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAG8_bI3aY3lXZg8NZqkr3w0DOLFlRBks5rhohngaJpZM4DHGqc>
.
|
If you need i18n, use package main
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func main() {
p := message.NewPrinter(language.English)
p.Printf("%d\n", 1000)
// Output:
// 1,000
} |
This adds preliminary support for i18n - see #12
French & other languages will follow.