Branch | Status | Coverage |
---|---|---|
master |
The Hyperscale translation library provides a simple translation manager over x/text
package.
package main
import (
"fmt"
"github.com/hyperscale-stack/locale"
"github.com/hyperscale-stack/translation"
"golang.org/x/text/language"
"golang.org/x/text/message/catalog"
)
func main() {
// plase use golang.org/x/text/cmd/gotext for build catalog
c := catalog.NewBuilder(catalog.Fallback(language.English))
c.SetString(language.English, "Hello World", "Hello World")
c.SetString(language.French, "Hello World", "Bonjour le monde")
// the default language is always language.English, for override use translation.WithDefaultLocale()
trans := translation.New(
[]language.Tag{
language.English,
language.French,
},
translation.WithCatalog(c),
)
ctx := context.Background()
ctx = locale.ToContext(ctx, language.French)
trans.Translate(ctx, "Hello World") // return Bonjour le monde
}
Hyperscale Translation is licensed under the MIT license.