From a3624a0e10994805801a2f767995280cbaeefb1e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 28 Oct 2014 14:38:27 +0800 Subject: [PATCH] Fix #113 --- conf/wide.go | 8 ++------ i18n/locales.go | 16 ++++++++++++---- util/os.go | 11 +++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/conf/wide.go b/conf/wide.go index 3ec8fee..2b6c48b 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -264,12 +264,8 @@ func Load() { Wide.ShellChannel = strings.Replace(Wide.ShellChannel, "{IP}", ip, 1) Wide.SessionChannel = strings.Replace(Wide.SessionChannel, "{IP}", ip, 1) - // 获取当前执行路径 - file, _ := exec.LookPath(os.Args[0]) - pwd, _ := filepath.Abs(file) - pwd = pwd[:strings.LastIndex(pwd, PathSeparator)] - Wide.Pwd = pwd - glog.V(3).Infof("pwd [%s]", pwd) + Wide.Pwd = util.OS.Pwd() + glog.V(3).Infof("pwd [%s]", Wide.Pwd) glog.V(3).Info("Conf: \n" + string(bytes)) diff --git a/i18n/locales.go b/i18n/locales.go index 02d6946..632caa5 100644 --- a/i18n/locales.go +++ b/i18n/locales.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io/ioutil" "os" + "strings" "github.com/golang/glog" ) @@ -20,11 +21,18 @@ var Locales = map[string]locale{} // 加载国际化配置. func Load() { - // TODO: 自动加载所有语言配置 + f, _ := os.Open("i18n") + names, _ := f.Readdirnames(-1) + f.Close() - load("zh_CN") - load("ja_JP") - load("en_US") + for _, name := range names { + if !strings.HasSuffix(name, ".json") { + continue + } + + loc := name[:strings.LastIndex(name, ".")] + load(loc) + } } func load(localeStr string) { diff --git a/util/os.go b/util/os.go index 7350aeb..8517abe 100644 --- a/util/os.go +++ b/util/os.go @@ -1,6 +1,9 @@ package util import ( + "os" + "os/exec" + "path/filepath" "runtime" ) @@ -13,3 +16,11 @@ var OS = myos{} func (*myos) IsWindows() bool { return "windows" == runtime.GOOS } + +// 获取当前执行程序的工作目录的绝对路径. +func (*myos) Pwd() string { + file, _ := exec.LookPath(os.Args[0]) + pwd, _ := filepath.Abs(file) + + return filepath.Dir(pwd) +}