i18n

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package i18n provide i18n (Internationalization) support

Index

Constants

View Source
const (
	// CookieValueZH ...
	CookieValueZH = "zh-cn"
	// CookieValueEN ...
	CookieValueEN = "en-us"
)
View Source
const Placeholder = "<TODO>"

Placeholder 翻译文件中的占位符

Variables

This section is empty.

Functions

func ExtractMessages

func ExtractMessages() error

ExtractMessages 提取国际化消息

func GetLangCookieValue

func GetLangCookieValue(lang Lang) string

GetLangCookieValue 获取语言版本 Cookie 值

func InitMsgMap

func InitMsgMap()

InitMsgMap 服务启动时初始化 i18n 配置

func MsgFilepath

func MsgFilepath() string

MsgFilepath 获取国际化配置文件路径

func T

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

T 获取国际化翻译文本

func TranslateWithLang

func TranslateWithLang(msgID string, lang Lang) string

TranslateWithLang 获取国际化文本

Types

type Lang

type Lang string

Lang 语言

const (
	// LangDefault 默认语言
	LangDefault Lang = "default"
	// LangZH 中文
	LangZH Lang = "zh"
	// LangEN 英文
	LangEN Lang = "en"
)

func GetLangFromContext

func GetLangFromContext(ctx context.Context) Lang

GetLangFromContext 从 Context 中获取语言版本

func GetLangFromCookie

func GetLangFromCookie(ck *http.Cookie) Lang

GetLangFromCookie 从 Cookie 中获取语言版本

Jump to

Keyboard shortcuts

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