Skip to content

Commit

Permalink
i18n: Prevent data race in lang code handling
Browse files Browse the repository at this point in the history
See #3564
  • Loading branch information
bep committed Nov 4, 2017
1 parent bb04010 commit c97216e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion i18n/translationProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c97216e

Please sign in to comment.