This commit is contained in:
@@ -36,8 +36,57 @@ func requestLangCode(r *http.Request) string {
|
||||
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)
|
||||
// textForLang returns body text stored for the post's source language only.
|
||||
func (t postTextI18n) textForLang(lang string) string {
|
||||
switch translateNormalizePostLang(lang) {
|
||||
case "en":
|
||||
return strings.TrimSpace(t.TextEn)
|
||||
case "ja":
|
||||
return strings.TrimSpace(t.TextJa)
|
||||
case "ko":
|
||||
return strings.TrimSpace(t.TextKo)
|
||||
case "vi":
|
||||
return strings.TrimSpace(t.TextVi)
|
||||
case "id":
|
||||
return strings.TrimSpace(t.TextId)
|
||||
case "ms":
|
||||
return strings.TrimSpace(t.TextMs)
|
||||
default:
|
||||
return strings.TrimSpace(t.TextZh)
|
||||
}
|
||||
}
|
||||
|
||||
func postTextI18nFromSingle(lang, text string) postTextI18n {
|
||||
lang = translateNormalizePostLang(lang)
|
||||
text = strings.TrimSpace(text)
|
||||
var t postTextI18n
|
||||
switch lang {
|
||||
case "en":
|
||||
t.TextEn = text
|
||||
case "ja":
|
||||
t.TextJa = text
|
||||
case "ko":
|
||||
t.TextKo = text
|
||||
case "vi":
|
||||
t.TextVi = text
|
||||
case "id":
|
||||
t.TextId = text
|
||||
case "ms":
|
||||
t.TextMs = text
|
||||
default:
|
||||
t.TextZh = text
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func normalizePostSourceLang(lang string) string {
|
||||
lang = translateNormalizePostLang(strings.TrimSpace(lang))
|
||||
switch lang {
|
||||
case "zh", "en", "ja", "ko", "vi", "id", "ms":
|
||||
return lang
|
||||
default:
|
||||
return "zh"
|
||||
}
|
||||
}
|
||||
|
||||
func (t postTextI18n) anyNonEmpty() bool {
|
||||
|
||||
Reference in New Issue
Block a user