Documentation ¶
Overview ¶
Package gettext implements GNU gettext utilities.
Index ¶
- type FileSystemSource
- type Locale
- type LocaleSet
- type NullLocale
- func (l NullLocale) AddDomain(_ string) error
- func (l NullLocale) Get(s string, args ...interface{}) string
- func (l NullLocale) GetC(str string, _ string, vars ...interface{}) string
- func (l NullLocale) GetD(_ string, str string, vars ...interface{}) string
- func (l NullLocale) GetDC(_ string, str, _ string, vars ...interface{}) string
- func (l NullLocale) GetN(str string, _ string, _ int, vars ...interface{}) string
- func (l NullLocale) GetNC(str string, _ string, _ int, _ string, vars ...interface{}) string
- func (l NullLocale) GetND(_ string, str string, _ string, _ int, vars ...interface{}) string
- func (l NullLocale) GetNDC(_ string, str string, _ string, _ int, _ string, vars ...interface{}) string
- type Option
- type Parser
- type Po
- type Source
- type SourceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileSystemSource ¶
type FileSystemSource struct {
// contains filtered or unexported fields
}
func NewFileSystemSource ¶
func NewFileSystemSource(dir string) *FileSystemSource
type Locale ¶
type Locale interface { AddDomain(string) error Get(string, ...interface{}) string GetN(string, string, int, ...interface{}) string GetD(string, string, ...interface{}) string GetND(string, string, string, int, ...interface{}) string GetC(string, string, ...interface{}) string GetNC(string, string, int, string, ...interface{}) string GetDC(string, string, string, ...interface{}) string GetNDC(string, string, string, int, string, ...interface{}) string }
Locale wraps the entire i18n collection for a single language (locale)
type LocaleSet ¶
type LocaleSet struct {
// contains filtered or unexported fields
}
LocaleSet is a convenience wrapper around Locale objects. Multiple locales can be stored in this set, and users may dynamically ask for a Locale object for a given locale name.
func NewLocaleSet ¶
func NewLocaleSet() *LocaleSet
func (*LocaleSet) GetLocale ¶
GetLocale returns the Locale corresponding to the ID l (i.e. "en", "ja", etc). If the corresponding locale is not found, an error is returned, and the first return value is set to *NullLocale, which you can use as a default fallback
type NullLocale ¶
type NullLocale struct{}
func (NullLocale) AddDomain ¶
func (l NullLocale) AddDomain(_ string) error
func (NullLocale) Get ¶
func (l NullLocale) Get(s string, args ...interface{}) string
func (NullLocale) GetDC ¶
func (l NullLocale) GetDC(_ string, str, _ string, vars ...interface{}) string
func (NullLocale) GetN ¶
func (l NullLocale) GetN(str string, _ string, _ int, vars ...interface{}) string
type Option ¶
type Option interface { Name() string Value() interface{} }
func WithDefaultDomain ¶
WithDefaultDomain is used in NewLocale() to specify the name of the domain that will be used by the `Get` method
func WithSource ¶
WithSource is used in NewLocale() to specify where to load the .po files from. By default FileSystemSource will be used.
func WithStrictParsing ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses .po files and creates new Po objects
type Po ¶
type Po struct {
// contains filtered or unexported fields
}
Po stores content required for translation, and does the grunt work of producing localized strings.
Once created you cannot alter the object. You will have to create a new one yourself.
func (*Po) Get ¶
Get retrieves the corresponding translation for the given string. Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
func (*Po) GetC ¶
GetC retrieves the corresponding translation for a given string in the given context. Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
func (*Po) GetN ¶
GetN retrieves the (N)th plural form of translation for the given string. Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
type Source ¶
Source is an abstraction over where to get the content of a .po file. By default the FileSystemSource is used, but you may plug this into asset loaders, databases, etc byt providing a very thin wrapper around it.
Because this whole scheme originated from file-based systems, we still need to use file names as key