Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/locales.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/translator.tmpl')
-rw-r--r--cmd/translator.tmpl379
1 files changed, 183 insertions, 196 deletions
diff --git a/cmd/translator.tmpl b/cmd/translator.tmpl
index e623a3a2..0bd42b6f 100644
--- a/cmd/translator.tmpl
+++ b/cmd/translator.tmpl
@@ -15,47 +15,47 @@ type {{ .Locale }} struct {
pluralsCardinal []locales.PluralRule
pluralsOrdinal []locales.PluralRule
pluralsRange []locales.PluralRule
- decimal []byte
- group []byte
- minus []byte
- percent []byte
+ decimal string
+ group string
+ 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 []byte
- timeSeparator []byte
- inifinity []byte
- currencies [][]byte // idx = enum of currency code
+ perMille string
+ timeSeparator string
+ inifinity string
+ currencies []string // idx = enum of currency code
{{- if gt (len .FmtCurrencyPrefix) 0}}
- currencyPositivePrefix []byte
+ currencyPositivePrefix string
{{- end }}
{{- if gt (len .FmtCurrencySuffix) 0}}
- currencyPositiveSuffix []byte
+ currencyPositiveSuffix string
{{- end }}
{{- if gt (len .FmtCurrencyNegativePrefix) 0}}
- currencyNegativePrefix []byte
+ currencyNegativePrefix string
{{- end }}
{{- if gt (len .FmtCurrencyNegativeSuffix) 0}}
- currencyNegativeSuffix []byte
+ currencyNegativeSuffix string
{{- end }}
- monthsAbbreviated [][]byte
- monthsNarrow [][]byte
- monthsWide [][]byte
- daysAbbreviated [][]byte
- daysNarrow [][]byte
- daysShort [][]byte
- daysWide [][]byte
- periodsAbbreviated [][]byte
- periodsNarrow [][]byte
- periodsShort [][]byte
- periodsWide [][]byte
- erasAbbreviated [][]byte
- erasNarrow [][]byte
- erasWide [][]byte
- timezones map[string][]byte
+ monthsAbbreviated []string
+ monthsNarrow []string
+ monthsWide []string
+ daysAbbreviated []string
+ daysNarrow []string
+ daysShort []string
+ daysWide []string
+ periodsAbbreviated []string
+ periodsNarrow []string
+ periodsShort []string
+ periodsWide []string
+ erasAbbreviated []string
+ erasNarrow []string
+ erasWide []string
+ timezones map[string]string
}
// New returns a new instance of translator for the '{{ .Locale }}' locale
@@ -65,35 +65,45 @@ func New() locales.Translator {
pluralsCardinal: {{ .Plurals }},
pluralsOrdinal: {{ .PluralsOrdinal }},
pluralsRange: {{ .PluralsRange }},
- decimal: {{ .Decimal }},
- group: {{ .Group }},
- minus: {{ .Minus }},
- percent: {{ .Percent }},
- perMille: {{ .PerMille }},
+ {{- if gt (len .Decimal) 0}}
+ decimal: "{{ .Decimal }}",
+ {{- end}}
+ {{- if gt (len .Group) 0}}
+ group: "{{ .Group }}",
+ {{- end}}
+ {{- if gt (len .Minus) 0}}
+ minus: "{{ .Minus }}",
+ {{- end}}
+ {{- if gt (len .Percent) 0}}
+ percent: "{{ .Percent }}",
+ {{- end}}
+ {{- if gt (len .PerMille) 0}}
+ perMille: "{{ .PerMille }}",
+ {{- end}}
{{- if gt (len .TimeSeparator) 0}}
- timeSeparator: {{ .TimeSeparator }},
+ timeSeparator: "{{ .TimeSeparator }}",
{{- end}}
{{- if gt (len .Infinity) 0}}
- inifinity: {{ .Infinity }},
+ inifinity: "{{ .Infinity }}",
{{- 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 }},
+ currencyPositivePrefix: "{{ .FmtCurrencyPrefix }}",
{{- end -}}
{{- if gt (len .FmtCurrencySuffix) 0}}
- currencyPositiveSuffix: {{ .FmtCurrencySuffix }},
+ currencyPositiveSuffix: "{{ .FmtCurrencySuffix }}",
{{- end -}}
{{- if gt (len .FmtCurrencyNegativePrefix) 0}}
- currencyNegativePrefix: {{ .FmtCurrencyNegativePrefix }},
+ currencyNegativePrefix: "{{ .FmtCurrencyNegativePrefix }}",
{{- end -}}
{{- if gt (len .FmtCurrencyNegativeSuffix) 0}}
- currencyNegativeSuffix: {{ .FmtCurrencyNegativeSuffix }},
+ currencyNegativeSuffix: "{{ .FmtCurrencyNegativeSuffix }}",
{{- end -}}
{{- if gt (len .FmtMonthsAbbreviated) 0 }}
monthsAbbreviated: {{ .FmtMonthsAbbreviated }},
@@ -177,84 +187,82 @@ func({{ .BaseLocale }} *{{ .Locale }}) RangePluralRule(num1 float64, v1 uint64,n
}
// MonthAbbreviated returns the locales abbreviated month given the 'month' provided
-func({{ .BaseLocale }} *{{ .Locale }}) MonthAbbreviated(month time.Month) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) MonthAbbreviated(month time.Month) string {
return {{ .BaseLocale }}.monthsAbbreviated[month]
}
// MonthsAbbreviated returns the locales abbreviated months
-func({{ .BaseLocale }} *{{ .Locale }}) MonthsAbbreviated() [][]byte {
+func({{ .BaseLocale }} *{{ .Locale }}) MonthsAbbreviated() []string {
return {{ .BaseLocale }}.monthsAbbreviated[1:]
}
// MonthNarrow returns the locales narrow month given the 'month' provided
-func({{ .BaseLocale }} *{{ .Locale }}) MonthNarrow(month time.Month) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) MonthNarrow(month time.Month) string {
return {{ .BaseLocale }}.monthsNarrow[month]
}
// MonthsNarrow returns the locales narrow months
-func({{ .BaseLocale }} *{{ .Locale }}) MonthsNarrow() [][]byte {
+func({{ .BaseLocale }} *{{ .Locale }}) MonthsNarrow() []string {
return {{ .BaseLocale }}.monthsNarrow[1:]
}
// MonthWide returns the locales wide month given the 'month' provided
-func({{ .BaseLocale }} *{{ .Locale }}) MonthWide(month time.Month) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) MonthWide(month time.Month) string {
return {{ .BaseLocale }}.monthsWide[month]
}
// MonthsWide returns the locales wide months
-func({{ .BaseLocale }} *{{ .Locale }}) MonthsWide() [][]byte {
+func({{ .BaseLocale }} *{{ .Locale }}) MonthsWide() []string {
return {{ .BaseLocale }}.monthsWide[1:]
}
// WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdayAbbreviated(weekday time.Weekday) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdayAbbreviated(weekday time.Weekday) string {
return {{ .BaseLocale }}.daysAbbreviated[weekday]
}
// WeekdaysAbbreviated returns the locales abbreviated weekdays
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysAbbreviated() [][]byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysAbbreviated() []string {
return {{ .BaseLocale }}.daysAbbreviated
}
// WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdayNarrow(weekday time.Weekday) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdayNarrow(weekday time.Weekday) string {
return {{ .BaseLocale }}.daysNarrow[weekday]
}
// WeekdaysNarrow returns the locales narrow weekdays
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysNarrow() [][]byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysNarrow() []string {
return {{ .BaseLocale }}.daysNarrow
}
// WeekdayShort returns the locales short weekday given the 'weekday' provided
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdayShort(weekday time.Weekday) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdayShort(weekday time.Weekday) string {
return {{ .BaseLocale }}.daysShort[weekday]
}
// WeekdaysShort returns the locales short weekdays
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysShort() [][]byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysShort() []string {
return {{ .BaseLocale }}.daysShort
}
// WeekdayWide returns the locales wide weekday given the 'weekday' provided
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdayWide(weekday time.Weekday) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdayWide(weekday time.Weekday) string {
return {{ .BaseLocale }}.daysWide[weekday]
}
// WeekdaysWide returns the locales wide weekdays
-func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysWide() [][]byte {
+func({{ .BaseLocale }} *{{ .Locale }}) WeekdaysWide() []string {
return {{ .BaseLocale }}.daysWide
}
// FmtNumber returns 'num' with digits/precision of 'v' for '{{ .Locale }}' and handles both Whole and Real numbers based on 'v'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) string {
+ {{ if eq .FmtNumberExists true }}
s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
- {{- if eq .FmtNumberExists true }}
{{- if gt .FmtNumberGroupLen 0 }}
- l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtNumberGroupLen }}
+ l := len(s) + {{ byte_count .Decimal .Minus }} + {{ byte_count .Group }} * len(s[:len(s)-int(v)-1]) / {{ .FmtNumberGroupLen }}
count := 0
inWhole := v == 0
{{- if gt .FmtNumberSecondaryGroupLen 0}}
@@ -262,7 +270,7 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte {
groupThreshold := {{ .FmtNumberGroupLen }}
{{ end -}}
{{ else }}
- l := len(s) + len({{ .BaseLocale }}.decimal)
+ l := len(s) + {{ byte_count .Decimal .Minus }}
{{ end }}
b := make([]byte, 0, l)
@@ -270,13 +278,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte {
if s[i] == '.' {
- {{- if eq .DecimalLen 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 }}
@@ -289,13 +297,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte {
{{- if gt .FmtNumberSecondaryGroupLen 0}}
if count == groupThreshold {
- {{- if eq .GroupLen 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 {
@@ -304,13 +312,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte {
}
{{ else }}
if count == {{ .FmtNumberGroupLen }} {
- {{- if eq .GroupLen 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 {
@@ -324,12 +332,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte {
}
if num < 0 {
- {{- if eq .MinusLen 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 -}}
}
@@ -351,22 +359,20 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtNumber(num float64, v uint64) []byte {
}
{{ end }}
- return b
+ return string(b)
{{ else }}
- return []byte(s)
+ 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'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
// NOTE: 'num' passed into FmtPercent is assumed to be in percent already
-func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) string {
- s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
{{- if eq .FmtPercentExists true }}
+ s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
{{- if gt .FmtPercentGroupLen 0 }}
- l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtPercentGroupLen }}
+ l := len(s) + {{ byte_count .Decimal .Minus .Percent .FmtPercentPrefix .FmtPercentSuffix }} + {{ byte_count .Group }} * len(s[:len(s)-int(v)-1]) / {{ .FmtPercentGroupLen }}
count := 0
inWhole := v == 0
{{- if gt .FmtPercentSecondaryGroupLen 0}}
@@ -374,7 +380,7 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
groupThreshold := {{ .FmtPercentGroupLen }}
{{ end -}}
{{ else }}
- l := len(s) + len({{ .BaseLocale }}.decimal)
+ l := len(s) + {{ byte_count .Decimal .Minus .Percent .FmtPercentPrefix .FmtPercentSuffix }}
{{- end }}
b := make([]byte, 0, l)
@@ -382,13 +388,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
if s[i] == '.' {
- {{- if eq .DecimalLen 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 }}
@@ -401,13 +407,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
{{- if gt .FmtPercentSecondaryGroupLen 0}}
if count == groupThreshold {
- {{- if eq .GroupLen 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 {
@@ -416,13 +422,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
}
{{ else }}
if count == {{ .FmtPercentGroupLen }} {
- {{- if eq .GroupLen 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 {
@@ -436,42 +442,42 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
}
if num < 0 {
- {{- if eq .MinusLen 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 .PercentLen 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 }}
{{ if gt (len .FmtPercentPrefix) 0}}
- {{- if eq (len .FmtPercentPrefix) 1 }}
- b = append(b, {{ .BaseLocale }}.percentPrefix[0])
- {{ else }}
+ {{- if is_multibyte .FmtPercentPrefix }}
for j := len({{ .BaseLocale }}.percentPrefix) - 1; j >= 0; j-- {
b = append(b, {{ .BaseLocale }}.percentPrefix[j])
}
+ {{ else }}
+ b = append(b, {{ .BaseLocale }}.percentPrefix[0])
{{ end }}
{{ end }}
{{ if and .FmtPercentInPrefix .FmtPercentLeft }}
- {{- if eq .PercentLen 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 }}
@@ -505,22 +511,20 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
b = append(b, {{ .BaseLocale }}.percent...)
{{ end }}
- return b
+ return string(b)
{{ else }}
- return []byte(s)
+ 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 }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, currency currency.Type) []byte {
+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]
{{- if eq .FmtCurrencyExists true }}
{{- if gt .FmtCurrencyGroupLen 0 }}
- l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtCurrencyGroupLen }}
+ l := len(s) + len(symbol) + {{ byte_count .Decimal .Minus .FmtCurrencyPrefix .FmtCurrencySuffix }} + {{ byte_count .Group }} * len(s[:len(s)-int(v)-1]) / {{ .FmtCurrencyGroupLen }}
count := 0
inWhole := v == 0
{{- if gt .FmtCurrencySecondaryGroupLen 0}}
@@ -528,7 +532,7 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
groupThreshold := {{ .FmtCurrencyGroupLen }}
{{ end -}}
{{ else }}
- l := len(s) + len({{ .BaseLocale }}.decimal)
+ l := len(s) + len(symbol) + {{ byte_count .Decimal .Minus .FmtCurrencyPrefix .FmtCurrencySuffix }}
{{ end }}
b := make([]byte, 0, l)
@@ -536,13 +540,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
if s[i] == '.' {
- {{- if eq .DecimalLen 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 }}
@@ -555,13 +559,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
{{- if gt .FmtCurrencySecondaryGroupLen 0}}
if count == groupThreshold {
- {{- if eq .GroupLen 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 {
@@ -570,13 +574,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
}
{{ else }}
if count == {{ .FmtCurrencyGroupLen }} {
- {{- if eq .GroupLen 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 {
@@ -596,12 +600,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
{{ end }}
{{ if gt (len .FmtCurrencyPrefix) 0}}
- {{- if eq (len .FmtCurrencyPrefix) 1 }}
- b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[0])
- {{ else }}
+ {{- if is_multibyte .FmtCurrencyPrefix }}
for j := len({{ .BaseLocale }}.currencyPositivePrefix) - 1; j >= 0; j-- {
b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[j])
}
+ {{ else }}
+ b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[0])
{{ end }}
{{ end }}
@@ -612,12 +616,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
{{ end }}
if num < 0 {
- {{- if eq .MinusLen 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 -}}
}
@@ -651,22 +655,21 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, curren
b = append(b, symbol...)
{{ end }}
- return b
+ return string(b)
{{ else }}
- return append(append([]byte{}, symbol...), s...)
+ 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. returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, currency currency.Type) []byte {
+// in accounting notation.
+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]
{{- if eq .FmtCurrencyExists true }}
{{- if gt .FmtCurrencyGroupLen 0 }}
- l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtCurrencyGroupLen }}
+ l := len(s) + len(symbol) + {{ byte_count .Decimal .Minus .FmtCurrencyNegativePrefix .FmtCurrencyNegativeSuffix }} + {{ byte_count .Group }} * len(s[:len(s)-int(v)-1]) / {{ .FmtCurrencyGroupLen }}
count := 0
inWhole := v == 0
{{- if gt .FmtCurrencySecondaryGroupLen 0}}
@@ -674,7 +677,7 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
groupThreshold := {{ .FmtCurrencyGroupLen }}
{{ end -}}
{{ else }}
- l := len(s) + len({{ .BaseLocale }}.decimal)
+ l := len(s) + len(symbol) + {{ byte_count .Decimal .Minus .FmtCurrencyNegativePrefix .FmtCurrencyNegativeSuffix }}
{{ end }}
b := make([]byte, 0, l)
@@ -682,13 +685,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
if s[i] == '.' {
- {{- if eq .DecimalLen 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 }}
@@ -701,13 +704,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
{{- if gt .FmtCurrencySecondaryGroupLen 0}}
if count == groupThreshold {
- {{- if eq .GroupLen 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 {
@@ -716,13 +719,13 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
}
{{ else }}
if count == {{ .FmtCurrencyGroupLen }} {
- {{- if eq .GroupLen 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 {
@@ -744,12 +747,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
{{ end }}
{{ if gt (len .FmtCurrencyNegativePrefix) 0}}
- {{- if eq (len .FmtCurrencyNegativePrefix) 1 }}
- b = append(b, {{ .BaseLocale }}.currencyNegativePrefix[0])
- {{ else }}
+ {{- if is_multibyte .FmtCurrencyNegativePrefix }}
for j := len({{ .BaseLocale }}.currencyNegativePrefix) - 1; j >= 0; j-- {
b = append(b, {{ .BaseLocale }}.currencyNegativePrefix[j])
}
+ {{ else }}
+ b = append(b, {{ .BaseLocale }}.currencyNegativePrefix[0])
{{ end }}
{{ end }}
@@ -760,12 +763,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
{{ end }}
{{ if eq (not .FmtCurrencyNegativeExists) true}}
- {{- if eq .MinusLen 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 }}
@@ -780,12 +783,12 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
{{ end }}
{{ if gt (len .FmtCurrencyPrefix) 0}}
- {{- if eq (len .FmtCurrencyPrefix) 1 }}
- b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[0])
- {{ else }}
+ {{- if is_multibyte .FmtCurrencyPrefix }}
for j := len({{ .BaseLocale }}.currencyPositivePrefix) - 1; j >= 0; j-- {
b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[j])
}
+ {{ else }}
+ b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[0])
{{ end }}
{{ end }}
@@ -846,106 +849,90 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtAccounting(num float64, v uint64, curr
}
{{- end }}
- return b
+ return string(b)
{{ else }}
- return append(append([]byte{}, symbol...), s...)
+ return string(append(append([]byte{}, symbol...), s...))
{{ end -}}
}
// FmtDateShort returns the short date representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtDateShort(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtDateShort(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtDateShort }}
- return b
+ return string(b)
}
// FmtDateMedium returns the medium date representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtDateMedium(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtDateMedium(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtDateMedium }}
- return b
+ return string(b)
}
// FmtDateLong returns the long date representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtDateLong(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtDateLong(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtDateLong }}
- return b
+ return string(b)
}
// FmtDateFull returns the full date representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtDateFull(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtDateFull(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtDateFull }}
- return b
+ return string(b)
}
// FmtTimeShort returns the short time representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeShort(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeShort(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtTimeShort }}
- return b
+ return string(b)
}
// FmtTimeMedium returns the medium time representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeMedium(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeMedium(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtTimeMedium }}
- return b
+ return string(b)
}
// FmtTimeLong returns the long time representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeLong(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeLong(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtTimeLong }}
- return b
+ return string(b)
}
// FmtTimeFull returns the full time representation of 't' for '{{ .Locale }}'
-// returned as a []byte just in case the caller wishes to add more and can help
-// avoid allocations; otherwise just cast as string.
-func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeFull(t time.Time) []byte {
+func({{ .BaseLocale }} *{{ .Locale }}) FmtTimeFull(t time.Time) string {
b := make([]byte, 0, 32)
{{ .FmtTimeFull }}
- return b
+ return string(b)
}
{{ end }}