Documentation ¶
Overview ¶
Package gi18n implements internationalization and localization.
Package gi18n implements internationalization and localization.
Index ¶
- Constants
- func GetContent(ctx context.Context, key string) string
- func LanguageFromCtx(ctx context.Context) string
- func SetDelimiters(left, right string)
- func SetLanguage(language string)
- func SetPath(path string) error
- func T(ctx context.Context, content string) string
- func Tf(ctx context.Context, format string, values ...interface{}) string
- func Translate(ctx context.Context, content string) string
- func TranslateFormat(ctx context.Context, format string, values ...interface{}) string
- func WithLanguage(ctx context.Context, language string) context.Context
- type Manager
- func (m *Manager) GetContent(ctx context.Context, key string) string
- func (m *Manager) SetDelimiters(left, right string)
- func (m *Manager) SetLanguage(language string)
- func (m *Manager) SetPath(path string) error
- func (m *Manager) T(ctx context.Context, content string) string
- func (m *Manager) Tf(ctx context.Context, format string, values ...interface{}) string
- func (m *Manager) Translate(ctx context.Context, content string) string
- func (m *Manager) TranslateFormat(ctx context.Context, format string, values ...interface{}) string
- type Options
Constants ¶
const (
// DefaultName is the default group name for instance usage.
DefaultName = "default"
)
Variables ¶
This section is empty.
Functions ¶
func GetContent ¶
GetContent retrieves and returns the configured content for given key and specified language. It returns an empty string if not found.
func LanguageFromCtx ¶
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 Translate ¶
Translate translates `content` with configured language and returns the translated content.
func TranslateFormat ¶
TranslateFormat translates, formats and returns the `format` with configured language and given `values`.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager for i18n contents, it is concurrent safe, supporting hot reload.
func Instance ¶
Instance returns an instance of Resource. The parameter `name` is the name for the instance.
func New ¶
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 ¶
GetContent retrieves and returns the configured content for given key and specified language. It returns an empty string if not found.
func (*Manager) SetDelimiters ¶
SetDelimiters sets the delimiters for translator.
func (*Manager) SetLanguage ¶
SetLanguage sets the language for translator.
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.