Skip to content

Commit a40d1f6

Browse files
n10vbep
authored andcommitted
i18n: Improve the detection of untranslated string
Fix #2607
1 parent 635b3bb commit a40d1f6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

‎i18n/i18n.go‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,21 @@ func (t Translator) initFuncs(bndl *bundle.Bundle) {
7676
tFunc, err := bndl.Tfunc(currentLang)
7777
if err != nil {
7878
jww.WARN.Printf("could not load translations for language %q (%s), will use default content language.\n", lang, err)
79-
} else if translated := tFunc(translationID, args...); translated != translationID {
79+
}
80+
81+
translated := tFunc(translationID, args...)
82+
// If there is no translation for translationID,
83+
// then Tfunc returns translationID itself.
84+
if translated == translationID {
85+
// But if user set same translationID and translation, we should check
86+
// if it really untranslated this way:
87+
// If bndl contains the translationID for specified currentLang,
88+
// then the translationID is actually translated.
89+
_, contains := bndl.Translations()[currentLang][translationID]
90+
if contains {
91+
return translated
92+
}
93+
} else {
8094
return translated
8195
}
8296
if t.cfg.GetBool("logI18nWarnings") {

0 commit comments

Comments
 (0)