|
|
@@ -20,10 +20,10 @@ type {{ .Locale }} struct {
|
|
|
minus string
|
|
|
percent string
|
|
|
{{- if gt (len .FmtPercentPrefix) 0}}
|
|
|
- percentPrefix []byte
|
|
|
+ percentPrefix string
|
|
|
{{- end }}
|
|
|
{{- if gt (len .FmtPercentSuffix) 0}}
|
|
|
- percentSuffix []byte
|
|
|
+ percentSuffix string
|
|
|
{{- end }}
|
|
|
perMille string
|
|
|
timeSeparator string
|
|
|
@@ -88,10 +88,10 @@ func New() locales.Translator {
|
|
|
{{- end}}
|
|
|
currencies: {{ .Currencies }},
|
|
|
{{- if gt (len .FmtPercentPrefix) 0}}
|
|
|
- percentPrefix: {{ .FmtPercentPrefix }},
|
|
|
+ percentPrefix: "{{ .FmtPercentPrefix }}",
|
|
|
{{- end -}}
|
|
|
{{- if gt (len .FmtPercentSuffix) 0}}
|
|
|
- percentSuffix: {{ .FmtPercentSuffix }},
|
|
|
+ percentSuffix: "{{ .FmtPercentSuffix }}",
|
|
|
{{- end -}}
|
|
|
{{- if gt (len .FmtCurrencyPrefix) 0}}
|
|
|
currencyPositivePrefix: "{{ .FmtCurrencyPrefix }}",
|
|
|
@@ -257,9 +257,9 @@ func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysWide() []string {
|
|
|
}
|
|
|
|
|
|
// FmtNumber returns 'num' with digits/precision of 'v' for '{{ .Locale }}' and handles both Whole and Real numbers based on 'v'
|
|
|
-func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) (results string) {
|
|
|
+func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) string {
|
|
|
|
|
|
- {{- if eq .FmtNumberExists true }}
|
|
|
+ {{ if eq .FmtNumberExists true }}
|
|
|
s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
{{- if gt .FmtNumberGroupLen 0 }}
|
|
|
l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtNumberGroupLen }}
|
|
|
@@ -278,13 +278,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) (results
|
|
|
|
|
|
if s[i] == '.' {
|
|
|
|
|
|
- {{- if eq (len .Decimal) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Decimal }}
|
|
|
for j := len({{ .BaseLocale }}.decimal) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.decimal[j])
|
|
|
}
|
|
|
- {{ end -}}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
+ {{- end -}}
|
|
|
{{- if gt .FmtNumberGroupLen 0 }}
|
|
|
inWhole = true
|
|
|
{{- end }}
|
|
|
@@ -297,13 +297,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) (results
|
|
|
{{- if gt .FmtNumberSecondaryGroupLen 0}}
|
|
|
|
|
|
if count == groupThreshold {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
|
|
|
if !inSecondary {
|
|
|
@@ -312,13 +312,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) (results
|
|
|
}
|
|
|
{{ else }}
|
|
|
if count == {{ .FmtNumberGroupLen }} {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
{{ end -}}
|
|
|
} else {
|
|
|
@@ -332,12 +332,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) (results
|
|
|
}
|
|
|
|
|
|
if num < 0 {
|
|
|
- {{- if eq (len .Minus) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
- {{ else }}
|
|
|
+ {{- if is_multibyte .Minus }}
|
|
|
for j := len({{ .BaseLocale }}.minus) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.minus[j])
|
|
|
}
|
|
|
+ {{ else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
{{ end -}}
|
|
|
}
|
|
|
|
|
|
@@ -359,17 +359,15 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) (results
|
|
|
}
|
|
|
{{ end }}
|
|
|
|
|
|
- results = string(b)
|
|
|
- return
|
|
|
+ return string(b)
|
|
|
{{ else }}
|
|
|
- results = strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
- return
|
|
|
+ return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
{{ end -}}
|
|
|
}
|
|
|
|
|
|
// FmtPercent 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
|
|
|
-func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) (results string) {
|
|
|
+func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) string {
|
|
|
|
|
|
{{- if eq .FmtPercentExists true }}
|
|
|
s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
@@ -390,13 +388,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) (result
|
|
|
|
|
|
if s[i] == '.' {
|
|
|
|
|
|
- {{- if eq (len .Decimal) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Decimal }}
|
|
|
for j := len({{ .BaseLocale }}.decimal) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.decimal[j])
|
|
|
}
|
|
|
- {{ end -}}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
+ {{- end -}}
|
|
|
{{- if gt .FmtPercentGroupLen 0 }}
|
|
|
inWhole = true
|
|
|
{{ end }}
|
|
|
@@ -409,13 +407,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) (result
|
|
|
{{- if gt .FmtPercentSecondaryGroupLen 0}}
|
|
|
|
|
|
if count == groupThreshold {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
|
|
|
if !inSecondary {
|
|
|
@@ -424,13 +422,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) (result
|
|
|
}
|
|
|
{{ else }}
|
|
|
if count == {{ .FmtPercentGroupLen }} {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
{{ end -}}
|
|
|
} else {
|
|
|
@@ -444,22 +442,22 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) (result
|
|
|
}
|
|
|
|
|
|
if num < 0 {
|
|
|
- {{- if eq (len .Minus) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
- {{ else }}
|
|
|
+ {{- if is_multibyte .Minus }}
|
|
|
for j := len({{ .BaseLocale }}.minus) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.minus[j])
|
|
|
}
|
|
|
+ {{ else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
{{ end -}}
|
|
|
}
|
|
|
|
|
|
{{ if and .FmtPercentInPrefix (not .FmtPercentLeft) }}
|
|
|
- {{- if eq (len .Percent) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.percent[0])
|
|
|
- {{ else }}
|
|
|
+ {{- if is_multibyte .Percent }}
|
|
|
for j := len({{ .BaseLocale }}.percent) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.percent[j])
|
|
|
}
|
|
|
+ {{ else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.percent[0])
|
|
|
{{ end }}
|
|
|
{{ end }}
|
|
|
|
|
|
@@ -474,12 +472,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) (result
|
|
|
{{ end }}
|
|
|
|
|
|
{{ if and .FmtPercentInPrefix .FmtPercentLeft }}
|
|
|
- {{- if eq (len .Percent) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.percent[0])
|
|
|
- {{ else }}
|
|
|
+ {{- if is_multibyte .Percent }}
|
|
|
for j := len({{ .BaseLocale }}.percent) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.percent[j])
|
|
|
}
|
|
|
+ {{ else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.percent[0])
|
|
|
{{ end }}
|
|
|
{{ end }}
|
|
|
|
|
|
@@ -513,16 +511,14 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) (result
|
|
|
b = append(b, {{ .BaseLocale }}.percent...)
|
|
|
{{ end }}
|
|
|
|
|
|
- results = string(b)
|
|
|
- return
|
|
|
+ return string(b)
|
|
|
{{ else }}
|
|
|
- results = strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
- return
|
|
|
+ return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
{{ end -}}
|
|
|
}
|
|
|
|
|
|
// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for '{{ .Locale }}'
|
|
|
-func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, currency currency.Type) (results string) {
|
|
|
+func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, currency currency.Type) string {
|
|
|
|
|
|
s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
symbol := {{ .BaseLocale }}.currencies[currency]
|
|
|
@@ -544,13 +540,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
|
|
|
|
|
|
if s[i] == '.' {
|
|
|
|
|
|
- {{- if eq (len .Decimal) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Decimal }}
|
|
|
for j := len({{ .BaseLocale }}.decimal) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.decimal[j])
|
|
|
}
|
|
|
- {{ end -}}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
+ {{- end -}}
|
|
|
{{- if gt .FmtCurrencyGroupLen 0 }}
|
|
|
inWhole = true
|
|
|
{{- end }}
|
|
|
@@ -563,13 +559,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
|
|
|
{{- if gt .FmtCurrencySecondaryGroupLen 0}}
|
|
|
|
|
|
if count == groupThreshold {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
|
|
|
if !inSecondary {
|
|
|
@@ -578,13 +574,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
|
|
|
}
|
|
|
{{ else }}
|
|
|
if count == {{ .FmtCurrencyGroupLen }} {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
{{ end -}}
|
|
|
} else {
|
|
|
@@ -620,12 +616,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
|
|
|
{{ end }}
|
|
|
|
|
|
if num < 0 {
|
|
|
- {{- if eq (len .Minus) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
- {{ else }}
|
|
|
+ {{- if is_multibyte .Minus }}
|
|
|
for j := len({{ .BaseLocale }}.minus) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.minus[j])
|
|
|
}
|
|
|
+ {{ else -}}
|
|
|
+ b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
{{ end -}}
|
|
|
}
|
|
|
|
|
|
@@ -659,17 +655,15 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
|
|
|
b = append(b, symbol...)
|
|
|
{{ end }}
|
|
|
|
|
|
- results = string(b)
|
|
|
- return
|
|
|
+ return string(b)
|
|
|
{{ else }}
|
|
|
- results = string(append(append([]byte{}, symbol...), s...))
|
|
|
- return
|
|
|
+ return string(append(append([]byte{}, symbol...), s...))
|
|
|
{{ end -}}
|
|
|
}
|
|
|
|
|
|
// FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for '{{ .Locale }}'
|
|
|
// in accounting notation.
|
|
|
-func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, currency currency.Type) (results string) {
|
|
|
+func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, currency currency.Type) string {
|
|
|
|
|
|
s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
|
|
|
symbol := {{ .BaseLocale }}.currencies[currency]
|
|
|
@@ -691,13 +685,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
|
|
|
|
|
|
if s[i] == '.' {
|
|
|
|
|
|
- {{- if eq (len .Decimal) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Decimal }}
|
|
|
for j := len({{ .BaseLocale }}.decimal) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.decimal[j])
|
|
|
}
|
|
|
- {{ end -}}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.decimal[0])
|
|
|
+ {{- end -}}
|
|
|
{{- if gt .FmtCurrencyGroupLen 0 }}
|
|
|
inWhole = true
|
|
|
{{- end }}
|
|
|
@@ -710,13 +704,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
|
|
|
{{- if gt .FmtCurrencySecondaryGroupLen 0}}
|
|
|
|
|
|
if count == groupThreshold {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
|
|
|
if !inSecondary {
|
|
|
@@ -725,13 +719,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
|
|
|
}
|
|
|
{{ else }}
|
|
|
if count == {{ .FmtCurrencyGroupLen }} {
|
|
|
- {{- if eq (len .Group) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
- {{- else }}
|
|
|
+ {{- if is_multibyte .Group }}
|
|
|
for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.group[j])
|
|
|
}
|
|
|
- {{ end }}
|
|
|
+ {{- else }}
|
|
|
+ b = append(b, {{ .BaseLocale }}.group[0])
|
|
|
+ {{- end }}
|
|
|
count = 1
|
|
|
{{ end -}}
|
|
|
} else {
|
|
|
@@ -769,12 +763,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
|
|
|
{{ end }}
|
|
|
|
|
|
{{ if eq (not .FmtCurrencyNegativeExists) true}}
|
|
|
- {{- if eq (len .Minus) 1 }}
|
|
|
- b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
- {{ else }}
|
|
|
+ {{- if is_multibyte .Minus }}
|
|
|
for j := len({{ .BaseLocale }}.minus) - 1; j >= 0; j-- {
|
|
|
b = append(b, {{ .BaseLocale }}.minus[j])
|
|
|
}
|
|
|
+ {{ else -}}
|
|
|
+ b = append(b, {{ .BaseLocale }}.minus[0])
|
|
|
{{ end -}}
|
|
|
{{ end }}
|
|
|
|
|
|
@@ -855,11 +849,9 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
|
|
|
}
|
|
|
{{- end }}
|
|
|
|
|
|
- results = string(b)
|
|
|
- return
|
|
|
+ return string(b)
|
|
|
{{ else }}
|
|
|
- results = string(append(append([]byte{}, symbol...), s...))
|
|
|
- return
|
|
|
+ return string(append(append([]byte{}, symbol...), s...))
|
|
|
{{ end -}}
|
|
|
}
|
|
|
|