Use i18n.Reset to reload locales (#15073)

This commit is contained in:
6543 2021-03-21 16:11:36 +01:00 committed by GitHub
parent 17731e05ff
commit 24f7bd5899
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 12 deletions

View file

@ -5,8 +5,6 @@
package translation
import (
"errors"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/setting"
@ -38,6 +36,7 @@ func AllLangs() []LangType {
// InitLocales loads the locales
func InitLocales() {
i18n.Reset()
localeNames, err := options.Dir("locale")
if err != nil {
log.Fatal("Failed to list locale files: %v", err)
@ -60,12 +59,7 @@ func InitLocales() {
for i := range setting.Names {
key := "locale_" + setting.Langs[i] + ".ini"
if err = i18n.SetMessageWithDesc(setting.Langs[i], setting.Names[i], localFiles[key]); err != nil {
if errors.Is(err, i18n.ErrLangAlreadyExist) {
// just log if lang is already loaded since we can not reload it
log.Warn("Can not load language '%s' since already loaded", setting.Langs[i])
} else {
log.Error("Failed to set messages to %s: %v", setting.Langs[i], err)
}
log.Error("Failed to set messages to %s: %v", setting.Langs[i], err)
}
}
i18n.SetDefaultLang("en-US")