gi18n

package
v1.16.9 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 14 Imported by: 23

Documentation

Overview

Package gi18n implements internationalization and localization.

Package gi18n implements internationalization and localization.

Index

Constants

View Source
const (
	// DefaultName is the default group name for instance usage.
	DefaultName = "default"
)

Variables

This section is empty.

Functions

func GetContent added in v1.13.0

func GetContent(ctx context.Context, key string) string

GetContent retrieves and returns the configured content for given key and specified language. It returns an empty string if not found.

func LanguageFromCtx added in v1.16.0

func LanguageFromCtx(ctx context.Context) string

LanguageFromCtx retrieves and returns language name from context. It returns an empty string if it is not set previously.

func SetDelimiters

func SetDelimiters(left, right string)

SetDelimiters sets the delimiters for translator.

func SetLanguage

func SetLanguage(language string)

SetLanguage sets the language for translator.

func SetPath

func SetPath(path string) error

SetPath sets the directory path storing i18n files.

func T

func T(ctx context.Context, content string) string

T is alias of Translate for convenience.

func Tf added in v1.14.1

func Tf(ctx context.Context, format string, values ...interface{}) string

Tf is alias of TranslateFormat for convenience.

func Translate

func Translate(ctx context.Context, content string) string

Translate translates <content> with configured language and returns the translated content.

func TranslateFormat added in v1.13.4

func TranslateFormat(ctx context.Context, format string, values ...interface{}) string

TranslateFormat translates, formats and returns the <format> with configured language and given <values>.

func WithLanguage added in v1.16.0

func WithLanguage(ctx context.Context, language string) context.Context

WithLanguage append language setting to the context and returns a new context.

Types

type Manager

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

Manager for i18n contents, it is concurrent safe, supporting hot reload.

func Instance

func Instance(name ...string) *Manager

Instance returns an instance of Resource. The parameter <name> is the name for the instance.

func New

func New(options ...Options) *Manager

New creates and returns a new i18n manager. The optional parameter <option> specifies the custom options for i18n manager. It uses a default one if it's not passed.

func (*Manager) GetContent added in v1.13.0

func (m *Manager) GetContent(ctx context.Context, key string) string

GetContent retrieves and returns the configured content for given key and specified language. It returns an empty string if not found.

func (*Manager) SetDelimiters

func (m *Manager) SetDelimiters(left, right string)

SetDelimiters sets the delimiters for translator.

func (*Manager) SetLanguage

func (m *Manager) SetLanguage(language string)

SetLanguage sets the language for translator.

func (*Manager) SetPath

func (m *Manager) SetPath(path string) error

SetPath sets the directory path storing i18n files.

func (*Manager) T

func (m *Manager) T(ctx context.Context, content string) string

T is alias of Translate for convenience.

func (*Manager) Tf added in v1.14.1

func (m *Manager) Tf(ctx context.Context, format string, values ...interface{}) string

Tf is alias of TranslateFormat for convenience.

func (*Manager) Translate

func (m *Manager) Translate(ctx context.Context, content string) string

Translate translates <content> with configured language.

func (*Manager) TranslateFormat added in v1.13.4

func (m *Manager) TranslateFormat(ctx context.Context, format string, values ...interface{}) string

TranslateFormat translates, formats and returns the <format> with configured language and given <values>.

type Options

type Options struct {
	Path       string   // I18n files storage path.
	Language   string   // Default local language.
	Delimiters []string // Delimiters for variable parsing.
}

Options is used for i18n object configuration.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions creates and returns a default options for i18n manager.

Jump to

Keyboard shortcuts

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