Documentation ¶
Overview ¶
Package translations provides for translations.
Example ¶
package main import ( "fmt" "github.com/soranoba/valis" "github.com/soranoba/valis/code" "github.com/soranoba/valis/translations" "golang.org/x/text/language" "golang.org/x/text/message" "golang.org/x/text/message/catalog" ) func main() { c := translations.NewCatalog(catalog.Fallback(language.English)) if true /* When set all predefined translation data. */ { for _, f := range translations.AllPredefinedCatalogRegistrationFunc { c.Set(f) } } else /* When select and set by yourself. */ { c.Set(translations.DefaultEnglish) c.Set(translations.DefaultJapanese) } err := valis.NewError(code.TooShortLength, "value", 10) en := message.NewPrinter(language.English, message.Catalog(c)) fmt.Printf("%s %s.\n", ".Name", en.Sprintf(err.Code(), err.Params()...)) ja := message.NewPrinter(language.Japanese, message.Catalog(c)) fmt.Printf("%s%s。\n", "名前", ja.Sprintf(err.Code(), err.Params()...)) }
Output: .Name is too short length (minimum is 10 characters). 名前は10文字以上必要です。
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // AllPredefinedCatalogRegistrationFunc is all catalog registration functions predefined by this library. AllPredefinedCatalogRegistrationFunc = [...]CatalogRegistrationFunc{ DefaultEnglish, DefaultJapanese, } )
Functions ¶
func DefaultEnglish ¶
DefaultEnglish is a CatalogRegistrationFunc for English.
func DefaultJapanese ¶
DefaultJapanese is a CatalogRegistrationFunc for Japanese.
Types ¶
type Catalog ¶
Catalog is a wrapper of catalog.Catalog.
func NewCatalog ¶
NewCatalog returns a new catalog instance.
func (*Catalog) Set ¶
func (t *Catalog) Set(f CatalogRegistrationFunc)
Set calls CatalogRegistrationFunc, and registers translation data.
type CatalogRegistrationFunc ¶
CatalogRegistrationFunc is a function that registers translation data to catalog.Builder.
Click to show internal directories.
Click to hide internal directories.