i18n

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(opts ...Option)

Types

type LocaleOption

type LocaleOption func(*i18n.LocalizeConfig)

func WithParam

func WithParam(param any) LocaleOption

func WithPluralCount

func WithPluralCount(pluralCount any) LocaleOption

Plura的一些使用场景 英语: 复数形式:通常情况下,当数字为 1 时使用单数形式,其他情况使用复数形式。 示例: 1 apple 2 apples 0 apples

西班牙语: 复数形式:通常情况下,当数字为 1 时使用单数形式,其他情况使用复数形式。 示例: 1 manzana (苹果) 2 manzanas 0 manzanas

法语:

复数形式:通常情况下,当数字为 0 或 1 时使用单数形式,其他情况使用复数形式。 示例: 1 pomme (苹果) 2 pommes 0 pommes

德语:

复数形式:通常情况下,当数字为 1 时使用单数形式,其他情况使用复数形式。 示例: 1 Apfel (苹果) 2 Äpfel 0 Äpfel

俄语:

复数形式:通常情况下,1 对应单数形式,2-4 对应复数形式,5 及以上对应另一种复数形式。 示例: 1 яблоко (苹果) 2 яблока 5 яблок

意大利语:

复数形式:通常情况下,1 对应单数形式,其他情况使用复数形式。 示例: 1 mela (苹果) 2 mele 0 mele

葡萄牙语:

复数形式:通常情况下,当数字为 1 时使用单数形式,其他情况使用复数形式。 示例: 1 maçã (苹果) 2 maçãs 0 maçãs

阿拉伯语:

复数形式:规则较复杂,通常与数字的形式、性别和状态等有关。 示例: ١ تفاحة (苹果) ٢ تفاحة ٥ تفاحات ------------------------------------------- Plura必须为int或float类型,否则会出现panic Plura为句子中包含的数量值,i18n通过这个判断使用哪种类型的句式

type Localizer

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

func GetLocalizer

func GetLocalizer(lang string) *Localizer

func (*Localizer) Msg

func (l *Localizer) Msg(id string, opts ...LocaleOption) (string, error)

func (*Localizer) MustMsg

func (l *Localizer) MustMsg(id string, opts ...LocaleOption) string

type Option

type Option func(*langset)

func WithDefaultTemplateFuncs

func WithDefaultTemplateFuncs() Option

import sprig(https://github.com/Masterminds/sprig) template funcs

func WithMsgDir

func WithMsgDir(dirs ...string) Option

func WithMsgFiles

func WithMsgFiles(paths ...string) Option

func WithMsgFilesDirFs

func WithMsgFilesDirFs(fs fs.ReadDirFS, dirs ...string) Option

func WithMsgFilesFs

func WithMsgFilesFs(fs fs.FS, paths ...string) Option

func WithTemplateDelim

func WithTemplateDelim(left, right string) Option

set delimiters in template

func WithTemplateFunc

func WithTemplateFunc(name string, f any) Option

add a template function

func WithTemplateFuncs

func WithTemplateFuncs(fs map[string]any) Option

add template functions eg: WithTemplateFuncs(sprig.FuncMap()) import sprig(https://github.com/Masterminds/sprig) template funcs

func WithUnmarshaler

func WithUnmarshaler(ft string, unmarshalFunc i18n.UnmarshalFunc) Option

set the Unmarshaler to parse the language file for the specified file type