PrismatiXEngine
故事與素材

多語系

為同一個遊戲提供繁體中文和英文故事、介面文字與素材。

English

這章設定的是遊戲內語言。CLI 的 --locale 只設定語言標籤,台詞與介面文字需要自己翻譯。

加入支援語言

prismatix.json 合併:

{
  "defaultLocale": "zh-TW",
  "supportedLocales": ["zh-TW", "en"],
  "storyIndex": "Content/story.pxstoryindex"
}

已有 Story index 時,直接修改原本的檔案。CLI 會依 supportedLocales 載入 Content/Localization/<locale>.json,因此加入英文後也要建立 en.json

翻譯介面文字

Content/Localization/zh-TW.json

{
  "format": "PrismatiXLocale",
  "schemaRevision": 2,
  "locale": "zh-TW",
  "fontChain": ["Content/Fonts/NotoSansTC-Bold.ttf"],
  "strings": {
    "ui.welcome": "歡迎來到第一道光",
    "ui.start": "開始遊戲",
    "ui.load": "讀取進度"
  },
  "resources": {}
}

Content/Localization/en.json

{
  "format": "PrismatiXLocale",
  "schemaRevision": 2,
  "locale": "en",
  "fontChain": ["Content/Fonts/NotoSansTC-Bold.ttf"],
  "strings": {
    "ui.welcome": "Welcome to First Light",
    "ui.start": "Start game",
    "ui.load": "Load progress"
  },
  "resources": {}
}

已有翻譯檔時,保留其他字串和資源。TSX 透過 bind={{ text: 'locale.ui.welcome' }} 讀取 strings 中的文字。

fontChain 指定字型;resources 可為不同語言指定圖片等素材。它們仍須放在專案中,並使用合法的相對路徑。

翻譯故事

中文故事保留在 Story/main.pxstory,另複製一份到 Story/en/main.pxstory。翻譯台詞、旁白和選項文字,保留標籤、指令、角色別名、變數、資源參照和 ID。

同一句台詞在兩份檔案中使用相同 ID:

; Story/main.pxstory 的片段
[id main.question]
@guide
今晚,你想先做什麼?
; Story/en/main.pxstory 的對應片段
[id main.question]
@guide
What would you like to do this evening?

上面只列出一小段;兩份故事都需要保留完整流程。接著建立 Content/story.pxstoryindex,指定各語言的故事來源:

{
  "format": "PrismatiXStoryIndex",
  "schemaRevision": 2,
  "id": "first-light.story",
  "entryScene": "main",
  "chapters": [
    {"id": "chapter-1", "title": "First Light", "scenes": ["main"]}
  ],
  "scenes": [
    {
      "id": "main",
      "title": "First evening",
      "sources": {
        "zh-TW": "Story/main.pxstory",
        "en": "Story/en/main.pxstory"
      },
      "requiredLabels": ["start"]
    }
  ]
}

這裡使用預設的 main 場景。自訂過故事入口時,確認它與 entryScene 一致。新增場景要同步更新 chaptersscenes;Story index 並不提供任意跨檔 jump 語法。

保持兩種語言的流程對應

執行中切換語言時,引擎需要找到目前台詞在另一語言的位置,因此對應的文件、ID 和操作類型都要一致。

例如把一句中文拆成三句英文,或把對話改成旁白,就改變了操作結構。初次製作多語系時,先維持一對一翻譯;需要重排劇情,再另外安排切換與讀檔測試。

測試翻譯

先執行 prismatix validate my-game,再分別以 zh-TWen 作為 defaultLocale 啟動,確認兩份故事都能載入。完成後恢復預定的預設語言。

有語言切換 UI 時,再測試遊戲中途切換。檢查長選項、缺字、標點、換行、對話紀錄和語音;角色檔中固定的顯示名稱也要檢查,因為更換故事語言不會自動翻譯所有角色欄位。

最後在兩種語言各建立測試存檔,重新啟動 Player 並讀取,確認語言和故事位置都正確。

實作參考:Locale schemaStory index載入流程語言切換

On this page