go-humanize
go-humanize copied to clipboard
Preliminary i18n support
This adds preliminary support for i18n - see #12
French & other languages will follow.
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 < [email protected]> wrote:
@jfbus commented on this pull request.
In comma.go https://github.com/dustin/go-humanize/pull/13#discussion_r103879265:
@@ -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 https://github.com/dustin/go-humanize/pull/13#discussion_r103879265, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAG8_bI3aY3lXZg8NZqkr3w0DOLFlRBks5rhohngaJpZM4DHGqc .
If you need i18n, use golang.org/x/text/message:
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
}