Help us shape the future of Go! Take the 2026 Go Developer Survey

i18n

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SERVICE_X_LANGUAGE          = "x-lang"
	URI_LIST_STRINGS_BY_APPNAME = "/lang/string/list"
	URI_GET_APP_STRINGS_VERSION = "/lang/string/app/version"
)

Variables

This section is empty.

Functions

func CheckParametersLost

func CheckParametersLost(params map[string]string, paramNames ...string) models.Result[any]

func Error

func Error(code int, messageId string) models.Result[any]

func ErrorDef

func ErrorDef(def errcode.Definition, args ...any) models.Result[any]

ErrorDef v2.1 新增:基于 errcode.Definition 的标准化错误响应。

把三向映射(errcode.Definition → i18n 文案 → HTTP 状态码)一步完成:

  • 文案通过 def.MessageKey + args 走 i18n.Format
  • 业务码写入返回体的 Code 字段
  • HTTP 状态码由 def.HTTPStatus 决定(调用方需在自己的 handler 里手动 c.JSON(def.HTTPStatus, result))

返回的 result 是已渲染文案的 models.Result,业务侧调用方式:

c.JSON(errcode.LookupDef(errcode.PARAM_ERROR).HTTPStatus,
    i18n.ErrorDef(errcode.PARAM_ERROR, paramName))

func ErrorDefT

func ErrorDefT[T any](def errcode.Definition, args ...any) models.Result[T]

ErrorDefT 泛型版,行为同 ErrorDef。

func ErrorT

func ErrorT[T any](code int, messageId string) models.Result[T]

func ErrorWithMsg

func ErrorWithMsg(code int, messageId, msg string) models.Result[any]

func ErrorWithMsgT

func ErrorWithMsgT[T any](code int, messageId, msg string) models.Result[T]

func Format

func Format(messageId string, args ...any) string

Format 格式化数据,messageId对应的内容为带{}的模板

func GetAppXLangStringsAll

func GetAppXLangStringsAll(appName string) (map[string]string, error)

func GetAppXLangVersion

func GetAppXLangVersion(appName string) (string, error)

func GetXLangString

func GetXLangString(stringId, lang string) string

func Init

func Init()

func ParamError

func ParamError(param string) models.Result[any]

func ParamLostError

func ParamLostError(param string) models.Result[any]

func String

func String(messageId string) string

String 将messageId根据当前协程X-Lang参数转换成当前语言字符串

func Success

func Success[T any](data T) models.Result[T]

func SuccessWithPage

func SuccessWithPage[T any](data T, count, index, size, total int) models.Result[T]

Types

This section is empty.

Jump to

Keyboard shortcuts

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