This commit is contained in:
parent
1b3cabed7e
commit
034731610d
|
@ -71,8 +71,8 @@ func CheckEnv() {
|
||||||
glog.Warningf("Not found ide_stub [%s]", ide_stub)
|
glog.Warningf("Not found ide_stub [%s]", ide_stub)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7 分钟进行一次检查
|
// TODO: 7 分钟进行一次检查环境
|
||||||
time.Sleep(time.Minute * 7)
|
time.Sleep(time.Second * 10)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,15 @@ func Load() {
|
||||||
glog.V(5).Info("Loaded [zh_CN] locale configuration")
|
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)
|
locale := GetLocale(r)
|
||||||
|
|
||||||
return Locales[locale].Langs
|
return Locales[locale].Langs
|
||||||
|
|
2
main.go
2
main.go
|
@ -41,7 +41,7 @@ func init() {
|
||||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
i18n.Load()
|
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")
|
session, _ := user.Session.Get(r, "wide-session")
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,8 @@ type WSChannel struct {
|
||||||
// <sid, WSChannel>
|
// <sid, WSChannel>
|
||||||
var notificationWSs = map[string]*WSChannel{}
|
var notificationWSs = map[string]*WSChannel{}
|
||||||
|
|
||||||
|
// 用户事件处理:将事件转为通知,并通过通知通道推送给前端.
|
||||||
|
// 当用户事件队列接收到事件时将会调用该函数进行处理.
|
||||||
func event2Notification(e *event.Event) {
|
func event2Notification(e *event.Event) {
|
||||||
if nil == notificationWSs[e.Sid] {
|
if nil == notificationWSs[e.Sid] {
|
||||||
return
|
return
|
||||||
|
@ -63,8 +65,8 @@ func event2Notification(e *event.Event) {
|
||||||
return
|
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)
|
wsChannel.Conn.WriteJSON(¬ification)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ var shellWS = map[string]*websocket.Conn{}
|
||||||
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
i18n.Load()
|
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")
|
session, _ := user.Session.Get(r, "wide-session")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue