i18n: Prevent data race in lang code handling

See #3564
This commit is contained in:
Bjørn Erik Pedersen 2017-11-04 09:43:35 +01:00
parent bb04010cbf
commit c97216e4f0
2 changed files with 3 additions and 1 deletions

View File

@ -68,7 +68,9 @@ func (t Translator) initFuncs(bndl *bundle.Bundle) {
currentLang := lang
t.translateFuncs[currentLang] = func(translationID string, args ...interface{}) string {
tpMu.RLock()
tFunc, err := bndl.Tfunc(currentLang)
tpMu.RUnlock()
if err != nil {
jww.WARN.Printf("could not load translations for language %q (%s), will use default content language.\n", lang, err)
}

View File

@ -25,7 +25,7 @@ import (
// Unfortunately this needs to be global, see
// https://github.com/nicksnyder/go-i18n/issues/82
var tpMu sync.Mutex
var tpMu sync.RWMutex
// TranslationProvider provides translation handling, i.e. loading
// of bundles etc.