|
|
@ -60,9 +60,9 @@ func InitLocales(ctx context.Context) { |
|
|
|
log.Fatal("Failed to list locale files: %v", err) |
|
|
|
log.Fatal("Failed to list locale files: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
localFiles := make(map[string]interface{}, len(localeNames)) |
|
|
|
localeData := make(map[string][]byte, len(localeNames)) |
|
|
|
for _, name := range localeNames { |
|
|
|
for _, name := range localeNames { |
|
|
|
localFiles[name], err = options.Locale(name) |
|
|
|
localeData[name], err = options.Locale(name) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal("Failed to load %s locale file. %v", name, err) |
|
|
|
log.Fatal("Failed to load %s locale file. %v", name, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -75,9 +75,17 @@ func InitLocales(ctx context.Context) { |
|
|
|
|
|
|
|
|
|
|
|
matcher = language.NewMatcher(supportedTags) |
|
|
|
matcher = language.NewMatcher(supportedTags) |
|
|
|
for i := range setting.Names { |
|
|
|
for i := range setting.Names { |
|
|
|
key := "locale_" + setting.Langs[i] + ".ini" |
|
|
|
var localeDataBase []byte |
|
|
|
|
|
|
|
if i == 0 && setting.Langs[0] != "en-US" { |
|
|
|
|
|
|
|
// Only en-US has complete translations. When use other language as default, the en-US should still be used as fallback.
|
|
|
|
|
|
|
|
localeDataBase = localeData["locale_en-US.ini"] |
|
|
|
|
|
|
|
if localeDataBase == nil { |
|
|
|
|
|
|
|
log.Fatal("Failed to load locale_en-US.ini file.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = i18n.DefaultLocales.AddLocaleByIni(setting.Langs[i], setting.Names[i], localFiles[key]); err != nil { |
|
|
|
key := "locale_" + setting.Langs[i] + ".ini" |
|
|
|
|
|
|
|
if err = i18n.DefaultLocales.AddLocaleByIni(setting.Langs[i], setting.Names[i], localeDataBase, localeData[key]); err != nil { |
|
|
|
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) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|