From: Bjørn Erik Pedersen Date: Sat, 4 Nov 2017 08:43:35 +0000 (+0100) Subject: i18n: Prevent data race in lang code handling X-Git-Tag: v0.31~31 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=c97216e4f0f3021b12cd3803e512393be569c886;p=brevno-suite%2Fhugo i18n: Prevent data race in lang code handling See #3564 --- diff --git a/i18n/i18n.go b/i18n/i18n.go index 73417fb3..6cc3d0b3 100644 --- a/i18n/i18n.go +++ b/i18n/i18n.go @@ -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) } diff --git a/i18n/translationProvider.go b/i18n/translationProvider.go index 663a8dd5..556ee7a9 100644 --- a/i18n/translationProvider.go +++ b/i18n/translationProvider.go @@ -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.