Remote Loader
從遠端資源獲取翻譯內容,實現更彈性的部署與整合策略。
載入流程
Remote Loader 會依 url 與語系組合遠端資源路徑,
並透過 namespaces 決定需載入的翻譯資源,最終請求並合併為 LocaleMessages。
Remote Loader ─▶ Collect paths ─▶ Fetch resources ─▶ LocaleMessages
翻譯內容組織方式
Remote Loader 會透過 HTTP 存取以下形式的遠端翻譯資源:
<remote-root>/en/index.json <remote-root>/en/ui.json <remote-root>/fr/index.json
<remote-root>代表 HTTP 遠端翻譯來源的根路徑。
以下為遠端翻譯資源組織示意,適用於以 object storage 為基礎的來源(如 S3、R2):
index.jsonui.jsonindex.json
- 每個語系對應一個遠端路徑節點
- 翻譯內容以 檔案為單位 提供,不支援巢狀資料夾結構
Key 結構規則
Loader 會根據 檔案名稱,推導每一筆翻譯對應的完整 Key 路徑。
- 當檔案名稱不是
index時,檔名本身也會被視為 Key 路徑中的一個節點。
<remote-root>/ └─ en/ ├─ index.json │ └─ { text: "Hello" } → Key: "text" └─ ui.json └─ { text: "Hello" } → Key: "ui.text"
使用方式
Remote Loader 透過 設定檔 啟用。
defineIntorConfig({ loader: { mode: "remote", url: "https://cdn.example.com/messages", }, });
server 與 client 可依需求使用不同的遠端設定。
defineIntorConfig({ server: { loader: { mode: "remote", url: "https://private-cdn.com/messages", headers: { authorization: "Bearer <SERVER_TOKEN>" }, }, }, client: { loader: { url: "https://public-cdn.com/messages", }, }, });