This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user