This commit is contained in:
toom1996
2026-08-26 10:45:21 +08:00
parent 3cf1368e68
commit 30c9f21da4
48 changed files with 3442 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package service
// 默认语言与受支持语言(与前端 i18n/config.ts 的 LOCALES 保持一致)。
const (
defaultLocale = "en"
localeCN = "cn"
localeEN = "en"
)
// normalizeLocale 把任意输入收敛为受支持的语言;非法或空回落默认 en。
func normalizeLocale(locale string) string {
if locale == localeCN || locale == localeEN {
return locale
}
return defaultLocale
}
// pickLocale 按 locale 选语言字段,缺翻译时回落另一语言,保证出参永远非空(除非两者皆空)。
//
// 这是 i18n 选列的唯一入口:repository 返回 en/cn 两列裸数据,service 在此按 locale 收敛成
// 对外单字段(name / title / description / brand_name),前端契约因此保持不变。
func pickLocale(en, cn, locale string) string {
if normalizeLocale(locale) == localeCN {
if cn != "" {
return cn
}
return en
}
if en != "" {
return en
}
return cn
}