Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Preliminary i18n support #13

wants to merge 1 commit into from

Conversation

jfbus
Copy link

@jfbus jfbus commented Dec 11, 2014

This adds preliminary support for i18n - see #12

French & other languages will follow.

// commas after every three orders of magnitude.
//
// e.g. Comma(834142) -> 834,142
func (h *EnglishHumanizer) Comma(v int64) string {
Copy link

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.

Copy link
Author

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 {

@dustin
Copy link
Owner

dustin commented Mar 2, 2017 via email

@dolmen
Copy link

dolmen commented Mar 20, 2024

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants