Skip to content

Commit

Permalink
fix i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed May 11, 2024
1 parent 17a0cc2 commit 9935139
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions module/i18n/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Init(cfg gcore.Config) (err error) {
}

func initFromBinData(cfg gcore.Config) (err error) {
fallbackLang := cfg.GetString("i18n.default")
fallbackLang := strings.ToLower(cfg.GetString("i18n.default"))
enabled := cfg.GetBool("i18n.enable")
if !enabled {
return
Expand Down Expand Up @@ -71,7 +71,7 @@ func initFromBinData(cfg gcore.Config) (err error) {

func initFromDisk(cfg gcore.Config) (err error) {
dir := cfg.GetString("i18n.dir")
fallbackLang := cfg.GetString("i18n.default")
fallbackLang := strings.ToLower(cfg.GetString("i18n.default"))
enalbed := cfg.GetBool("i18n.enable")
if !enalbed {
return
Expand Down
5 changes: 3 additions & 2 deletions module/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newI18n() *I18n {
func (this *I18n) Clone(lang string) gcore.I18n {
return &I18n{
langs: this.langs,
fallbackLang: lang,
fallbackLang: strings.ToLower(lang),
}
}
func (this *I18n) Add(lang string, data map[string]string) {
Expand All @@ -50,7 +50,7 @@ func (this *I18n) Tr(lang, key string, defaultMessage ...string) string {
if len(defaultMessage) > 0 {
msg = defaultMessage[0]
}
for _, k := range []string{lang, this.fallbackLang} {
for _, k := range []string{strings.ToLower(lang), this.fallbackLang} {
if v, ok := this.langs[k]; ok {
if vv, ok := v[key]; ok {
return vv
Expand All @@ -67,6 +67,7 @@ func (this *I18n) TrLangs(langs []string, key string, defaultMessage ...string)
msg = defaultMessage[0]
}
for _, k := range langs {
k = strings.ToLower(k)
if v, ok := this.langs[k]; ok {
if vv, ok := v[key]; ok {
return vv
Expand Down

0 comments on commit 9935139

Please sign in to comment.