diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-02-07 15:43:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-07 15:43:53 +0800 |
commit | c2a3e38194c7bb4ca1ea62f033e633e597e09be4 (patch) | |
tree | 714d5f49a22041d845ba8693fb976d88ff862be1 /modules/translation | |
parent | f393bc82cbf83ab890a55ecdb7f41583e583ddad (diff) | |
download | gitea-c2a3e38194c7bb4ca1ea62f033e633e597e09be4.tar.gz gitea-c2a3e38194c7bb4ca1ea62f033e633e597e09be4.zip |
Fix the missing i18n key for update checker (#18646)
Diffstat (limited to 'modules/translation')
-rw-r--r-- | modules/translation/translation.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/translation/translation.go b/modules/translation/translation.go index 2dce6e16b9..977f2cdc23 100644 --- a/modules/translation/translation.go +++ b/modules/translation/translation.go @@ -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() |