Skip to content

Instantly share code, notes, and snippets.

@maximilien
Created May 14, 2014 19:18
Show Gist options
  • Save maximilien/0d740c8f2d0d9d6c2ad7 to your computer and use it in GitHub Desktop.
Save maximilien/0d740c8f2d0d9d6c2ad7 to your computer and use it in GitHub Desktop.
Initialization of go-i18n taking care of loading locale for Linux
import( i18n "github.com/nicksnyder/go-i18n/i18n" )
func i18nInit(packageName string) (i18n.TranslateFunc, error) {
osLocale := os.Getenv("LANG")
userLocale := osLocale[:len(".UTF8")] //Might need to make this generic
defaultLocale := "en_US"
i18n.MustLoadTranslationFile(fmt.Sprintf("./src/cf/i18n/%s/%s.all.json", packageName, defaultLocale))
i18n.MustLoadTranslationFile(fmt.Sprintf("./src/cf/i18n/%s/%s.all.json", packageName, userLocale))
T, err := i18n.Tfunc(userLocale, defaultLocale)
if err != nil {
fmt.Printf("Could not initialize i18n strings")
return nil, err
}
return T, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment