1 Star 0 Fork 0

彭明 / dm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
zj.go 924 Bytes
一键复制 编辑 原始数据 按行查看 历史
彭明 提交于 2024-04-10 13:53 . DmDMS first init
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package i18n
import (
"encoding/json"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
type msg struct {
Id string `json:"id"`
Translation string `json:"translation,omitempty"`
}
type i18n struct {
Language string `json:"language"`
Messages []msg `json:"messages"`
}
func InitConfig(jsonStr string) {
var i18n i18n
json.Unmarshal([]byte(jsonStr), &i18n)
msaArry := i18n.Messages
tag := language.MustParse(i18n.Language)
for _, e := range msaArry {
message.SetString(tag, e.Id, e.Translation)
}
}
func Get(key string, locale int) string {
var p *message.Printer
switch locale {
case 0:
p = message.NewPrinter(language.SimplifiedChinese)
case 1:
p = message.NewPrinter(language.AmericanEnglish)
case 2:
p = message.NewPrinter(language.TraditionalChinese)
}
return p.Sprintf(key)
}
Go
1
https://gitee.com/sitkcn/dm.git
git@gitee.com:sitkcn/dm.git
sitkcn
dm
dm
v0.0.1

搜索帮助