package webutility import ( "encoding/json" "io/ioutil" ) var locales = map[string]map[string]string{} func LoadLocale(loc, filePath string) error { file, err := ioutil.ReadFile(filePath) if err != nil { return err } var data interface{} err = json.Unmarshal(file, &data) if err != nil { return err } l := map[string]string{} for k, v := range data.(map[string]interface{}) { l[k] = v.(string) } locales[loc] = l return nil } func Translate(loc, key string) string { return locales[loc][key] }