gi18n

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package gi18n implements internationalization and localization.

Package gi18n 实现了国际化和本地化功能。

Index

Constants

View Source
const (
	// DefaultName 是用于实例使用的默认组名。
	DefaultName = "default"
)

Variables

This section is empty.

Functions

func GetContent

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

GetContent 函数根据给定的键和指定的语言获取并返回配置的内容。 如果未找到,则返回一个空字符串。

func LanguageFromCtx

func LanguageFromCtx(ctx context.Context) string

LanguageFromCtx 从context中获取并返回语言名称。 如果此前未设置,则返回一个空字符串。

func SetDelimiters

func SetDelimiters(left, right string)

SetDelimiters 设置翻译器的分隔符。

func SetLanguage

func SetLanguage(language string)

SetLanguage 设置翻译器的语言。

func SetPath

func SetPath(path string) error

SetPath 设置存储 i18n 文件的目录路径。

func T

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

T 是 Translate 的别名,用于提供便利。

func Tf

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

Tf 是 TranslateFormat 的别名,用于提供便利。

func Translate

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

Translate 使用配置的语言对`content`进行翻译并返回翻译后的内容。

func TranslateFormat

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

TranslateFormat 将根据配置的语言和给定的 `values` 对 `format` 进行翻译、格式化并返回结果。

func WithLanguage

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

WithLanguage 将语言设置追加到上下文中并返回一个新的上下文。

Types

type Manager

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

i18n内容的管理器,它是并发安全的,并支持热重载。

func Instance

func Instance(name ...string) *Manager

Instance 返回一个 Resource 类型的实例。 参数 `name` 是该实例的名称。

func New

func New(options ...Options) *Manager

New 创建并返回一个新的 i18n 管理器。 可选参数 `option` 指定 i18n 管理器的自定义选项。 若未传递该参数,则使用默认选项。

func (*Manager) GetContent

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

GetContent 函数根据给定的键和指定的语言获取并返回配置的内容。 如果未找到,则返回一个空字符串。

func (*Manager) SetDelimiters

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

SetDelimiters 设置翻译器的分隔符。

func (*Manager) SetLanguage

func (m *Manager) SetLanguage(language string)

SetLanguage 设置翻译器的语言。

func (*Manager) SetPath

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

SetPath 设置存储 i18n 文件的目录路径。

func (*Manager) T

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

T 是 Translate 的别名,用于提供便利。

func (*Manager) Tf

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

Tf 是 TranslateFormat 的别名,用于提供便利。

func (*Manager) Translate

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

Translate 使用配置的语言对`content`进行翻译。

func (*Manager) TranslateFormat

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

TranslateFormat 将根据配置的语言和给定的 `values` 对 `format` 进行翻译、格式化并返回结果。

type Options

type Options struct {
	Path       string        // 国际化文件存储路径。
	Language   string        // 默认本地语言。
	Delimiters []string      // 变量解析的分隔符。
	Resource   *资源类.Resource // i18n文件资源。
}

Options 用于i18n对象配置。

Jump to

Keyboard shortcuts

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