Fix the missing i18n key for update checker (#18646)

This commit is contained in:
wxiaoguang 2022-02-07 15:43:53 +08:00 committed by GitHub
parent f393bc82cb
commit c2a3e38194
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -39,6 +39,18 @@ func AllLangs() []LangType {
return allLangs
}
// TryTr tries to do the translation, if no translation, it returns (format, false)
func TryTr(lang, format string, args ...interface{}) (string, bool) {
s := i18n.Tr(lang, format, args...)
// now the i18n library is not good enough and we can only use this hacky method to detect whether the transaction exists
idx := strings.IndexByte(format, '.')
defaultText := format
if idx > 0 {
defaultText = format[idx+1:]
}
return s, s != defaultText
}
// InitLocales loads the locales
func InitLocales() {
i18n.Reset()