From 9742d1ffa34633289a03789780f723cf6586b299 Mon Sep 17 00:00:00 2001 From: gouguoyin <245629560@qq.com> Date: Sat, 29 Oct 2022 14:32:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20window=20=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=B8=8B=E8=AF=AD=E8=A8=80=E7=BF=BB=E8=AF=91=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- language.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/language.go b/language.go index c05d879..574866c 100755 --- a/language.go +++ b/language.go @@ -4,7 +4,6 @@ import ( "embed" "encoding/json" "fmt" - "os" "strconv" "strings" ) @@ -13,13 +12,16 @@ import ( var fs embed.FS var ( - // defaultDir default directory - defaultDir = "lang" + // default directory + // 默认目录 + defaultDir = "lang/" - // defaultLocale default locale + // default locale + // 默认区域 defaultLocale = "en" - // invalidLocaleError returns an invalid locale error. + // invalid locale error + // 无效的区域错误 invalidLocaleError = func(locale string) error { return fmt.Errorf("invalid locale file %q, please make sure the json file exists and is valid", locale) } @@ -51,7 +53,7 @@ func (lang *Language) SetLocale(locale string) { return } lang.locale = locale - fileName := lang.dir + string(os.PathSeparator) + locale + ".json" + fileName := lang.dir + locale + ".json" bytes, err := fs.ReadFile(fileName) if err != nil { lang.Error = invalidLocaleError(fileName) @@ -76,7 +78,7 @@ func (lang *Language) SetResources(resources map[string]string) { } } -// translate returns a translated string. +// returns a translated string. // 翻译转换 func (lang *Language) translate(unit string, value int64) string { if len(lang.resources) == 0 {