...

Source file src/github.com/go-playground/locales/wae/wae.go

Documentation: github.com/go-playground/locales/wae

     1  package wae
     2  
     3  import (
     4  	"math"
     5  	"strconv"
     6  	"time"
     7  
     8  	"github.com/go-playground/locales"
     9  	"github.com/go-playground/locales/currency"
    10  )
    11  
    12  type wae struct {
    13  	locale                 string
    14  	pluralsCardinal        []locales.PluralRule
    15  	pluralsOrdinal         []locales.PluralRule
    16  	pluralsRange           []locales.PluralRule
    17  	decimal                string
    18  	group                  string
    19  	minus                  string
    20  	percent                string
    21  	perMille               string
    22  	timeSeparator          string
    23  	inifinity              string
    24  	currencies             []string // idx = enum of currency code
    25  	currencyPositivePrefix string
    26  	currencyPositiveSuffix string
    27  	currencyNegativePrefix string
    28  	currencyNegativeSuffix string
    29  	monthsAbbreviated      []string
    30  	monthsNarrow           []string
    31  	monthsWide             []string
    32  	daysAbbreviated        []string
    33  	daysNarrow             []string
    34  	daysShort              []string
    35  	daysWide               []string
    36  	periodsAbbreviated     []string
    37  	periodsNarrow          []string
    38  	periodsShort           []string
    39  	periodsWide            []string
    40  	erasAbbreviated        []string
    41  	erasNarrow             []string
    42  	erasWide               []string
    43  	timezones              map[string]string
    44  }
    45  
    46  // New returns a new instance of translator for the 'wae' locale
    47  func New() locales.Translator {
    48  	return &wae{
    49  		locale:                 "wae",
    50  		pluralsCardinal:        []locales.PluralRule{2, 6},
    51  		pluralsOrdinal:         nil,
    52  		pluralsRange:           nil,
    53  		decimal:                ",",
    54  		group:                  "’",
    55  		timeSeparator:          ":",
    56  		currencies:             []string{"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH", "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "ERN", "ESA", "ESB", "ESP", "ETB", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "¥", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MRU", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZD", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "$", "USN", "USS", "UYI", "UYP", "UYU", "UYW", "UZS", "VEB", "VEF", "VES", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWD", "ZWL", "ZWR"},
    57  		currencyPositivePrefix: " ",
    58  		currencyPositiveSuffix: "K",
    59  		currencyNegativePrefix: " ",
    60  		currencyNegativeSuffix: "K",
    61  		monthsAbbreviated:      []string{"", "Jen", "Hor", "Mär", "Abr", "Mei", "Brá", "Hei", "Öig", "Her", "Wím", "Win", "Chr"},
    62  		monthsNarrow:           []string{"", "J", "H", "M", "A", "M", "B", "H", "Ö", "H", "W", "W", "C"},
    63  		monthsWide:             []string{"", "Jenner", "Hornig", "Märze", "Abrille", "Meije", "Bráčet", "Heiwet", "Öigšte", "Herbštmánet", "Wímánet", "Wintermánet", "Chrištmánet"},
    64  		daysAbbreviated:        []string{"Sun", "Män", "Ziš", "Mit", "Fró", "Fri", "Sam"},
    65  		daysNarrow:             []string{"S", "M", "Z", "M", "F", "F", "S"},
    66  		daysWide:               []string{"Sunntag", "Mäntag", "Zištag", "Mittwuč", "Fróntag", "Fritag", "Samštag"},
    67  		erasAbbreviated:        []string{"v. Chr.", "n. Chr"},
    68  		erasNarrow:             []string{"", ""},
    69  		erasWide:               []string{"", ""},
    70  		timezones:              map[string]string{"ACDT": "ACDT", "ACST": "ACST", "ACWDT": "ACWDT", "ACWST": "ACWST", "ADT": "Atlantiši Summerzit", "AEDT": "AEDT", "AEST": "AEST", "AKDT": "AKDT", "AKST": "AKST", "ARST": "ARST", "ART": "ART", "AST": "Atlantiši Standardzit", "AWDT": "AWDT", "AWST": "AWST", "BOT": "BOT", "BT": "BT", "CAT": "CAT", "CDT": "CDT", "CHADT": "CHADT", "CHAST": "CHAST", "CLST": "CLST", "CLT": "CLT", "COST": "COST", "COT": "COT", "CST": "CST", "ChST": "ChST", "EAT": "EAT", "ECT": "ECT", "EDT": "EDT", "EST": "EST", "GFT": "GFT", "GMT": "GMT", "GST": "GST", "GYT": "GYT", "HADT": "HADT", "HAST": "HAST", "HAT": "HAT", "HECU": "HECU", "HEEG": "HEEG", "HENOMX": "HENOMX", "HEOG": "HEOG", "HEPM": "HEPM", "HEPMX": "HEPMX", "HKST": "HKST", "HKT": "HKT", "HNCU": "HNCU", "HNEG": "HNEG", "HNNOMX": "HNNOMX", "HNOG": "HNOG", "HNPM": "HNPM", "HNPMX": "HNPMX", "HNT": "HNT", "IST": "IST", "JDT": "JDT", "JST": "JST", "LHDT": "LHDT", "LHST": "LHST", "MDT": "MDT", "MESZ": "Mitteleuropäiši Summerzit", "MEZ": "Mitteleuropäiši Standardzit", "MST": "MST", "MYT": "MYT", "NZDT": "NZDT", "NZST": "NZST", "OESZ": "Ošteuropäiši Summerzit", "OEZ": "Ošteuropäiši Standardzit", "PDT": "PDT", "PST": "PST", "SAST": "SAST", "SGT": "SGT", "SRT": "SRT", "TMST": "TMST", "TMT": "TMT", "UYST": "UYST", "UYT": "UYT", "VET": "VET", "WARST": "WARST", "WART": "WART", "WAST": "WAST", "WAT": "WAT", "WESZ": "Wešteuropäiši Summerzit", "WEZ": "Wešteuropäiši Standardzit", "WIB": "WIB", "WIT": "WIT", "WITA": "WITA", "∅∅∅": "∅∅∅"},
    71  	}
    72  }
    73  
    74  // Locale returns the current translators string locale
    75  func (wae *wae) Locale() string {
    76  	return wae.locale
    77  }
    78  
    79  // PluralsCardinal returns the list of cardinal plural rules associated with 'wae'
    80  func (wae *wae) PluralsCardinal() []locales.PluralRule {
    81  	return wae.pluralsCardinal
    82  }
    83  
    84  // PluralsOrdinal returns the list of ordinal plural rules associated with 'wae'
    85  func (wae *wae) PluralsOrdinal() []locales.PluralRule {
    86  	return wae.pluralsOrdinal
    87  }
    88  
    89  // PluralsRange returns the list of range plural rules associated with 'wae'
    90  func (wae *wae) PluralsRange() []locales.PluralRule {
    91  	return wae.pluralsRange
    92  }
    93  
    94  // CardinalPluralRule returns the cardinal PluralRule given 'num' and digits/precision of 'v' for 'wae'
    95  func (wae *wae) CardinalPluralRule(num float64, v uint64) locales.PluralRule {
    96  
    97  	n := math.Abs(num)
    98  
    99  	if n == 1 {
   100  		return locales.PluralRuleOne
   101  	}
   102  
   103  	return locales.PluralRuleOther
   104  }
   105  
   106  // OrdinalPluralRule returns the ordinal PluralRule given 'num' and digits/precision of 'v' for 'wae'
   107  func (wae *wae) OrdinalPluralRule(num float64, v uint64) locales.PluralRule {
   108  	return locales.PluralRuleUnknown
   109  }
   110  
   111  // RangePluralRule returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for 'wae'
   112  func (wae *wae) RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) locales.PluralRule {
   113  	return locales.PluralRuleUnknown
   114  }
   115  
   116  // MonthAbbreviated returns the locales abbreviated month given the 'month' provided
   117  func (wae *wae) MonthAbbreviated(month time.Month) string {
   118  	return wae.monthsAbbreviated[month]
   119  }
   120  
   121  // MonthsAbbreviated returns the locales abbreviated months
   122  func (wae *wae) MonthsAbbreviated() []string {
   123  	return wae.monthsAbbreviated[1:]
   124  }
   125  
   126  // MonthNarrow returns the locales narrow month given the 'month' provided
   127  func (wae *wae) MonthNarrow(month time.Month) string {
   128  	return wae.monthsNarrow[month]
   129  }
   130  
   131  // MonthsNarrow returns the locales narrow months
   132  func (wae *wae) MonthsNarrow() []string {
   133  	return wae.monthsNarrow[1:]
   134  }
   135  
   136  // MonthWide returns the locales wide month given the 'month' provided
   137  func (wae *wae) MonthWide(month time.Month) string {
   138  	return wae.monthsWide[month]
   139  }
   140  
   141  // MonthsWide returns the locales wide months
   142  func (wae *wae) MonthsWide() []string {
   143  	return wae.monthsWide[1:]
   144  }
   145  
   146  // WeekdayAbbreviated returns the locales abbreviated weekday given the 'weekday' provided
   147  func (wae *wae) WeekdayAbbreviated(weekday time.Weekday) string {
   148  	return wae.daysAbbreviated[weekday]
   149  }
   150  
   151  // WeekdaysAbbreviated returns the locales abbreviated weekdays
   152  func (wae *wae) WeekdaysAbbreviated() []string {
   153  	return wae.daysAbbreviated
   154  }
   155  
   156  // WeekdayNarrow returns the locales narrow weekday given the 'weekday' provided
   157  func (wae *wae) WeekdayNarrow(weekday time.Weekday) string {
   158  	return wae.daysNarrow[weekday]
   159  }
   160  
   161  // WeekdaysNarrow returns the locales narrow weekdays
   162  func (wae *wae) WeekdaysNarrow() []string {
   163  	return wae.daysNarrow
   164  }
   165  
   166  // WeekdayShort returns the locales short weekday given the 'weekday' provided
   167  func (wae *wae) WeekdayShort(weekday time.Weekday) string {
   168  	return wae.daysShort[weekday]
   169  }
   170  
   171  // WeekdaysShort returns the locales short weekdays
   172  func (wae *wae) WeekdaysShort() []string {
   173  	return wae.daysShort
   174  }
   175  
   176  // WeekdayWide returns the locales wide weekday given the 'weekday' provided
   177  func (wae *wae) WeekdayWide(weekday time.Weekday) string {
   178  	return wae.daysWide[weekday]
   179  }
   180  
   181  // WeekdaysWide returns the locales wide weekdays
   182  func (wae *wae) WeekdaysWide() []string {
   183  	return wae.daysWide
   184  }
   185  
   186  // Decimal returns the decimal point of number
   187  func (wae *wae) Decimal() string {
   188  	return wae.decimal
   189  }
   190  
   191  // Group returns the group of number
   192  func (wae *wae) Group() string {
   193  	return wae.group
   194  }
   195  
   196  // Group returns the minus sign of number
   197  func (wae *wae) Minus() string {
   198  	return wae.minus
   199  }
   200  
   201  // FmtNumber returns 'num' with digits/precision of 'v' for 'wae' and handles both Whole and Real numbers based on 'v'
   202  func (wae *wae) FmtNumber(num float64, v uint64) string {
   203  
   204  	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   205  }
   206  
   207  // FmtPercent returns 'num' with digits/precision of 'v' for 'wae' and handles both Whole and Real numbers based on 'v'
   208  // NOTE: 'num' passed into FmtPercent is assumed to be in percent already
   209  func (wae *wae) FmtPercent(num float64, v uint64) string {
   210  	return strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   211  }
   212  
   213  // FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'wae'
   214  func (wae *wae) FmtCurrency(num float64, v uint64, currency currency.Type) string {
   215  
   216  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   217  	symbol := wae.currencies[currency]
   218  	l := len(s) + len(symbol) + 4
   219  
   220  	b := make([]byte, 0, l)
   221  
   222  	for i := len(s) - 1; i >= 0; i-- {
   223  
   224  		if s[i] == '.' {
   225  			b = append(b, wae.decimal[0])
   226  			continue
   227  		}
   228  
   229  		b = append(b, s[i])
   230  	}
   231  
   232  	for j := len(symbol) - 1; j >= 0; j-- {
   233  		b = append(b, symbol[j])
   234  	}
   235  
   236  	for j := len(wae.currencyPositivePrefix) - 1; j >= 0; j-- {
   237  		b = append(b, wae.currencyPositivePrefix[j])
   238  	}
   239  
   240  	if num < 0 {
   241  		b = append(b, wae.minus[0])
   242  	}
   243  
   244  	// reverse
   245  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   246  		b[i], b[j] = b[j], b[i]
   247  	}
   248  
   249  	b = append(b, wae.currencyPositiveSuffix...)
   250  
   251  	return string(b)
   252  }
   253  
   254  // FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'wae'
   255  // in accounting notation.
   256  func (wae *wae) FmtAccounting(num float64, v uint64, currency currency.Type) string {
   257  
   258  	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
   259  	symbol := wae.currencies[currency]
   260  	l := len(s) + len(symbol) + 4
   261  
   262  	b := make([]byte, 0, l)
   263  
   264  	for i := len(s) - 1; i >= 0; i-- {
   265  
   266  		if s[i] == '.' {
   267  			b = append(b, wae.decimal[0])
   268  			continue
   269  		}
   270  
   271  		b = append(b, s[i])
   272  	}
   273  
   274  	if num < 0 {
   275  
   276  		for j := len(symbol) - 1; j >= 0; j-- {
   277  			b = append(b, symbol[j])
   278  		}
   279  
   280  		for j := len(wae.currencyNegativePrefix) - 1; j >= 0; j-- {
   281  			b = append(b, wae.currencyNegativePrefix[j])
   282  		}
   283  
   284  		b = append(b, wae.minus[0])
   285  
   286  	} else {
   287  
   288  		for j := len(symbol) - 1; j >= 0; j-- {
   289  			b = append(b, symbol[j])
   290  		}
   291  
   292  		for j := len(wae.currencyPositivePrefix) - 1; j >= 0; j-- {
   293  			b = append(b, wae.currencyPositivePrefix[j])
   294  		}
   295  
   296  	}
   297  
   298  	// reverse
   299  	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
   300  		b[i], b[j] = b[j], b[i]
   301  	}
   302  
   303  	if num < 0 {
   304  		b = append(b, wae.currencyNegativeSuffix...)
   305  	} else {
   306  
   307  		b = append(b, wae.currencyPositiveSuffix...)
   308  	}
   309  
   310  	return string(b)
   311  }
   312  
   313  // FmtDateShort returns the short date representation of 't' for 'wae'
   314  func (wae *wae) FmtDateShort(t time.Time) string {
   315  
   316  	b := make([]byte, 0, 32)
   317  
   318  	return string(b)
   319  }
   320  
   321  // FmtDateMedium returns the medium date representation of 't' for 'wae'
   322  func (wae *wae) FmtDateMedium(t time.Time) string {
   323  
   324  	b := make([]byte, 0, 32)
   325  
   326  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   327  	b = append(b, []byte{0x2e, 0x20}...)
   328  	b = append(b, wae.monthsAbbreviated[t.Month()]...)
   329  	b = append(b, []byte{0x20}...)
   330  
   331  	if t.Year() > 0 {
   332  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   333  	} else {
   334  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   335  	}
   336  
   337  	return string(b)
   338  }
   339  
   340  // FmtDateLong returns the long date representation of 't' for 'wae'
   341  func (wae *wae) FmtDateLong(t time.Time) string {
   342  
   343  	b := make([]byte, 0, 32)
   344  
   345  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   346  	b = append(b, []byte{0x2e, 0x20}...)
   347  	b = append(b, wae.monthsWide[t.Month()]...)
   348  	b = append(b, []byte{0x20}...)
   349  
   350  	if t.Year() > 0 {
   351  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   352  	} else {
   353  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   354  	}
   355  
   356  	return string(b)
   357  }
   358  
   359  // FmtDateFull returns the full date representation of 't' for 'wae'
   360  func (wae *wae) FmtDateFull(t time.Time) string {
   361  
   362  	b := make([]byte, 0, 32)
   363  
   364  	b = append(b, wae.daysWide[t.Weekday()]...)
   365  	b = append(b, []byte{0x2c, 0x20}...)
   366  	b = strconv.AppendInt(b, int64(t.Day()), 10)
   367  	b = append(b, []byte{0x2e, 0x20}...)
   368  	b = append(b, wae.monthsWide[t.Month()]...)
   369  	b = append(b, []byte{0x20}...)
   370  
   371  	if t.Year() > 0 {
   372  		b = strconv.AppendInt(b, int64(t.Year()), 10)
   373  	} else {
   374  		b = strconv.AppendInt(b, int64(-t.Year()), 10)
   375  	}
   376  
   377  	return string(b)
   378  }
   379  
   380  // FmtTimeShort returns the short time representation of 't' for 'wae'
   381  func (wae *wae) FmtTimeShort(t time.Time) string {
   382  
   383  	b := make([]byte, 0, 32)
   384  
   385  	return string(b)
   386  }
   387  
   388  // FmtTimeMedium returns the medium time representation of 't' for 'wae'
   389  func (wae *wae) FmtTimeMedium(t time.Time) string {
   390  
   391  	b := make([]byte, 0, 32)
   392  
   393  	return string(b)
   394  }
   395  
   396  // FmtTimeLong returns the long time representation of 't' for 'wae'
   397  func (wae *wae) FmtTimeLong(t time.Time) string {
   398  
   399  	b := make([]byte, 0, 32)
   400  
   401  	return string(b)
   402  }
   403  
   404  // FmtTimeFull returns the full time representation of 't' for 'wae'
   405  func (wae *wae) FmtTimeFull(t time.Time) string {
   406  
   407  	b := make([]byte, 0, 32)
   408  
   409  	return string(b)
   410  }
   411  

View as plain text