fix(region): cloudregion&zone add namei18n

This commit is contained in:
TangBin
2020-12-26 17:35:42 +08:00
parent 516892ed6f
commit d097679e47
44 changed files with 737 additions and 7 deletions
+17
View File
@@ -6,6 +6,13 @@ import (
"golang.org/x/text/language"
)
type Tag = language.Tag
var (
I18N_TAG_CHINESE Tag = Tag(language.Chinese)
I18N_TAG_ENGLISH Tag = Tag(language.English)
)
type ITable interface {
Lookup(ctx context.Context, key string) string
}
@@ -27,6 +34,14 @@ func (te TableEntry) EN(v string) TableEntry {
return te
}
func (te TableEntry) Lookup(ctx context.Context) (string, bool) {
lang := Lang(ctx)
lang = tableLangMatch(lang)
v, ok := te[lang]
return v, ok
}
func (tbl Table) Set(k string, te TableEntry) {
tbl[k] = te
}
@@ -41,11 +56,13 @@ func (tbl Table) LookupByLang(lang language.Tag, key string) string {
if !ok {
return key
}
lang = tableLangMatch(lang)
v, ok := te[lang]
if !ok {
return key
}
return v
}