i18n

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package i18n defines internationalization and localization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocaleMap

type LocaleMap struct {
	// contains filtered or unexported fields
}

LocaleMap is a map of locale names to their data structure.

func Load

func Load(pth string, opts ...Option) (*LocaleMap, error)

Load parses and loads the localization files from disk. It builds the locale matcher based on the currently available data (organized by folder).

Due to the heavy I/O, callers should cache the resulting value and only call Load when data needs to be refreshed.

func (*LocaleMap) Canonicalize

func (l *LocaleMap) Canonicalize(id string) (string, error)

Canonicalize converts the given ID to the expected name.

func (*LocaleMap) Lookup

func (l *LocaleMap) Lookup(ids ...string) *gotext.Locale

Lookup finds the best locale for the given ids. If none exists, the default locale is used.

If reloading is enabled, the locales are reloaded before lookup. If reloading fails, it panics. For this reason, you should not enable reloading in production.

type Option

type Option func(*LocaleMap) *LocaleMap

Option is an option to creating a locale map.

func WithReloading

func WithReloading(v bool) Option

WithReloading enables hot reloading for the map.

Jump to

Keyboard shortcuts

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