Created
May 14, 2014 19:18
-
-
Save maximilien/0d740c8f2d0d9d6c2ad7 to your computer and use it in GitHub Desktop.
Initialization of go-i18n taking care of loading locale for Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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