translation

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 5 Imported by: 0

README

Hyperscale Translation Last release Documentation

Go Report Card

Branch Status Coverage
master Build Status Coveralls

The Hyperscale translation library provides a simple translation manager over x/text package.

Example

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() {
    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
}

License

Hyperscale Translation is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(t *translator)

func WithCatalog

func WithCatalog(c catalog.Catalog) Option

func WithDefaultLocale

func WithDefaultLocale(locale language.Tag) Option

type Translator

type Translator interface {
	GetSupportedLocale(tag language.Tag) language.Tag
	Translate(ctx context.Context, key message.Reference, args ...interface{}) string
}

func New

func New(locales []language.Tag, opts ...Option) Translator

Jump to

Keyboard shortcuts

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