2026-05-25 00:09:44 +08:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const resourceI18nColsSQL = `
|
2026-05-25 16:45:33 +08:00
|
|
|
COALESCE(r.title_zh,''), COALESCE(r.title_en,''), COALESCE(r.title_ja,''),
|
|
|
|
|
COALESCE(r.title_ko,''), COALESCE(r.title_vi,''), COALESCE(r.title_id,''), COALESCE(r.title_ms,''),
|
|
|
|
|
COALESCE(r.description_zh,''), COALESCE(r.description_en,''), COALESCE(r.description_ja,''),
|
|
|
|
|
COALESCE(r.description_ko,''), COALESCE(r.description_vi,''), COALESCE(r.description_id,''), COALESCE(r.description_ms,''),
|
|
|
|
|
COALESCE(r.body_text_zh,''), COALESCE(r.body_text_en,''), COALESCE(r.body_text_ja,''),
|
|
|
|
|
COALESCE(r.body_text_ko,''), COALESCE(r.body_text_vi,''), COALESCE(r.body_text_id,''), COALESCE(r.body_text_ms,'')`
|
2026-05-25 00:09:44 +08:00
|
|
|
|
|
|
|
|
type resourceTextI18n struct {
|
2026-05-25 16:45:33 +08:00
|
|
|
TitleZh, TitleEn, TitleJa, TitleKo, TitleVi, TitleId, TitleMs string
|
|
|
|
|
DescZh, DescEn, DescJa, DescKo, DescVi, DescId, DescMs string
|
|
|
|
|
BodyZh, BodyEn, BodyJa, BodyKo, BodyVi, BodyId, BodyMs string
|
2026-05-25 00:09:44 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-25 16:45:33 +08:00
|
|
|
func pickLangField(r *http.Request, zh, en, ja, ko, vi, id, ms string) string {
|
2026-05-25 00:09:44 +08:00
|
|
|
lang := strings.TrimSpace(r.URL.Query().Get("lang"))
|
|
|
|
|
if lang == "" {
|
|
|
|
|
lang = r.Header.Get("Accept-Language")
|
|
|
|
|
}
|
|
|
|
|
lang = strings.ToLower(strings.TrimSpace(strings.Split(lang, ",")[0]))
|
|
|
|
|
switch {
|
2026-05-25 16:45:33 +08:00
|
|
|
case strings.HasPrefix(lang, "zh"):
|
|
|
|
|
if zh != "" {
|
|
|
|
|
return zh
|
2026-05-25 00:09:44 +08:00
|
|
|
}
|
|
|
|
|
case strings.HasPrefix(lang, "en"):
|
|
|
|
|
if en != "" {
|
|
|
|
|
return en
|
|
|
|
|
}
|
2026-05-25 16:45:33 +08:00
|
|
|
case strings.HasPrefix(lang, "ja"):
|
|
|
|
|
if ja != "" {
|
|
|
|
|
return ja
|
|
|
|
|
}
|
|
|
|
|
case strings.HasPrefix(lang, "ko"):
|
|
|
|
|
if ko != "" {
|
|
|
|
|
return ko
|
|
|
|
|
}
|
|
|
|
|
case strings.HasPrefix(lang, "vi"):
|
|
|
|
|
if vi != "" {
|
|
|
|
|
return vi
|
|
|
|
|
}
|
|
|
|
|
case lang == "id", strings.HasPrefix(lang, "in"):
|
|
|
|
|
if id != "" {
|
|
|
|
|
return id
|
|
|
|
|
}
|
|
|
|
|
case strings.HasPrefix(lang, "ms"):
|
|
|
|
|
if ms != "" {
|
|
|
|
|
return ms
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if zh != "" {
|
|
|
|
|
return zh
|
2026-05-25 00:09:44 +08:00
|
|
|
}
|
2026-05-25 16:45:33 +08:00
|
|
|
if en != "" {
|
|
|
|
|
return en
|
2026-05-25 00:09:44 +08:00
|
|
|
}
|
2026-05-25 16:45:33 +08:00
|
|
|
if ja != "" {
|
|
|
|
|
return ja
|
2026-05-25 00:09:44 +08:00
|
|
|
}
|
2026-05-25 16:45:33 +08:00
|
|
|
if ko != "" {
|
|
|
|
|
return ko
|
|
|
|
|
}
|
|
|
|
|
if vi != "" {
|
|
|
|
|
return vi
|
|
|
|
|
}
|
|
|
|
|
if id != "" {
|
|
|
|
|
return id
|
|
|
|
|
}
|
|
|
|
|
return ms
|
2026-05-25 00:09:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t resourceTextI18n) pick(r *http.Request) (title, description, body string) {
|
2026-05-25 16:45:33 +08:00
|
|
|
return pickLangField(r, t.TitleZh, t.TitleEn, t.TitleJa, t.TitleKo, t.TitleVi, t.TitleId, t.TitleMs),
|
|
|
|
|
pickLangField(r, t.DescZh, t.DescEn, t.DescJa, t.DescKo, t.DescVi, t.DescId, t.DescMs),
|
|
|
|
|
pickLangField(r, t.BodyZh, t.BodyEn, t.BodyJa, t.BodyKo, t.BodyVi, t.BodyId, t.BodyMs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func scanResourceTextI18n(
|
|
|
|
|
titleZh, titleEn, titleJa, titleKo, titleVi, titleId, titleMs string,
|
|
|
|
|
descZh, descEn, descJa, descKo, descVi, descId, descMs string,
|
|
|
|
|
bodyZh, bodyEn, bodyJa, bodyKo, bodyVi, bodyId, bodyMs string,
|
|
|
|
|
) resourceTextI18n {
|
|
|
|
|
return resourceTextI18n{
|
|
|
|
|
TitleZh: titleZh, TitleEn: titleEn, TitleJa: titleJa, TitleKo: titleKo, TitleVi: titleVi, TitleId: titleId, TitleMs: titleMs,
|
|
|
|
|
DescZh: descZh, DescEn: descEn, DescJa: descJa, DescKo: descKo, DescVi: descVi, DescId: descId, DescMs: descMs,
|
|
|
|
|
BodyZh: bodyZh, BodyEn: bodyEn, BodyJa: bodyJa, BodyKo: bodyKo, BodyVi: bodyVi, BodyId: bodyId, BodyMs: bodyMs,
|
|
|
|
|
}
|
2026-05-25 00:09:44 +08:00
|
|
|
}
|