翻譯內容

系統中實際被解析與輸出的翻譯內容。


介面

Intor 使用 LocaleMessages 作為翻譯內容的資料介面。

type LocaleMessages = Record<string, MessageObject>;
{
  "en": {
    "title": "Hello",
    "nav": {
      "about": "About"
    }
  },
  "fr": {
    "title": "Bonjour"
  }
}
  • 翻譯內容以 locale 作為最外層結構單位
  • 每個 locale 對應一個 MessageObject ,代表該語系下的完整翻譯內容結構

翻譯內容組織方式

在專案根目錄下建立 messages/ 資料夾,用來放置各語系的翻譯內容。

index.json

index.json
  • 每個語系對應一個資料夾
  • 每個語系必須以 messages/{locale}/index.json 作為唯一入口

Intor 刻意使用 {locale}/index.json 作為翻譯內容的入口, 而非採用 {locale}.json 形式。

這能讓翻譯內容在不同載入模式與工具中,都維持相同的結構與行為。