Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into migrate-meta-name
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates authored Jan 29, 2018
2 parents 6fec8cf + 44bde5b commit 9db7e65
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions middleware/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package i18n

import (
"fmt"
"log"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -43,15 +42,18 @@ func (t *Translator) Load() error {
return t.Box.Walk(func(path string, f packr.File) error {
b, err := t.Box.MustBytes(path)
if err != nil {
log.Fatal(err)
return errors.WithStack(err)
return errors.Wrapf(err, "unable to read locale file %s", path)
}

base := filepath.Base(path)
dir := filepath.Dir(path)

// Add a prefix to the loaded string, to avoid collision with an ISO lang code
return i18n.ParseTranslationFileBytes(fmt.Sprintf("%sbuff%s", dir, base), b)
err = i18n.ParseTranslationFileBytes(fmt.Sprintf("%sbuff%s", dir, base), b)
if err != nil {
return errors.Wrapf(err, "unable to parse locale file %s", base)
}
return nil
})
}

Expand Down Expand Up @@ -108,7 +110,8 @@ func (t *Translator) Middleware() buffalo.MiddlewareFunc {
langs := c.Value("languages").([]string)
T, err := i18n.Tfunc(langs[0], langs[1:]...)
if err != nil {
return err
c.Logger().Warn(err)
c.Logger().Warn("Your locale files are probably empty or missing")
}
c.Set("T", T)
}
Expand Down

0 comments on commit 9db7e65

Please sign in to comment.