翻譯模組文本
More languages
More actions
使用模組文件夾中的同一組語言文件,翻譯 Modloader 界面文本和 Lua 文本。通過 PR #42 添加的 shroudforge.locale() 讀取 Modloader 語言。
語言文件
為每種語言在 locales/<code>.json 下添加一個文件。Modloader 語言選擇器當前支持的代碼為 de、de-AT、de-CH、en-GB、en-US、es、fr、hi、it、ja、nl、pl、sv 和 zh。文件名必須與代碼完全一致。這些文件與 mod.json 和 extended.mod.json 放在一起。
架構已發布為 mod-locale.schema.json。語言目錄可以翻譯 mod.name 和 mod.description、設置和選項標籤、分組、操作、更新日誌條目以及 Lua strings。目錄可以只包含部分翻譯。沒有譯文的條目會保留源文本。
{
"$schema": "https://bonsaibauer.github.io/shroudforge/schemas/mod-locale.schema.json",
"settings": {
"severity": {
"label": "Log level",
"options": { "info": "Information", "warn": "Warning" }
}
},
"groups": [
{ "label": "Logging", "actions": { "write": { "label": "Write message" } } }
],
"strings": { "overlay.ready": "Ready" }
}
設置和選項的鍵與 extended.mod.json 中的鍵保持一致。分組翻譯遵循該文件中的分組順序。操作翻譯使用現有的操作 ID。已保存的值不會改變。
在 Lua 中使用相同文本
local locale = shroudforge.locale()
local ready = shroudforge.i18n.get("overlay.ready", locale, "Ready")
shroudforge.i18n.get(key, locale, fallback) 使用 Modloader 已加載的同一目錄。它會先檢查 de-AT 這樣的區域代碼,然後檢查語言代碼 de。如果缺少字符串,則返回備用文本;如果未提供備用文本,則返回鍵本身。查詢時不會重新讀取文件。PR #42 提供語言 API,此功能會將它連接到每個模組的目錄。
如果無法讀取配置而使 shroudforge.locale() 返回 en,目錄查詢會先檢查 en-GB.json,然後檢查 en.json。en-GB 是 Modloader 的默認英語。en-US 仍可作為顯式選擇的變體使用。
語言文件不需要 runtime 能力。ShroudForge 界面文本仍位於 Modloader 共享翻譯中。