1
All checks were successful
Deploy API / deploy (push) Successful in 34s

This commit is contained in:
2026-05-26 11:12:22 +08:00
parent f8792f8db8
commit 09089e1335
3 changed files with 110 additions and 9 deletions

View File

@@ -23,6 +23,19 @@ type postLocalePayload struct {
Text string `json:"text"`
}
// requestLangCode is the normalized locale from ?lang= or Accept-Language (zh, en, ja, …).
func requestLangCode(r *http.Request) string {
raw := strings.TrimSpace(r.URL.Query().Get("lang"))
if raw == "" {
raw = r.Header.Get("Accept-Language")
}
raw = strings.TrimSpace(strings.Split(raw, ",")[0])
if raw == "" {
return "zh"
}
return translateNormalizePostLang(raw)
}
func (t postTextI18n) pick(r *http.Request) string {
return pickLangField(r, t.TextZh, t.TextEn, t.TextJa, t.TextKo, t.TextVi, t.TextId, t.TextMs)
}