i18n: Improve the detection of untranslated string
authorAlbert Nigmatzianov <albertnigma@gmail.com>
Tue, 2 May 2017 17:01:05 +0000 (19:01 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 2 May 2017 20:45:37 +0000 (22:45 +0200)
Fix #2607

i18n/i18n.go

index ce268fac3b2d5c6b63a8122a513667741eddf8cc..80fc5bb046216f641fa2b3d5cbc4e7e16b85aa94 100644 (file)
@@ -76,7 +76,21 @@ func (t Translator) initFuncs(bndl *bundle.Bundle) {
                        tFunc, err := bndl.Tfunc(currentLang)
                        if err != nil {
                                jww.WARN.Printf("could not load translations for language %q (%s), will use default content language.\n", lang, err)
-                       } else if translated := tFunc(translationID, args...); translated != translationID {
+                       }
+
+                       translated := tFunc(translationID, args...)
+                       // 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 {
                                return translated
                        }
                        if t.cfg.GetBool("logI18nWarnings") {