translation

package
v0.0.0-...-83cf971 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Language

func Language(ctx context.Context) string

func LanguageMiddleware

func LanguageMiddleware(next http.Handler) http.Handler

func MergePoFiles

func MergePoFiles(poFiles ...io.Reader) io.Reader

func PoFromGo

func PoFromGo(filename string, code io.Reader) io.Reader

func PoFromHTML

func PoFromHTML(filename string, html io.Reader) io.Reader

PoFromHTML extracts all translation messages from the HTML template. Template is expected to use Go stdlib template engine with {{ and }} for blocks. Translation function must be called "translate" and contain either one or three arguments.

Types

type LangRenderer

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

LangRenderer is a language aware template renderer.

func Renderer

func Renderer(
	root *template.Template,
	templatesFS embed.FS,
	templatesPattern string,
	trans *Translations,
) (*LangRenderer, error)

Renderer returns a renderer with translation functions attached.

func (*LangRenderer) Render

func (r *LangRenderer) Render(w http.ResponseWriter, code int, templateName string, context interface{})

Render writes an HTML response.

func (*LangRenderer) RenderTo

func (r *LangRenderer) RenderTo(w io.Writer, language string, templateName string, context interface{}) error

type Locale

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

Locale provides translations for a single language.

func (*Locale) T

func (lo *Locale) T(s string) string

T returns translation for a simple string.

func (*Locale) Tn

func (lo *Locale) Tn(singular, plural string, n int) string

Tn provides translation for a string, depending on the n argument which is used to determine which plural form to use.

type Translations

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

func Load

func Load(translations embed.FS, glob string) (*Translations, error)

func (Translations) Bind

func (t Translations) Bind(language string) *Locale

Jump to

Keyboard shortcuts

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