diff --git a/conf/wide.go b/conf/wide.go index 9ec73aa..6ff47b4 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -71,8 +71,8 @@ func CheckEnv() { glog.Warningf("Not found ide_stub [%s]", ide_stub) } - // 7 分钟进行一次检查 - time.Sleep(time.Minute * 7) + // TODO: 7 分钟进行一次检查环境 + time.Sleep(time.Second * 10) } }() } diff --git a/i18n/locales.go b/i18n/locales.go index bee668f..af41a89 100644 --- a/i18n/locales.go +++ b/i18n/locales.go @@ -39,8 +39,15 @@ func Load() { glog.V(5).Info("Loaded [zh_CN] locale configuration") } +// 获取请求对应的本地语言配置项. +func Get(r *http.Request, key string) interface{} { + locale := GetLocale(r) + + return Locales[locale].Langs[key] +} + // 获取请求对应的本地语言配置. -func GetLangs(r *http.Request) map[string]interface{} { +func GetAll(r *http.Request) map[string]interface{} { locale := GetLocale(r) return Locales[locale].Langs diff --git a/main.go b/main.go index f6aeb57..539fb04 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func init() { func indexHandler(w http.ResponseWriter, r *http.Request) { i18n.Load() - model := map[string]interface{}{"Wide": conf.Wide, "i18n": i18n.GetLangs(r), "locale": i18n.GetLocale(r)} + model := map[string]interface{}{"Wide": conf.Wide, "i18n": i18n.GetAll(r), "locale": i18n.GetLocale(r)} session, _ := user.Session.Get(r, "wide-session") diff --git a/notification/notifications.go b/notification/notifications.go index 5ab9696..79cc94c 100644 --- a/notification/notifications.go +++ b/notification/notifications.go @@ -44,6 +44,8 @@ type WSChannel struct { // var notificationWSs = map[string]*WSChannel{} +// 用户事件处理:将事件转为通知,并通过通知通道推送给前端. +// 当用户事件队列接收到事件时将会调用该函数进行处理. func event2Notification(e *event.Event) { if nil == notificationWSs[e.Sid] { return @@ -63,8 +65,8 @@ func event2Notification(e *event.Event) { return } - msgs := i18n.GetLangs(wsChannel.Request) - notification.Message = msgs["notification_"+strconv.Itoa(e.Code)].(string) + // 消息国际化处理 + notification.Message = i18n.Get(wsChannel.Request, "notification_"+strconv.Itoa(e.Code)).(string) wsChannel.Conn.WriteJSON(¬ification) } diff --git a/shell/shells.go b/shell/shells.go index a2c3e03..0516eef 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -23,7 +23,7 @@ var shellWS = map[string]*websocket.Conn{} func IndexHandler(w http.ResponseWriter, r *http.Request) { i18n.Load() - model := map[string]interface{}{"Wide": conf.Wide, "i18n": i18n.GetLangs(r), "locale": i18n.GetLocale(r)} + model := map[string]interface{}{"Wide": conf.Wide, "i18n": i18n.GetAll(r), "locale": i18n.GetLocale(r)} session, _ := user.Session.Get(r, "wide-session")