ttenn

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 4 Imported by: 0

README

ttenn

A simple translation (t10n) package.

Documentation

Overview

Package ttenn provides a simple way to translate text.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParsingJSON              = errors.New("parsing json")
	ErrDefaultLanguageUndefined = errors.New("default language undefined")
	ErrNotFound                 = errors.New("translation not found")
)

Functions

This section is empty.

Types

type InMemoryOption

type InMemoryOption func(*InMemoryTranslator) error

InMemoryOption is a function that configures a InMemoryTranslator.

func WithDefaultLanguage

func WithDefaultLanguage(defaultLanguage language.Tag) InMemoryOption

WithDefaultLanguage sets the default language of an InMemoryTranslator.

func WithJSON

func WithJSON(r io.Reader) InMemoryOption

WithJSON uses the given JSON file to configure the languages and translations of an InMemoryTranslator.

type InMemoryTranslator

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

InMemoryTranslator implements Translator.

func NewInMemory

func NewInMemory(options ...InMemoryOption) (*InMemoryTranslator, error)

NewInMemory configures a new InMemoryTranslator.

func (InMemoryTranslator) Translate

func (t InMemoryTranslator) Translate(lang language.Tag, key string) (string, error)

Translate attempts to find a translation identified by key for a given language. When InMemoryTranslator is configured with a default language, it will attempt to fall back to default if the key is not found for the desired language.

type Translations

type Translations map[string]string

Translations is a key-value store for text.

type Translator

type Translator interface {
	Translate(language.Tag, string) (string, error)
}

Translator is a translator interface.

Jump to

Keyboard shortcuts

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