Files
sale/backend/internal/models/article.go
T
Hermes fab0aeb22e
Build and Push Docker Image / build-and-push (push) Successful in 1m3s
Build and Push Docker Image / deploy (push) Successful in 10s
feat(i18n): 公告/活动/资讯/分类/轮播改为「中文源 + 日文列」,按语言设置切换
上一版把这几类内容直接翻成日文写进主列,方向错了:它们是运营内容,
要用中文写、后台用中文看,只在语言切成日文时展示日文。

后端
· 模型加并列列(不拆表,量小且改起来不用 join;空值一律回落到中文):
  categories(name_ja, description_ja)
  banners(title_ja, desc_ja, button_ja)
  announcements(title_ja, content_ja)
  articles(title_ja, summary_ja, content_ja)
  lotteries(name_ja, description_ja)、lottery_prizes(name_ja)
· utils/i18n.go:语言解析 ?lang= > X-Lang 头 > Accept-Language > 默认 ja
· models/i18n.go:Localize* 方法在输出前把 *_ja 覆盖到同名字段,
  前端仍只认 name/title/content 一套字段,页面零改动
· 公开接口 List/GetByID 接入;后台 CRUD 接受并保存 *_ja

前端
· request 拦截器统一带 X-Lang 与 ?lang=,一处生效,不会漏接口
· 后台五个内容表单加「中文(源内容)/ 日本語」两段输入
· 切语言后整页重载(内容是后端按语言给的,不重拉就是旧语言缓存)

数据
· scripts/restore_content_zh.py:中文原文从内容日文化之前的备份读回主列,
  日文搬进 *_ja;已有 *_ja 的行跳过,可重复执行
2026-12-02 00:31:58 +08:00

32 lines
1.2 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type Article struct {
ID uint `gorm:"primaryKey" json:"id"`
Title string `gorm:"size:255;not null" json:"title"`
TitleJa string `gorm:"size:255" json:"title_ja"`
Content string `gorm:"type:text;not null" json:"content"`
ContentJa string `gorm:"type:text" json:"content_ja"`
Summary string `gorm:"size:500" json:"summary"`
SummaryJa string `gorm:"size:500" json:"summary_ja"`
CoverImage string `gorm:"size:500" json:"cover_image"`
Carousel string `gorm:"size:500" json:"carousel"`
IsPinned bool `gorm:"default:false" json:"is_pinned"`
IsPublished bool `gorm:"default:true" json:"is_published"`
SortOrder int `gorm:"default:0" json:"sort_order"`
AuthorID *uint `json:"author_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Author *User `gorm:"foreignKey:AuthorID" json:"author,omitempty"`
}
func (Article) TableName() string {
return "articles"
}