i18n

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewI18N added in v1.0.5

func NewI18N(dirPath string, defaultLang string, langs []string) error

Create new I18N instance. path - path to translation dir, automatic will be load files with current language and format yaml. langs - languages to load.

Types

type LocalizeConfig added in v1.0.5

type LocalizeConfig struct {
	TemplateData map[string]any
	PluralCount  any // int value set
}

Localize config.

type Localizer

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

Localizer defines the structure for managing language localization.

func GetLocalizer

func GetLocalizer() *Localizer

GetLocalizer returns the current global Localizer instance.

func (*Localizer) GetAvailableLanguages

func (l *Localizer) GetAvailableLanguages() []string

GetAvailableLanguages returns a list of all available languages for the localizer.

func (*Localizer) GetDefaultLanguage

func (l *Localizer) GetDefaultLanguage() string

GetDefaultLanguage returns the default language used by the localizer when no language is specified.

func (*Localizer) NewTranslator

func (l *Localizer) NewTranslator(lang string) Translator

NewTranslator returns a Translator for the specified language.

If the language is not found and it is not the default language, it will fall back to the default language.

The Translator is a function that takes a key and optional parameters to translate the key into a message in the specified language.

The optional parameters are:

  • PluralCount: the count of items to pluralize the message.
  • TemplateData: the data to be used to replace placeholders in the message.

If the key is not found, it will return the key itself.

If the language is not found, it will return the default message.

type Translator

type Translator func(key string, configs ...*LocalizeConfig) string

Translation model.

Jump to

Keyboard shortcuts

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