Refactor localization strings to English across various services and UI components

- Updated titles and subtitles in channel_service.go for web channel and WeChat MP channel configurations.
- Changed handoff messages in conversation_human_dispatch_service.go to English.
- Modified notification messages in event handlers for ticket and conversation assignments to English.
- Adjusted ticket creation messages in ticket_service.go to reflect English localization.
- Updated default locale settings in i18n configuration files to English (en-US).
- Changed HTML language attribute in layout.tsx to English.
- Refactored widget locale detection logic in agent-desk-sdk.ts to prioritize English.
This commit is contained in:
mlogclub
2026-05-31 20:06:44 +08:00
parent bcf2ee38c0
commit b128447a7e
36 changed files with 315 additions and 164 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ var (
func Bundle() *i18n.Bundle {
bundleOnce.Do(func() {
b := i18n.NewBundle(language.SimplifiedChinese)
b := i18n.NewBundle(language.AmericanEnglish)
b.RegisterUnmarshalFunc("toml", toml.Unmarshal)
for _, name := range []string{
"locales/active.zh-CN.toml",
+3 -3
View File
@@ -6,15 +6,15 @@ const contextLocaleKey = "i18nx.locale"
func Locale(ctx *gin.Context) string {
if ctx == nil {
return LocaleZhCN
return DefaultLocale
}
value, ok := ctx.Get(contextLocaleKey)
if !ok {
return LocaleZhCN
return DefaultLocale
}
locale, ok := value.(string)
if !ok {
return LocaleZhCN
return DefaultLocale
}
return NormalizeLocale(locale)
}
+4 -4
View File
@@ -16,14 +16,14 @@ func TestNormalizeLocale(t *testing.T) {
in string
want string
}{
{name: "default for blank", in: "", want: LocaleZhCN},
{name: "default for blank", in: "", want: LocaleEnUS},
{name: "exact chinese", in: "zh-CN", want: LocaleZhCN},
{name: "underscore chinese", in: "zh_CN", want: LocaleZhCN},
{name: "short chinese", in: "zh", want: LocaleZhCN},
{name: "exact english", in: "en-US", want: LocaleEnUS},
{name: "underscore english", in: "en_US", want: LocaleEnUS},
{name: "short english", in: "en", want: LocaleEnUS},
{name: "unsupported falls back", in: "fr-FR", want: LocaleZhCN},
{name: "unsupported falls back", in: "fr-FR", want: LocaleEnUS},
}
for _, tt := range tests {
@@ -60,13 +60,13 @@ func TestResolveLocalePrefersXLocale(t *testing.T) {
}
}
func TestTranslateFallsBackToChinese(t *testing.T) {
func TestTranslateFallsBackToEnglish(t *testing.T) {
t.Parallel()
if got := TLocale(LocaleEnUS, "error.auth.expired", nil); got != "Your session has expired. Please sign in again." {
t.Fatalf("english translation = %q", got)
}
if got := TLocale("fr-FR", "error.auth.expired", nil); got != "未登录或登录已过期" {
if got := TLocale("fr-FR", "error.auth.expired", nil); got != "Your session has expired. Please sign in again." {
t.Fatalf("fallback translation = %q", got)
}
}
+4 -4
View File
@@ -13,7 +13,7 @@ func T(ctx *gin.Context, messageID string, data map[string]any) string {
}
}
}
return TLocale(LocaleZhCN, messageID, data)
return TLocale(DefaultLocale, messageID, data)
}
func TLocale(locale string, messageID string, data map[string]any) string {
@@ -22,8 +22,8 @@ func TLocale(locale string, messageID string, data map[string]any) string {
if message != "" {
return message
}
if normalized != LocaleZhCN {
message = localize(LocaleZhCN, messageID, data)
if normalized != DefaultLocale {
message = localize(DefaultLocale, messageID, data)
if message != "" {
return message
}
@@ -32,7 +32,7 @@ func TLocale(locale string, messageID string, data map[string]any) string {
}
func localize(locale string, messageID string, data map[string]any) string {
localizer := i18n.NewLocalizer(Bundle(), locale, LocaleZhCN)
localizer := i18n.NewLocalizer(Bundle(), locale, DefaultLocale)
message, err := localizer.Localize(&i18n.LocalizeConfig{
MessageID: messageID,
TemplateData: data,
+7 -6
View File
@@ -9,8 +9,9 @@ import (
)
const (
LocaleZhCN = "zh-CN"
LocaleEnUS = "en-US"
LocaleZhCN = "zh-CN"
LocaleEnUS = "en-US"
DefaultLocale = LocaleEnUS
)
var supportedLocales = map[string]string{
@@ -26,17 +27,17 @@ var supportedLocales = map[string]string{
func NormalizeLocale(value string) string {
key := strings.ToLower(strings.TrimSpace(value))
if key == "" {
return LocaleZhCN
return DefaultLocale
}
if locale, ok := supportedLocales[key]; ok {
return locale
}
return LocaleZhCN
return DefaultLocale
}
func ResolveRequestLocale(req *http.Request) string {
if req == nil {
return LocaleZhCN
return DefaultLocale
}
if locale := normalizeSupportedLocale(req.Header.Get("X-Locale")); locale != "" {
return locale
@@ -47,7 +48,7 @@ func ResolveRequestLocale(req *http.Request) string {
if locale := normalizeSupportedLocale(req.URL.Query().Get("locale")); locale != "" {
return locale
}
return LocaleZhCN
return DefaultLocale
}
func Middleware() gin.HandlerFunc {