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

Add new localized versions of lang.FormatNumber etc. #8820

Closed
bep opened this issue Jul 28, 2021 · 0 comments
Closed

Add new localized versions of lang.FormatNumber etc. #8820

bep opened this issue Jul 28, 2021 · 0 comments
Assignees
Labels
Milestone

Comments

@bep
Copy link
Member

@bep bep commented Jul 28, 2021

We currently have this in the lang template funcs package:

func NumFmt(precision, number interface{}, options ...interface{}) (string, error) {}

The above isn't connected to any language definition, which makes it a little hard to use in a multilingual context.

With the introduction of time.Format in a57dda8 we now have the additional methods in the interface below (localized for "all" languages in the world).

We need to keep the existing function, so to avoid naming conflict, I suggest we add the below on the form

  • FormatNumber
  • FormatPercent
  • FormatCurrency
  • FormatAccounting

That way we could also, if we want, add an alias to FormatTime.

Thoughts? @jmooring @moorereason @regisphilibert and gang.

type interface Translator {
        // returns 'num' with digits/precision of 'v' for locale and handles both Whole and Real numbers based on 'v'
	FmtNumber(num float64, v uint64) string

	// returns 'num' with digits/precision of 'v' for locale and handles both Whole and Real numbers based on 'v'
	// NOTE: 'num' passed into FmtPercent is assumed to be in percent already
	FmtPercent(num float64, v uint64) string

	// returns the currency representation of 'num' with digits/precision of 'v' for locale
	FmtCurrency(num float64, v uint64, currency currency.Type) string

	// returns the currency representation of 'num' with digits/precision of 'v' for locale
	// in accounting notation.
	FmtAccounting(num float64, v uint64, currency currency.Type) string
}
@bep bep added the Proposal label Jul 28, 2021
@bep bep added this to the v0.87 milestone Jul 28, 2021
@bep bep self-assigned this Jul 28, 2021
@bep bep changed the title Add new Add new localized versions of lang.FormantNumber etc. Jul 28, 2021
@bep bep changed the title Add new localized versions of lang.FormantNumber etc. Add new localized versions of lang.FormatNumber etc. Jul 28, 2021
bep added a commit to bep/hugo that referenced this issue Jul 28, 2021
bep added a commit to bep/hugo that referenced this issue Jul 28, 2021
bep added a commit to bep/hugo that referenced this issue Jul 28, 2021
bep added a commit to bep/hugo that referenced this issue Jul 28, 2021
bep added a commit to bep/hugo that referenced this issue Jul 29, 2021
bep added a commit to bep/hugo that referenced this issue Jul 29, 2021
bep added a commit to bep/hugo that referenced this issue Jul 29, 2021
bep added a commit to bep/hugo that referenced this issue Jul 29, 2021
@bep bep closed this in 7907d24 Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant