locales

package module
v0.0.0-...-afc58ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 15 Imported by: 0

README ¶

locales

Project status Build Status

GoDoc

License

Locales is a set of locales generated from the Unicode CLDR Project which can be used independently or within an i18n package; these were built for use with, but not exclusive to, Universal Translator.

Features

  • Rules generated from the latest CLDR data, v36.0.1
  • Contains Cardinal, Ordinal and Range Plural Rules
  • Contains Month, Weekday and Timezone translations built in
  • Contains Date & Time formatting functions
  • Contains Number, Currency, Accounting and Percent formatting functions
  • Supports the "Gregorian" calendar only ( my time isn't unlimited, had to draw the line somewhere )

Full Tests

I could sure use your help adding tests for every locale, it is a huge undertaking and I just don't have the free time to do it all at the moment; any help would be greatly appreciated!!!! please see issue for details.

Installation

Use go get

go get github.com/moisespsena-go/locales

NOTES

You'll notice most return types are []byte, this is because most of the time the results will be concatenated with a larger body of text and can avoid some allocations if already appending to a byte array, otherwise just cast as string.

Usage

package main

import (
	"fmt"
	"time"

	"github.com/moisespsena-go/locales/currency"
	"github.com/moisespsena-go/locales/named/en_CA"
)

func main() {

	loc, _ := time.LoadLocation("America/Toronto")
	datetime := time.Date(2016, 02, 03, 9, 0, 1, 0, loc)

	l := en_CA.New()

	// Dates
	fmt.Println(l.FmtDateFull(datetime))
	fmt.Println(l.FmtDateLong(datetime))
	fmt.Println(l.FmtDateMedium(datetime))
	fmt.Println(l.FmtDateShort(datetime))

	// Times
	fmt.Println(l.FmtTimeFull(datetime))
	fmt.Println(l.FmtTimeLong(datetime))
	fmt.Println(l.FmtTimeMedium(datetime))
	fmt.Println(l.FmtTimeShort(datetime))

	// Months Wide
	fmt.Println(l.MonthWide(time.January))
	fmt.Println(l.MonthWide(time.February))
	fmt.Println(l.MonthWide(time.March))
	// ...

	// Months Abbreviated
	fmt.Println(l.MonthAbbreviated(time.January))
	fmt.Println(l.MonthAbbreviated(time.February))
	fmt.Println(l.MonthAbbreviated(time.March))
	// ...

	// Months Narrow
	fmt.Println(l.MonthNarrow(time.January))
	fmt.Println(l.MonthNarrow(time.February))
	fmt.Println(l.MonthNarrow(time.March))
	// ...

	// Weekdays Wide
	fmt.Println(l.WeekdayWide(time.Sunday))
	fmt.Println(l.WeekdayWide(time.Monday))
	fmt.Println(l.WeekdayWide(time.Tuesday))
	// ...

	// Weekdays Abbreviated
	fmt.Println(l.WeekdayAbbreviated(time.Sunday))
	fmt.Println(l.WeekdayAbbreviated(time.Monday))
	fmt.Println(l.WeekdayAbbreviated(time.Tuesday))
	// ...

	// Weekdays Short
	fmt.Println(l.WeekdayShort(time.Sunday))
	fmt.Println(l.WeekdayShort(time.Monday))
	fmt.Println(l.WeekdayShort(time.Tuesday))
	// ...

	// Weekdays Narrow
	fmt.Println(l.WeekdayNarrow(time.Sunday))
	fmt.Println(l.WeekdayNarrow(time.Monday))
	fmt.Println(l.WeekdayNarrow(time.Tuesday))
	// ...

	var f64 float64

	f64 = -10356.4523

	// Number
	fmt.Println(l.FmtNumber(f64, 2))

	// Currency
	fmt.Println(l.FmtCurrency(f64, 2, currency.CAD))
	fmt.Println(l.FmtCurrency(f64, 2, currency.USD))

	// Accounting
	fmt.Println(l.FmtAccounting(f64, 2, currency.CAD))
	fmt.Println(l.FmtAccounting(f64, 2, currency.USD))

	f64 = 78.12

	// Percent
	fmt.Println(l.FmtPercent(f64, 0))

	// Plural Rules for locale, so you know what rules you must cover
	fmt.Println(l.PluralsCardinal())
	fmt.Println(l.PluralsOrdinal())

	// Cardinal Plural Rules
	fmt.Println(l.CardinalPluralRule(1, 0))
	fmt.Println(l.CardinalPluralRule(1.0, 0))
	fmt.Println(l.CardinalPluralRule(1.0, 1))
	fmt.Println(l.CardinalPluralRule(3, 0))

	// Ordinal Plural Rules
	fmt.Println(l.OrdinalPluralRule(21, 0)) // 21st
	fmt.Println(l.OrdinalPluralRule(22, 0)) // 22nd
	fmt.Println(l.OrdinalPluralRule(33, 0)) // 33rd
	fmt.Println(l.OrdinalPluralRule(34, 0)) // 34th

	// Range Plural Rules
	fmt.Println(l.RangePluralRule(1, 0, 1, 0)) // 1-1
	fmt.Println(l.RangePluralRule(1, 0, 2, 0)) // 1-2
	fmt.Println(l.RangePluralRule(5, 0, 8, 0)) // 5-8
}

NOTES:

These rules were generated from the Unicode CLDR Project, if you encounter any issues I strongly encourage contributing to the CLDR project to get the locale information corrected and the next time these locales are regenerated the fix will come with.

I do however realize that time constraints are often important and so there are two options:

  1. Create your own locale, copy, paste and modify, and ensure it complies with the Translator interface.
  2. Add an exception in the locale generation code directly and once regenerated, fix will be in place.

Please to not make fixes inside the locale files, they WILL get overwritten when the locales are regenerated.

License

Distributed under MIT License, please see license file in code for more details.

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	DurationShort DurationMode = iota
	DurationLong

	HoursInDay   = 24
	HoursInMonth = HoursInDay * 30
	HoursInYear  = HoursInMonth * 12
)

Variables ¶

View Source
var (
	DefaultAndListJoinPattern = NewListPattern("{0} and {1}", "{0}, {1}", "{0}, {1}", "{0} and {1}")
	DefaultOrListJoinPattern  = NewListPattern("{0} or {1}", "{0}, {1}", "{0}, {1}", "{0} or {1}")
)
View Source
var ComputedNumberFormatOptions = NumberFormatOptions{
	Decimal: ".",
	Group:   "",
	Minus:   "-",
}
View Source
var DefaultDurationSpec = DurationSpec{
	LongSep:  " ",
	ShortSep: "",
	Year: DurationSpecPair{
		Masculine,
		&CounterFormat{
			Other: "%vY",
			Per:   "%v/Y",
		},
		&CounterFormat{
			"Years",
			"%d year",
			"%d years",
			"%v per year",
		},
	},
	Month: DurationSpecPair{
		Masculine,
		&CounterFormat{
			Other: "%vM",
			Per:   "%v/M",
		},
		&CounterFormat{
			"Months",
			"%d month",
			"%d months",
			"%v per month",
		},
	},
	Day: DurationSpecPair{
		Masculine,
		&CounterFormat{
			Other: "%vd",
			Per:   "%v/d",
		},
		&CounterFormat{
			"Days",
			"%d day",
			"%d days",
			"%v per day",
		},
	},
	Hour: DurationSpecPair{
		Masculine,
		&CounterFormat{
			Other: "%dh",
			Per:   "%v/h",
		},
		&CounterFormat{
			"Hours",
			"%d hour",
			"%d hours",
			"%v per hour",
		},
	},
	Minute: DurationSpecPair{
		Masculine,
		&CounterFormat{
			Other: "%dm",
			Per:   "%v/m",
		},
		&CounterFormat{
			"minutes",
			"%d minute",
			"%d minutes",
			"%v per minute",
		},
	},
	Second: DurationSpecPair{
		Masculine,
		&CounterFormat{
			Label: "sec",
			Other: "%vs",
			Per:   "%v/s",
		},
		&CounterFormat{
			"Seconds",
			"%v second",
			"%v seconds",
			"%v per second",
		},
	},
}
View Source
var NumberForamtters = map[reflect.Type]NumberFormatter{
	reflect.TypeOf(big.Rat{}): func(value interface{}, precision int, minus, thousand string, decimalStr string) string {
		var rat, _ = value.(*big.Rat)
		if rat == nil {
			var v2 any = value
			rat = v2.(*big.Rat)
		}

		if precision > 0 {
			return value.(*big.Rat).FloatString(precision)
		} else {
			return value.(*big.Rat).String()
		}
	},

	reflect.TypeOf(decimal.Decimal{}): func(value interface{}, precision int, minus, thousand string, decimalStr string) string {
		if precision > 0 {
			return value.(*decimal.Decimal).StringFixed(int32(precision))
		} else {
			return value.(*decimal.Decimal).String()
		}
	},
}

Functions ¶

func F ¶

func F(n float64, v uint64) (f int64)

F returns the visible fractional digits in N, with trailing zeros.

func FmtAccounting ¶

func FmtAccounting(t CurrencyWithNumberTranslator, level CurrencyLevel, currency currency.Type, num decimal.Decimal, precision int) string

FmtAccounting returns the currency representation of 'num' with digits/precision of 'v' for 'pt' in accounting notation.

func FmtCurrency ¶

func FmtCurrency(t CurrencyWithNumberTranslator, level CurrencyLevel, currency currency.Type, num decimal.Decimal, precision int) string

FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for 'pt'

func FormatNumber ¶

func FormatNumber(value interface{}, precision int, minus, thousand string, decimalStr string) string

FormatNumber is a base function of the library which formats a number with custom precision and separators. FormatNumber supports various types of value by runtime reflection. If you don't need runtime type evaluation, please refer to FormatNumberInt or FormatNumberFloat64. (supported value types : int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, *big.Rat) (also supported value types : decimal.Decimal, *decimal.Decimal *apd.Decimal)

func FormatNumberString ¶

func FormatNumberString(x string, precision int, minus, thousand string, decimalStr string) string

func FormatNumberT ¶

func FormatNumberT(t Translator, value interface{}, precision int) string

func FormatTime ¶

func FormatTime(t TimeTranslator, format string, T time.Time) string

func FormatTimeEra ¶

func FormatTimeEra(t TimeTranslator, format string, T time.Time, eraScore int8) string

func T ¶

func T(n float64, v uint64) (t int64)

T returns the visible fractional digits in N, without trailing zeros.

func UnformatNumber ¶

func UnformatNumber(t Translator, n string, precision int) string

UnformatNumber takes a string of the number to strip currency info on and precision for decimals. It pulls the currency descripter from the LocaleInfo map and uses it to return an unformatted value based on thous sep and decimal sep

func W ¶

func W(n float64, v uint64) (w int64)

W returns the number of visible fraction digits in N, without trailing zeros.

Types ¶

type CounterFormat ¶

type CounterFormat struct {
	Label, One, Other, Per string
}

func (*CounterFormat) Dump ¶

func (f *CounterFormat) Dump(pkg string, out io.Writer)

func (*CounterFormat) Get ¶

func (f *CounterFormat) Get(qnt uint64, defaul ...*CounterFormat) (v string)

func (*CounterFormat) GetF ¶

func (f *CounterFormat) GetF(qnt float64, defaul ...*CounterFormat) (v string)

func (*CounterFormat) Perf ¶

func (f *CounterFormat) Perf(qnt any) (v string)

type Currency ¶

type Currency struct {
	Names   map[PluralRule]string
	Symbols CurrencySymbols
}

type CurrencyAccountingFormatterByExp ¶

type CurrencyAccountingFormatterByExp struct {
	CurrencyFmt   map[uint8]*CurrencyAccountingFormatterByExpPlural
	AccountingFmt map[uint8]*CurrencyAccountingFormatterByExpPlural
}

func (*CurrencyAccountingFormatterByExp) Dump ¶

type CurrencyAccountingFormatterByExpPlural ¶

type CurrencyAccountingFormatterByExpPlural struct {
	Rules map[PluralRule]*NumberFormatProperties
}

func (*CurrencyAccountingFormatterByExpPlural) Dump ¶

type CurrencyFormat ¶

type CurrencyFormat struct {
	Raw                   string
	ThousandsLen          int
	DigitsLen             int
	SecondaryThousandsLen int
	MinDecimalLen         int
	SymbolDirection       Direction
	SymbolPrefix          string
	SymbolSuffix          string
	Prefix                string
	Suffix                string
}

func (*CurrencyFormat) Dump ¶

func (f *CurrencyFormat) Dump(pkg string, out io.Writer)

func (*CurrencyFormat) Exec ¶

func (f *CurrencyFormat) Exec(symbol, value string) string

func (*CurrencyFormat) Format ¶

func (f *CurrencyFormat) Format(t NumberTranslator, cur *Currency, num string, v uint64) string

Format returns the currency representation of 'num' with digits/precision of 'v' for '{{ .Locale }}'

func (*CurrencyFormat) Parse ¶

func (f *CurrencyFormat) Parse(numberFormat string)

type CurrencyFormatters ¶

type CurrencyFormatters struct {
	CurrencyFmt,
	AccountingFmt *NumberFormatProperties

	Short CurrencyAccountingFormatterByExp
}

func (*CurrencyFormatters) Accounting ¶

func (*CurrencyFormatters) Currency ¶

func (*CurrencyFormatters) Dump ¶

func (f *CurrencyFormatters) Dump(pkg string, out io.Writer)

func (*CurrencyFormatters) Format ¶

func (*CurrencyFormatters) GetAccounting ¶

func (*CurrencyFormatters) GetCurrency ¶

func (*CurrencyFormatters) IsZero ¶

func (f *CurrencyFormatters) IsZero() bool

type CurrencyLevel ¶

type CurrencyLevel uint8
const (
	CurrencyLong CurrencyLevel = iota
	CurrencyShort
)

type CurrencySpec ¶

type CurrencySpec struct {
	CurrenciesValue []Currency
	Formatters      *CurrencyFormatters
}

func (*CurrencySpec) Currencies ¶

func (c *CurrencySpec) Currencies() []Currency

func (*CurrencySpec) CurrencyFormatters ¶

func (c *CurrencySpec) CurrencyFormatters() *CurrencyFormatters

type CurrencySymbolLevel ¶

type CurrencySymbolLevel uint8
const (
	CurrencySymbolStd CurrencySymbolLevel = 1 + iota
	CurrencySymbolISO
	CurrencySymbolName
	CurrencySymbolNarrow
)

type CurrencySymbols ¶

type CurrencySymbols struct {
	Default string
	Narrow  string
}

type CurrencyTranslator ¶

type CurrencyTranslator interface {
	Currencies() []Currency

	CurrencyFormatters() *CurrencyFormatters
}

type CurrencyWithNumberTranslator ¶

type CurrencyWithNumberTranslator interface {
	CurrencyTranslator
	NumberTranslator
}

type Direction ¶

type Direction uint8
const (
	Left Direction = iota
	Right
)

type DurationMode ¶

type DurationMode uint8

type DurationSpec ¶

type DurationSpec struct {
	LongSep, ShortSep string
	Century           DurationSpecPair
	Decade            DurationSpecPair
	Year              DurationSpecPair
	Month             DurationSpecPair
	Week              DurationSpecPair
	Day               DurationSpecPair
	Hour              DurationSpecPair
	Minute            DurationSpecPair
	Second            DurationSpecPair
	Millisecond       DurationSpecPair
	Microsecond       DurationSpecPair
	Nanosecond        DurationSpecPair
}

func (*DurationSpec) Dump ¶

func (s *DurationSpec) Dump(pkg string, out io.Writer)

func (*DurationSpec) Format ¶

func (d *DurationSpec) Format(mode DurationMode, dur time.Duration) string

type DurationSpecPair ¶

type DurationSpecPair struct {
	Gender      Gender
	Short, Long *CounterFormat
}

func (*DurationSpecPair) Dump ¶

func (s *DurationSpecPair) Dump(pkg string, out io.Writer)

func (*DurationSpecPair) Of ¶

type DurationSpecValue ¶

type DurationSpecValue struct {
	D    time.Duration
	Spec *DurationSpec
}

func (DurationSpecValue) Format ¶

func (d DurationSpecValue) Format(f fmt.State, verb rune)

type DurationTranslator ¶

type DurationTranslator interface {
	GetDurationSpec() *DurationSpec
}

type DurationValue ¶

type DurationValue struct {
	Translator Translator
	Value      time.Duration
}

func (DurationValue) Format ¶

func (d DurationValue) Format(f fmt.State, verb rune)

type Gender ¶

type Gender uint8
const (
	Masculine Gender = iota
	Feminine
)

func (Gender) String ¶

func (g Gender) String() string

type JoinType ¶

type JoinType uint8
const (
	And JoinType = iota
	Or
)

type ListJoinToken ¶

type ListJoinToken uint8
const (
	ListJoinA ListJoinToken = iota
	ListJoinSep
	ListJoinB
)

func (ListJoinToken) String ¶

func (t ListJoinToken) String() string

type ListPattern ¶

type ListPattern struct {
	Two,
	Start,
	Middle,
	End *ListPatternSpec
}

func NewListPattern ¶

func NewListPattern(two, start, middle, end string) *ListPattern

func NewListPatternFromSlice ¶

func NewListPatternFromSlice(def []string) *ListPattern

func (*ListPattern) FormatTo ¶

func (p *ListPattern) FormatTo(w io.Writer, itens ...string)

func (*ListPattern) ToSlice ¶

func (p *ListPattern) ToSlice() []string

type ListPatternSpec ¶

type ListPatternSpec struct {
	Pattern string
	Sep     string
	Tokens  [3]ListJoinToken
}

func NewListPatternSpec ¶

func NewListPatternSpec(pattern string) *ListPatternSpec

func (*ListPatternSpec) Format ¶

func (s *ListPatternSpec) Format(itens ...string) string

func (*ListPatternSpec) String ¶

func (s *ListPatternSpec) String() string

type ListPatterns ¶

type ListPatterns struct {
	AndP, OrP *ListPattern
}

func NewListPatternsFromSlice ¶

func NewListPatternsFromSlice(s [][]string) *ListPatterns

func (*ListPatterns) And ¶

func (p *ListPatterns) And(w io.Writer, itens ...string)

func (*ListPatterns) AndS ¶

func (p *ListPatterns) AndS(itens ...string) string

func (*ListPatterns) Do ¶

func (p *ListPatterns) Do(w io.Writer, typ JoinType, itens ...string)

func (*ListPatterns) DoS ¶

func (p *ListPatterns) DoS(typ JoinType, itens ...string) string

func (*ListPatterns) Or ¶

func (p *ListPatterns) Or(w io.Writer, itens ...string)

func (*ListPatterns) OrS ¶

func (p *ListPatterns) OrS(itens ...string) string

func (*ListPatterns) ToSlice ¶

func (f *ListPatterns) ToSlice() [][]string

type MiscPatterns ¶

type MiscPatterns struct {
	Approximately,
	AtLeast,
	AtMost,
	Range string
}

type NumberFlag ¶

type NumberFlag uint8
const (
	PercentNumber NumberFlag = 1 + iota
	MilleNumber
	CurrencyNumber
)

type NumberFormatOptions ¶

type NumberFormatOptions struct {
	Minus                    string
	Group                    string
	Decimal                  string
	Symbol                   string
	Infinity                 string
	Percent                  string
	Zero                     string
	Precision                int
	DefaultPrecisionDisabled bool
}

type NumberFormatProperties ¶

type NumberFormatProperties struct {
	Pos,
	Neg NumberPatternProperties
}

func MustParseNumberFormatPatterns ¶

func MustParseNumberFormatPatterns(pattern string) *NumberFormatProperties

func (NumberFormatProperties) Dump ¶

func (f NumberFormatProperties) Dump(pkg string, out io.Writer)

func (*NumberFormatProperties) Format ¶

func (*NumberFormatProperties) FormatAny ¶

func (f *NumberFormatProperties) FormatAny(value any, opts NumberFormatOptions) (s string, err error)

func (*NumberFormatProperties) FormatS ¶

func (f *NumberFormatProperties) FormatS(s string, opts NumberFormatOptions) (ret string)

func (*NumberFormatProperties) Parse ¶

func (p *NumberFormatProperties) Parse(value string) (err error)

func (NumberFormatProperties) String ¶

func (f NumberFormatProperties) String() string

type NumberFormatter ¶

type NumberFormatter func(value interface{}, precision int, minus, thousand string, decimalStr string) string

type NumberPatternProperties ¶

type NumberPatternProperties struct {
	// Pattern Raw pattern value
	Pattern string

	Prefix string
	Padding,
	ScientificNotation string

	// MinimumIntegerDigits non-negative integer Number value indicating the minimum integer
	//        digits to be used. Numbers will be padded with leading zeroes if necessary.
	MinimumIntegerDigits,

	MinimumFractionDigits,
	MaximumFractionDigits,

	MinimumSignificantDigits,
	MaximumSignificantDigits,
	PrimaryGroupingSize,
	SecondaryGroupingSize int
	Suffix string

	// RoundIncrement Decimal round increment or null
	RoundIncrement float64

	Type NumberFlag

	CurrencySymbol CurrencySymbolLevel

	DivExp uint8
}

func (NumberPatternProperties) Dump ¶

func (f NumberPatternProperties) Dump(pkg string, out io.Writer)

func (*NumberPatternProperties) Format ¶

func (f *NumberPatternProperties) Format(value decimal.Decimal, opts NumberFormatOptions) (ret string)

func (*NumberPatternProperties) FormatS ¶

func (f *NumberPatternProperties) FormatS(s string, opts NumberFormatOptions) (ret string)

func (NumberPatternProperties) Neg ¶

func (*NumberPatternProperties) Parse ¶

func (p *NumberPatternProperties) Parse(pattern string) (err error)

*

func (*NumberPatternProperties) Template ¶

func (f *NumberPatternProperties) Template(opts NumberFormatOptions) (prefix, suffix string, precision int)

type NumberSpec ¶

type NumberSpec struct {
	GroupValue,
	DecimalValue,
	MinusValue string
}

func (*NumberSpec) Decimal ¶

func (n *NumberSpec) Decimal() string

func (*NumberSpec) Group ¶

func (n *NumberSpec) Group() string

func (*NumberSpec) Minus ¶

func (n *NumberSpec) Minus() string

type NumberTranslator ¶

type NumberTranslator interface {
	Group() string

	Decimal() string

	Minus() string
}

type PluralRule ¶

type PluralRule int

PluralRule denotes the type of plural rules

const (
	PluralRuleUnknown PluralRule = iota
	PluralRuleZero               // zero
	PluralRuleOne                // one - singular
	PluralRuleTwo                // two - dual
	PluralRuleFew                // few - paucal
	PluralRuleMany               // many - also used for fractions if they have a separate class
	PluralRuleOther              // other - required—general plural form—also used if the language only has a single form
)

PluralRule's

func (PluralRule) String ¶

func (p PluralRule) String() string

String returns the string value of PluralRule

type TimeRangeValue ¶

type TimeRangeValue struct {
	Translator Translator
	Formatter  TimestampFormat
	From, To   time.Time
}

func NewTimeRangeValue ¶

func NewTimeRangeValue(translator Translator, from time.Time, to time.Time) *TimeRangeValue

func NewdDateRangeValue ¶

func NewdDateRangeValue(translator Translator, from time.Time, to time.Time) *TimeRangeValue

func (TimeRangeValue) Format ¶

func (t TimeRangeValue) Format(f fmt.State, verb rune)

func (TimeRangeValue) ToString ¶

func (t TimeRangeValue) ToString() string

type TimeSpec ¶

type TimeSpec struct {
	Separator string

	// returns the locales wide months
	MonthsWideValue []string

	// returns the locales abbreviated months
	MonthsAbbreviatedValue []string

	// returns the locales narrow months
	MonthsNarrowValue []string

	// returns the locales wide weekdays
	WeekdaysWideValue []string

	// returns the locales abbreviated weekdays
	WeekdaysAbbreviatedValue []string

	// WeekdaysNarrowreturns the locales narrow weekdays
	WeekdaysNarrowValue []string

	// returns the locales short weekdays
	WeekdaysShortValue []string

	PeriodsAbbreviatedValue []string

	PeriodsShortValue []string

	PeriodsNarrowValue []string

	PeriodsWideValue []string

	ErasWideValue []string

	ErasAbbreviatedValue []string

	ErasNarrowValue []string

	TimezonesValue map[string]string
}

func (*TimeSpec) ErasAbbreviated ¶

func (t *TimeSpec) ErasAbbreviated() []string

func (*TimeSpec) ErasNarrow ¶

func (t *TimeSpec) ErasNarrow() []string

func (*TimeSpec) ErasWide ¶

func (t *TimeSpec) ErasWide() []string

func (*TimeSpec) MonthAbbreviated ¶

func (t *TimeSpec) MonthAbbreviated(m time.Month) string

func (*TimeSpec) MonthNarrow ¶

func (t *TimeSpec) MonthNarrow(m time.Month) string

func (*TimeSpec) MonthWide ¶

func (t *TimeSpec) MonthWide(m time.Month) string

func (*TimeSpec) MonthsAbbreviated ¶

func (t *TimeSpec) MonthsAbbreviated() []string

func (*TimeSpec) MonthsNarrow ¶

func (t *TimeSpec) MonthsNarrow() []string

func (*TimeSpec) MonthsWide ¶

func (t *TimeSpec) MonthsWide() []string

func (*TimeSpec) PeriodsAbbreviated ¶

func (t *TimeSpec) PeriodsAbbreviated() []string

func (*TimeSpec) PeriodsNarrow ¶

func (t *TimeSpec) PeriodsNarrow() []string

func (*TimeSpec) PeriodsShort ¶

func (t *TimeSpec) PeriodsShort() []string

func (*TimeSpec) PeriodsWide ¶

func (t *TimeSpec) PeriodsWide() []string

func (*TimeSpec) TimeSeparator ¶

func (t *TimeSpec) TimeSeparator() string

func (*TimeSpec) Timezones ¶

func (t *TimeSpec) Timezones() map[string]string

func (*TimeSpec) WeekdayAbbreviated ¶

func (t *TimeSpec) WeekdayAbbreviated(d time.Weekday) string

func (*TimeSpec) WeekdayNarrow ¶

func (t *TimeSpec) WeekdayNarrow(d time.Weekday) string

func (*TimeSpec) WeekdayShort ¶

func (t *TimeSpec) WeekdayShort(d time.Weekday) string

func (*TimeSpec) WeekdayWide ¶

func (t *TimeSpec) WeekdayWide(d time.Weekday) string

func (*TimeSpec) WeekdaysAbbreviated ¶

func (t *TimeSpec) WeekdaysAbbreviated() []string

func (*TimeSpec) WeekdaysNarrow ¶

func (t *TimeSpec) WeekdaysNarrow() []string

func (*TimeSpec) WeekdaysShort ¶

func (t *TimeSpec) WeekdaysShort() []string

func (*TimeSpec) WeekdaysWide ¶

func (t *TimeSpec) WeekdaysWide() []string

type TimeTranslator ¶

type TimeTranslator interface {
	TimeSeparator() string

	// returns the locales wide months
	MonthsWide() []string
	MonthWide(time.Month) string

	// returns the locales abbreviated months
	MonthsAbbreviated() []string
	MonthAbbreviated(time.Month) string

	// returns the locales narrow months
	MonthsNarrow() []string
	MonthNarrow(time.Month) string

	// returns the locales wide weekdays
	WeekdaysWide() []string
	WeekdayWide(d time.Weekday) string

	// returns the locales abbreviated weekdays
	WeekdaysAbbreviated() []string
	WeekdayAbbreviated(d time.Weekday) string

	// WeekdaysNarrowreturns the locales narrow weekdays
	WeekdaysNarrow() []string
	WeekdayNarrow(d time.Weekday) string

	// returns the locales short weekdays
	WeekdaysShort() []string
	WeekdayShort(d time.Weekday) string

	PeriodsAbbreviated() []string
	PeriodsShort() []string
	PeriodsWide() []string
	PeriodsNarrow() []string

	ErasWide() []string
	ErasAbbreviated() []string
	ErasNarrow() []string

	Timezones() map[string]string

	// returns the short date representation of 't' for locale
	FmtDateShort(t time.Time) string

	// returns the medium date representation of 't' for locale
	FmtDateMedium(t time.Time) string

	//  returns the long date representation of 't' for locale
	FmtDateLong(t time.Time) string

	// returns the full date representation of 't' for locale
	FmtDateFull(t time.Time) string

	// returns the short time representation of 't' for locale
	FmtTimeShort(t time.Time) string

	// returns the medium time representation of 't' for locale
	FmtTimeMedium(t time.Time) string

	// returns the long time representation of 't' for locale
	FmtTimeLong(t time.Time) string

	// returns the full time representation of 't' for locale
	FmtTimeFull(t time.Time) string

	// DateFullLayout returns the full date layout for '{{ .Locale }}'
	DateFullLayout() string

	// DateLongLayout returns the long date layout for '{{ .Locale }}'
	DateLongLayout() string

	// DateMediumLayout returns the medium date layout for '{{ .Locale }}'
	DateMediumLayout() string

	// DateShortLayout returns the short date layout for '{{ .Locale }}'
	DateShortLayout() string

	// TimeFullLayout returns the full time layout for '{{ .Locale }}'
	TimeFullLayout() string

	// TimeLongLayout returns the full long layout for '{{ .Locale }}'
	TimeLongLayout() string

	// TimeMediumLayout returns the medium time layout for '{{ .Locale }}'
	TimeMediumLayout() string

	// TimeShortLayout returns the short time layout for '{{ .Locale }}'
	TimeShortLayout() string
}

type TimeValue ¶

type TimeValue struct {
	Translator TimeTranslator
	Formatter  TimestampFormat
	Value      time.Time
}

func NewDateTimeValue ¶

func NewDateTimeValue(translator TimeTranslator, value time.Time) *TimeValue

func NewDateValue ¶

func NewDateValue(translator TimeTranslator, value time.Time) *TimeValue

func NewTimeValue ¶

func NewTimeValue(translator TimeTranslator, value time.Time) *TimeValue

func (TimeValue) Format ¶

func (t TimeValue) Format(f fmt.State, verb rune)

func (TimeValue) ToString ¶

func (t TimeValue) ToString() string

type TimestampFormat ¶

type TimestampFormat uint8
const (
	TFNone TimestampFormat = 0
	TFDate TimestampFormat = 1 << iota
	TFTime
	TFFull
	TFLong
	TFMedium
	TFShort
	TFTimeFirst

	DateTime = TFDate | TFTime
)

func (TimestampFormat) Clear ¶

func (*TimestampFormat) EraScore ¶

func (f *TimestampFormat) EraScore() int8

func (TimestampFormat) Format ¶

func (f TimestampFormat) Format(Tr TimeTranslator, t time.Time) string

func (TimestampFormat) FormatSep ¶

func (f TimestampFormat) FormatSep(Tr TimeTranslator, t time.Time, dateTimeSep string) string

func (TimestampFormat) Has ¶

func (f TimestampFormat) Has(flag TimestampFormat) bool

func (TimestampFormat) Layout ¶

func (f TimestampFormat) Layout() TimestampFormat

func (TimestampFormat) Layouts ¶

func (f TimestampFormat) Layouts(t TimeTranslator) (s []string)

func (*TimestampFormat) Parse ¶

func (f *TimestampFormat) Parse(s string)

func (*TimestampFormat) ParseAppend ¶

func (f *TimestampFormat) ParseAppend(p string)

func (*TimestampFormat) ParseAppendArray ¶

func (f *TimestampFormat) ParseAppendArray(p ...string)

func (TimestampFormat) Set ¶

func (*TimestampFormat) String ¶

func (f *TimestampFormat) String() string

func (TimestampFormat) Toggle ¶

type Translator ¶

type Translator interface {

	// Locale returns the string value of the translator
	Locale() string

	// returns an array of cardinal plural rules associated
	// with this translator
	PluralsCardinal() []PluralRule

	// returns an array of ordinal plural rules associated
	// with this translator
	PluralsOrdinal() []PluralRule

	// returns an array of range plural rules associated
	// with this translator
	PluralsRange() []PluralRule

	// returns the cardinal PluralRule given 'num' and digits/precision of 'v' for locale
	CardinalPluralRule(num float64, v uint64) PluralRule

	// returns the ordinal PluralRule given 'num' and digits/precision of 'v' for locale
	OrdinalPluralRule(num float64, v uint64) PluralRule

	// returns the ordinal PluralRule given 'num1', 'num2' and digits/precision of 'v1' and 'v2' for locale
	RangePluralRule(num1 float64, v1 uint64, num2 float64, v2 uint64) PluralRule

	ListPatterns() *ListPatterns

	GetMiscPatterns() *MiscPatterns

	NumberTranslator
	CurrencyTranslator
	TimeTranslator
	DurationTranslator
}

Translator encapsulates an instance of a locale NOTE: some values are returned as a []byte just in case the caller wishes to add more and can help avoid allocations; otherwise just cast as string

type TranslatorSpec ¶

type TranslatorSpec struct {
}

Directories ¶

Path Synopsis
named
af
agq
ak
am
ar
as
asa
ast
az
bas
be
bem
bez
bg
bm
bn
bo
br
brx
bs
ca
ccp
ce
ceb
cgg
chr
ckb
cs
cy
da
dav
de
dje
doi
dsb
dua
dyo
dz
ebu
ee
el
en
eo
es
et
eu
ewo
fa
ff
fi
fil
fo
fr
fur
fy
ga
gd
gl
gsw
gu
guz
gv
ha
haw
he
hi
hr
hsb
hu
hy
ia
id
ig
ii
is
it
ja
jgo
jmc
jv
ka
kab
kam
kde
kea
kgp
khq
ki
kk
kkj
kl
kln
km
kn
ko
kok
ks
ksb
ksf
ksh
ku
kw
ky
lag
lb
lg
lkt
ln
lo
lrc
lt
lu
luo
luy
lv
mai
mas
mer
mfe
mg
mgh
mgo
mi
mk
ml
mn
mni
mr
ms
mt
mua
my
mzn
naq
nb
nd
nds
ne
nl
nmg
nn
nnh
no
nus
nyn
om
or
os
pa
pcm
pl
ps
pt
qu
rm
rn
ro
rof
ru
rw
rwk
sa
sah
saq
sat
sbp
sc
sd
se
seh
ses
sg
shi
si
sk
sl
smn
sn
so
sq
sr
su
sv
sw
ta
te
teo
tg
th
ti
tk
to
tr
tt
twq
tzm
ug
uk
ur
uz
vai
vi
vun
wae
wo
xh
xog
yav
yi
yo
yrl
yue
zgh
zh
zu

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL