translator.tmpl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. {{ define "translator" }}
  2. package {{ .Locale }}
  3. import (
  4. "math"
  5. "github.com/go-playground/universal-translator/resources/locales"
  6. )
  7. type {{ .Locale }} struct {
  8. locale string
  9. plurals []locales.PluralRule
  10. decimal []byte
  11. group []byte
  12. minus []byte
  13. percent []byte
  14. perMille []byte
  15. symbol []byte
  16. }
  17. // New returns a new instance of translator for the '{{ .Locale }}' locale
  18. func New() locales.Translator {
  19. return &{{ .Locale }}{
  20. locale: "{{ .Locale }}",
  21. plurals: {{ .Plurals }},
  22. decimal: {{ .Decimal }},
  23. group: {{ .Group }},
  24. minus: {{ .Minus }},
  25. percent: {{ .Percent }},
  26. perMille: {{ .PerMille }},
  27. symbol: {{ .Symbol }},
  28. }
  29. }
  30. // Locale returns the current translators string locale
  31. func(t *{{ .Locale }}) Locale() string {
  32. return t.locale
  33. }
  34. // Plurals returns the list of plurals associated with '{{ .Locale }}'
  35. func(t *{{ .Locale }}) Plurals() []locales.PluralRule {
  36. return t.plurals
  37. }
  38. // cardinalPluralRule returns the PluralRule given 'num' and digits/precision of 'v' for '{{ .Locale }}'
  39. func(t *{{ .Locale }}) cardinalPluralRule(num float64, v uint64) locales.PluralRule {
  40. {{ .CardinalFunc }}
  41. }
  42. {{ end }}