summaryrefslogtreecommitdiffhomepage
path: root/i18n
diff options
context:
space:
mode:
authorAlbert Nigmatzianov <[email protected]>2017-05-03 09:11:14 +0200
committerBjørn Erik Pedersen <[email protected]>2017-05-03 09:23:13 +0200
commit8f2ab5f498fc8131ffe99840eac1f6091cec4a78 (patch)
tree6f2b404248f2f78eca73a6f289527df862a796b6 /i18n
parentcce49997a4f272b508ee98b83d40b087d0acf9e3 (diff)
downloadhugo-8f2ab5f498fc8131ffe99840eac1f6091cec4a78.tar.gz
hugo-8f2ab5f498fc8131ffe99840eac1f6091cec4a78.zip
i18n: Simplify code for detecting of untranslated id
Diffstat (limited to 'i18n')
-rw-r--r--i18n/i18n.go37
1 files changed, 20 insertions, 17 deletions
diff --git a/i18n/i18n.go b/i18n/i18n.go
index 80fc5bb04..6b8b92ce3 100644
--- a/i18n/i18n.go
+++ b/i18n/i18n.go
@@ -57,13 +57,8 @@ func (t Translator) Func(lang string) bundle.TranslateFunc {
func (t Translator) initFuncs(bndl *bundle.Bundle) {
defaultContentLanguage := t.cfg.GetString("defaultContentLanguage")
- var (
- defaultT bundle.TranslateFunc
- err error
- )
-
- defaultT, err = bndl.Tfunc(defaultContentLanguage)
+ defaultT, err := bndl.Tfunc(defaultContentLanguage)
if err != nil {
jww.WARN.Printf("No translation bundle found for default language %q", defaultContentLanguage)
}
@@ -79,20 +74,17 @@ func (t Translator) initFuncs(bndl *bundle.Bundle) {
}
translated := tFunc(translationID, args...)
+ if translated != translationID {
+ return translated
+ }
// If there is no translation for translationID,
// then Tfunc returns translationID itself.
- if translated == translationID {
- // But if user set same translationID and translation, we should check
- // if it really untranslated this way:
- // If bndl contains the translationID for specified currentLang,
- // then the translationID is actually translated.
- _, contains := bndl.Translations()[currentLang][translationID]
- if contains {
- return translated
- }
- } else {
+ // But if user set same translationID and translation, we should check
+ // if it really untranslated:
+ if isIDTranslated(currentLang, translationID, bndl) {
return translated
}
+
if t.cfg.GetBool("logI18nWarnings") {
i18nWarningLogger.Printf("i18n|MISSING_TRANSLATION|%s|%s", currentLang, translationID)
}
@@ -100,7 +92,11 @@ func (t Translator) initFuncs(bndl *bundle.Bundle) {
return "[i18n] " + translationID
}
if defaultT != nil {
- if translated := defaultT(translationID, args...); translated != translationID {
+ translated := defaultT(translationID, args...)
+ if translated != translationID {
+ return translated
+ }
+ if isIDTranslated(defaultContentLanguage, translationID, bndl) {
return translated
}
}
@@ -108,3 +104,10 @@ func (t Translator) initFuncs(bndl *bundle.Bundle) {
}
}
}
+
+// If bndl contains the translationID for specified currentLang,
+// then the translationID is actually translated.
+func isIDTranslated(lang, id string, b *bundle.Bundle) bool {
+ _, contains := b.Translations()[lang][id]
+ return contains
+}