國際化與劇情本地化
自動載入節點 KND_I18n 統一管理 Godot UI 翻譯、語言設定、本地化 .ks 檔案,以及語言切換後的劇情重新載入。目前語言儲存在 display/language。
內建語言代碼為 zh_Hans、zh_Hant、en、ja 與 ko。zh-CN、tc、zh-TW 等舊值會自動轉換成規範代碼。
切換語言
gdscript
KND_Settings.set_setting("display", "language", "zh_Hant")
# 或
KND_I18n.set_locale("zh_Hant")gdscript
KND_I18n.locale_changed.connect(func(locale: String): print(locale))set_locale() 會同步 TranslationServer、儲存設定,並通知已註冊的對話管理器重新載入劇情。
劇情檔案命名
在 res://dialogues/chapter.ks 旁放置各語言版本:
text
res://dialogues/chapter.zh_Hant.ks
res://dialogues/chapter.en.ks
res://dialogues/chapter.ja.ks查找順序是完整語言代碼(pt_BR)、基礎語言(pt)、原始 .ks。切換語言時會依序嘗試以穩定的 node_id、相同索引、起始節點恢復位置。
自訂 UI 翻譯
gdscript
var translation := Translation.new()
translation.locale = "fr_CA"
translation.add_message("开始游戏", "Commencer")
KND_I18n.register_translation(translation)
KND_I18n.set_locale("fr_CA")使用 unregister_translation("fr_CA") 移除;get_available_locales() 會列出內建與自訂語言。
手動載入本地化劇情
gdscript
var shot: KND_Shot = KND_I18n.load_localized_script(
"res://dialogues/chapter.ks", "zh_Hant"
)載入失敗時會回傳 null 並輸出明確錯誤。