i18n

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package i18n 按翻译表把服务生成的简体中文文案换成界面语言

Index

Constants

View Source
const Source = "zh-CN"

Source 是服务文案的原文语言

Variables

View Source
var (
	Stdout = Writer(os.Stdout, Console)
	Stderr = Writer(os.Stderr, Console)
)

Stdout 与 Stderr 是按 Console 翻译的标准输出与标准错误

View Source
var Console = SystemLocale()

Console 是命令行与控制台日志使用的语言,取自系统语言

View Source
var Locales = []string{"zh-CN", "zh-TW", "en", "ja", "ko", "fr", "de"}

Locales 是界面与命令行支持的语言

Functions

func Match

func Match(tag string) string

Match 返回与语言标签最接近的支持语言,简体中文变体为 zh-CN,繁体中文变体为 zh-TW,其余按语言主标签选择,都不支持时返回空字符串

func Messages

func Messages(locale string) ([]byte, bool)

Messages 返回 locale 的翻译表原文,键为格式串,值为带编号占位符的译文

func SystemLocale

func SystemLocale() string

SystemLocale 按 LC_ALL、LC_MESSAGES 与 LANG 返回最接近的支持语言,都不支持时为英文

func Translate

func Translate(locale, text string) string

Translate 返回 text 在 locale 下的译文,简体中文、不含汉字或没有匹配的文案原样返回

func Writer

func Writer(out io.Writer, locale string) io.Writer

Writer 返回按 locale 翻译写入内容的写入器:JSON 日志行只翻译含汉字的字符串值,其余文字逐行翻译

Types

This section is empty.

Jump to

Keyboard shortcuts

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