mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-29 18:57:37 +08:00
delete loader.go
This commit is contained in:
parent
06ebe49128
commit
d03187493b
@ -1,37 +0,0 @@
|
||||
// Package lang is a part of the package carbon for i18n
|
||||
package lang
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
var (
|
||||
// langDir language directory
|
||||
langDir = "./lang/"
|
||||
|
||||
// invalidLocaleError returns an invalid locale error.
|
||||
invalidLocaleError = func(locale string) error {
|
||||
return fmt.Errorf("invalid locale %q, please see the directory %q for all valid locales", locale, langDir)
|
||||
}
|
||||
|
||||
// invalidJsonFileError returns an invalid json file error.
|
||||
invalidJsonFileError = func(file string) error {
|
||||
return fmt.Errorf("invalid json file %q, please make sure the json file is valid", langDir+file)
|
||||
}
|
||||
)
|
||||
|
||||
// LoadLocale loads a given locale file.
|
||||
func LoadLocale(locale string) (map[string]string, error) {
|
||||
resources := make(map[string]string)
|
||||
fileName := langDir + locale + ".json"
|
||||
bytes, err := ioutil.ReadFile(fileName)
|
||||
if err != nil {
|
||||
return resources, invalidLocaleError(locale)
|
||||
}
|
||||
if err := json.Unmarshal(bytes, &resources); err != nil {
|
||||
return resources, invalidJsonFileError(fileName)
|
||||
}
|
||||
return resources, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user