mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-14 05:03:49 +08:00
发布v2.18.6版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Package simple
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Copyright Copyright (c) 2025 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package simple
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/gogf/gf/v2/encoding/gbase64"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"hotgo/internal/consts"
|
||||
@@ -74,6 +75,40 @@ func CheckPassword(input, salt, hash string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetHeaderLocale 获取请求头语言设置
|
||||
// gf支持格式:en/ja/ru/zh-CN/zh-TW
|
||||
func GetHeaderLocale(ctx context.Context) (lang string) {
|
||||
lang = g.Cfg().MustGet(ctx, "system.i18n.defaultLanguage", consts.SysDefaultLanguage).String()
|
||||
// 没有开启国际化,使用默认语言
|
||||
if !g.Cfg().MustGet(ctx, "system.i18n.switch", true).Bool() {
|
||||
return
|
||||
}
|
||||
|
||||
r := ghttp.RequestFromCtx(ctx)
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
locale := r.Header.Get("Locale")
|
||||
// 简体中文
|
||||
if locale == "zh-CN" || locale == "zh-Hans" || locale == "zh" || locale == "ZH" {
|
||||
lang = "zh-CN"
|
||||
return
|
||||
}
|
||||
// 繁体
|
||||
if locale == "zh-TW" || locale == "zh-Hant" {
|
||||
lang = "zh-TW"
|
||||
return
|
||||
}
|
||||
// 英文
|
||||
if locale == "en" || locale == "EN" {
|
||||
lang = "en"
|
||||
return
|
||||
}
|
||||
// 更多语言
|
||||
// ...
|
||||
return
|
||||
}
|
||||
|
||||
// SafeGo 安全的调用协程,遇到错误时输出错误日志而不是抛出panic
|
||||
func SafeGo(ctx context.Context, f func(ctx context.Context), lv ...int) {
|
||||
g.Go(ctx, f, func(ctx context.Context, err error) {
|
||||
|
||||
Reference in New Issue
Block a user