設定檔

Loader

定義翻譯內容的載入方式。


loader

defineIntorConfig({
  loader: {...},
});

mode

指定翻譯內容的載入模式。

  • "local":從本地檔案系統載入翻譯內容
  • "remote":透過 HTTP 遠端載入翻譯內容

預設為 undefined(不啟用 Loader)

defineIntorConfig({
  loader: {
    mode: "local",
  },
});

namespaces

local | remote

指定要載入的 頂層命名空間(namespace) 列表。

不論來源為本地檔案系統或 HTTP 遠端來源,皆適用相同的命名空間規則。

namespaces 代表 locale 節點下的第一層結構:

<root>/
└─ en/
   ├─ index.json        → always included
   ├─ ui.json           → namespace: "ui"
   └─ error/index.json  → namespace: "error"

index 為特殊保留節點,預設一律會被載入。

defineIntorConfig({
  loader: {
    namespaces: ["ui"],
  },
});

// 載入結果:
// - en/index
// - en/ui/**
// - en/error/**(未指定,將被忽略)

Localnamespaces 為選用。若未指定,預設會載入該 locale 下的所有命名空間。
Remotenamespaces 為必要。若未指定,僅會載入該 locale 下的 index 檔案。

concurrency

local | remote

同時進行翻譯內容載入的最大併發數。

預設為 10

rootDir

local

翻譯內容的根路徑設定,用於解析本地翻譯檔案。

預設為 "messages"

url

remote

用於請求翻譯內容的 HTTP 遠端基礎 URL。

headers

remote

請求遠端翻譯內容時所附加的 HTTP headers。

server.loader / client.loader

Intor 允許依執行環境分別定義 loader 設定。

defineIntorConfig({
  server: {
    loader: {
      mode: "local",
      rootDir: "messages",
    },
  },
  client: {
    loader: {
      url: "https://cdn.example.com/messages",
    },
  },
});
  • server.loader:用於 Server 環境
  • client.loader:用於 Client 環境(僅支援 remote loader)