Documentation ¶
Index ¶
- func GetLocaleData(tag language.Tag) (*cldr.Locale, error)
- func NamedParameters(format string, params FmtParams) string
- type FmtParams
- type Locale
- func (l *Locale) CountTranslations() int
- func (l *Locale) DisplayName(tag language.Tag) string
- func (l *Locale) FmtCurrency(currency string, number interface{}) (formatted string, err error)
- func (l *Locale) FmtCurrencyWhole(currency string, number interface{}) (formatted string, err error)
- func (l *Locale) FmtDateFull(tim time.Time) (string, error)
- func (l *Locale) FmtDateLong(tim time.Time) (string, error)
- func (l *Locale) FmtDateMedium(tim time.Time) (string, error)
- func (l *Locale) FmtDateShort(tim time.Time) (string, error)
- func (l *Locale) FmtDateTimeFull(tim time.Time) (string, error)
- func (l *Locale) FmtDateTimeLong(tim time.Time) (string, error)
- func (l *Locale) FmtDateTimeMedium(tim time.Time) (string, error)
- func (l *Locale) FmtDateTimeShort(tim time.Time) (string, error)
- func (l *Locale) FmtNumber(number interface{}) string
- func (l *Locale) FmtNumberWhole(number interface{}) string
- func (l *Locale) FmtPercent(number interface{}) string
- func (l *Locale) FmtTimeFull(tim time.Time) (string, error)
- func (l *Locale) FmtTimeLong(tim time.Time) (string, error)
- func (l *Locale) FmtTimeMedium(tim time.Time) (string, error)
- func (l *Locale) FmtTimeShort(tim time.Time) (string, error)
- func (l *Locale) Get(key string) string
- func (l *Locale) GetPlural(pluralID string, number interface{}, vars ...interface{}) string
- func (l *Locale) GetTranslations() map[string]store.Translation
- func (l *Locale) Load(source store.TranslationStore) error
- func (l *Locale) NewPrinter() *message.Printer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLocaleData ¶
GetLocaleData finds the best match for tag and returns a *cldr.Locale, which contains data populated from the Unicode CLDR.
func NamedParameters ¶
NamedParameters does string formatting on python-style format strings like "Hello %(name)s".
Types ¶
type FmtParams ¶
type FmtParams map[string]interface{}
FmtParams contains substitutions for python-style format strings
type Locale ¶
type Locale struct { Tag language.Tag Number cldr.Number Calendar cldr.Calendar Plural cldr.Plural Languages cldr.Languages Territories cldr.Territories DisplayPattern cldr.LocaleDisplayPattern // contains filtered or unexported fields }
Locale is the struct providing access to most of the localizer features
func GetLocale ¶
GetLocale returns a pointer to an existing, already-loaded locale (or nil if if doesn't exist)
func NewLocale ¶
NewLocale instantiates a new Locale for the supplied language tag. It does not load any translations, so it's useful when you only need to use the CLDR data (number/calendar etc). Use NewLocaleWithStore to load translations at initialization time, or call Load on the Locale returned by this function.
func NewLocaleWithStore ¶ added in v0.0.3
NewLocaleWithStore instantiates a new Locale for the supplied language tag. It loads the translations from the source store.TranslationStore. Use this if you know you want your Locale to be populated with translations.
func (*Locale) CountTranslations ¶ added in v0.0.8
CountTranslations returns the number of translations currently loaded in this locale.
func (*Locale) DisplayName ¶ added in v0.0.9
DisplayName returns the formatted display name for the provided language tag in the locale.
Example ¶
loc, _ := NewLocale(language.Spanish) fmt.Println(loc.DisplayName(language.English))
Output: inglés
func (*Locale) FmtCurrency ¶
FmtCurrency returns the number formatted as a currency for the locale, e.g. "$123.45"
func (*Locale) FmtCurrencyWhole ¶
func (l *Locale) FmtCurrencyWhole(currency string, number interface{}) (formatted string, err error)
FmtCurrencyWhole returns the number formatted as a currency for the locale, excluding any decimal portion, e.g. "$123"
func (*Locale) FmtDateFull ¶
FmtDateFull returns the CLDR Full form of the date, e.g. "Tuesday, September 14, 1999" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtDateLong ¶
FmtDateLong returns the CLDR Long form of the date, e.g. "September 14, 1999" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtDateMedium ¶
FmtDateMedium returns the CLDR Medium form of the date, e.g. "Sep 14, 1999" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtDateShort ¶
FmtDateShort returns the CLDR Short form of the date, e.g. "9/14/99" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtDateTimeFull ¶
FmtDateTimeFull returns the CLDR Full form of the date and time, e.g. "Tuesday, September 14, 1999 at 1:04:20 PM GMT+00:00" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtDateTimeLong ¶
FmtDateTimeLong returns the CLDR Long form of the date and time, e.g. "September 14, 1999 at 1:04:20 PM GMT+00:00" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtDateTimeMedium ¶
FmtDateTimeMedium returns the CLDR Medium form of the date and time, e.g. "Sep 14, 1999, 1:04:20 PM" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtDateTimeShort ¶
FmtDateTimeShort returns the CLDR Short form of the date and time, e.g. "9/14/99, 1:04 PM" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtNumber ¶
FmtNumber returns the number formatted for the locale, e.g. "123.45" or "123,45"
func (*Locale) FmtNumberWhole ¶
FmtNumberWhole returns the number formatted for the locale, excluding any decimal portion, e.g. "123.45" or "123,45"
func (*Locale) FmtPercent ¶
FmtPercent returns the number formatted as a percentage for the locale, e.g. 0.09 would return "9 %"
func (*Locale) FmtTimeFull ¶
FmtTimeFull returns the CLDR Full form of the time, e.g. "1:04:20 PM GMT+00:00" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtTimeLong ¶
FmtTimeLong returns the CLDR Long form of the time, e.g. "1:04:20 PM GMT+00:00" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtTimeMedium ¶
FmtTimeMedium returns the CLDR Medium form of the time, e.g. "1:04:20 PM" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) FmtTimeShort ¶
FmtTimeShort returns the CLDR Short form of the time, e.g. "1:04 PM" see http://cldr.unicode.org/translation/date-time-1/date-time-patterns for more information
func (*Locale) GetPlural ¶
GetPlural determines which plural form should be used for the supplied number. number can be an int type (including int64) or a float formatted as a string. It then determines which plural form should be used by calling the cldr plural function, and returns the corresponding plural translation, formatted with the optional vars.
func (*Locale) GetTranslations ¶ added in v0.0.3
func (l *Locale) GetTranslations() map[string]store.Translation
GetTranslations returns the entire catalog of translations currently loaded for this locale. This allows for enumeration of the catalog. Note that it returns a copy so that the internal store can continue to be protected by mutexes.
func (*Locale) Load ¶
func (l *Locale) Load(source store.TranslationStore) error
Load retrieves all translations from the supplied store.TranslationStore and prepares them for use in this Locale.
func (*Locale) NewPrinter ¶
NewPrinter creates a message.Printer for the Locale