ข้ามไปยังเนื้อหาหลัก

การผสานรวมกับ Framework

ขั้นตอนการตั้งค่า champollion กับ framework ยอดนิยม

Hugo (TOML / YAML / Markdown)

โครงสร้างโปรเจกต์

Hugo ใช้ i18n/ สำหรับการแปลสตริง และ content/ สำหรับเนื้อหาหน้า:

my-hugo-site/
├── i18n/
│ ├── en.toml ← source of truth
│ ├── fr.toml
│ └── ja.toml
├── content/
│ ├── posts/
│ │ ├── hello.md ← source (English)
│ │ ├── hello.fr.md
│ │ └── hello.ja.md
│ └── about.md
└── .env.local

การตั้งค่า

npm install --save-dev champollion
champollion.config.json
{
"version": 3,
"inputLocale": "en",
"localesDir": "./i18n",
"contentDir": "./content",
"format": "auto",
"languages": ["fr", "de", "ja", "es", "ko", "zh"]
}
champollion sync # sync i18n string files + content files
champollion sync --dry # preview changes without writing

รายละเอียดการแปลเนื้อหา

Front matter: รองรับทั้งตัวคั่น YAML (---) และ TOML (+++) แปล title, description, summary, subtitle, caption และ linkTitle ตามค่าเริ่มต้น ฟิลด์อื่นๆ ทั้งหมด (date, draft, tags, weight, slug ฯลฯ) จะถูกเก็บรักษาไว้ ปรับแต่งได้ด้วย translatableFields ในไฟล์ config ของคุณ

การป้องกันบล็อก: บล็อกโค้ด, Hugo shortcodes, inline code และ raw HTML จะถูกป้องกันโดยอัตโนมัติโดยใช้ Unicode sentinel placeholders โดยจะผ่านไปโดยไม่มีการเปลี่ยนแปลง

รูปแบบชื่อไฟล์: เป็นไปตามรูปแบบการแปลตามชื่อไฟล์ของ Hugo:

  • my-post.mdmy-post.fr.md
  • my-post.en.mdmy-post.fr.md (ตัดส่วนต่อท้ายของต้นฉบับออก)

ข้ามไฟล์ที่มีอยู่: ไฟล์ที่แปลแล้วจะไม่ถูกเขียนทับ ลบไฟล์เป้าหมายเพื่อบังคับให้แปลใหม่

รูปแบบพหูพจน์

locale แบบ TOML และ YAML รองรับรูปแบบพหูพจน์ CLDR:

[items]
one = "{{ .Count }} item"
other = "{{ .Count }} items"

แสดงภายในเป็น items.one และ items.other สำหรับการ diff จากนั้นจะถูก serialize กลับเป็นรูปแบบที่แบ่งส่วนที่ถูกต้องเมื่อบันทึก