* feat(i18n): add zh-TW locale support (backend infrastructure) - 新增 LanguageType.ZH_TW 枚舉值 - 擴展 _lang_to_locale() 映射支援 zh-TW - 創建 zh_TW 翻譯檔案結構 (messages.po + game_configs.po) Closes #114 * feat(i18n): add zh-TW locale support (translation completion) 完成繁體中文語言的完整翻譯工作: ## 後端翻譯 - 將 messages.po 和 game_configs.po 轉換為繁體中文 - 編譯生成對應的 .mo 檔案 - 使用 OpenCC 's2t' 轉換器進行簡繁轉換 ## 前端翻譯 - 新增 zh-TW.json 語言檔案 - 更新 index.ts 註冊 zh-TW 語言 - 修正 UI 語言標籤為「繁體中文」 ## 翻譯統計 - messages.po: 701 個 msgid(動態字串、戰鬥、奇遇等) - game_configs.po: 2972 個 msgid(遊戲配置) - zh-TW.json: 347 行(前端 UI) * feat(i18n): add zh-TW optimizations and tests ## 可選優化 1:用語本地化 - 修正前端 UI 詞彙為台灣繁體習慣 - 主要修正項目: - 菜單 -> 選單 - 設置 -> 設定 - 加載 -> 載入 - 保存 -> 儲存 - 程序 -> 程式 - 其他 UI 用語調整 ## 可選優化 2:測試覆蓋 - 新增 test_i18n_zh_tw.py 測試檔案 - 涵蓋 13 個測試用例: - 語言枚舉驗證 - 語言切換測試 - 日期格式驗證 - 動態翻譯測試 - 境界/動作/情緒翻譯測試 - 檔案完整性檢查 - 翻譯覆蓋率驗證 - 回退機制測試 ## 測試結果 - 所有 13 個測試用例通過 - 翻譯覆蓋率 > 95% * fix(i18n): add polib skip check to translation coverage test * feat(i18n): add zh-TW column to glossary with Taiwan localization
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from enum import Enum
|
|
|
|
class LanguageType(Enum):
|
|
ZH_CN = "zh-CN"
|
|
ZH_TW = "zh-TW"
|
|
EN_US = "en-US"
|
|
|
|
class LanguageManager:
|
|
def __init__(self):
|
|
self._current = LanguageType.ZH_CN
|
|
|
|
@property
|
|
def current(self) -> LanguageType:
|
|
return self._current
|
|
|
|
def set_language(self, lang_code: str):
|
|
try:
|
|
# 尝试直接通过值匹配.
|
|
self._current = LanguageType(lang_code)
|
|
except ValueError:
|
|
# 如果匹配失败,默认为 zh-CN.
|
|
self._current = LanguageType.ZH_CN
|
|
|
|
# Reload i18n translations when language changes.
|
|
from src.i18n import reload_translations
|
|
reload_translations()
|
|
|
|
# Update paths and reload game configs
|
|
from src.utils.config import update_paths_for_language
|
|
update_paths_for_language(self._current.value)
|
|
|
|
try:
|
|
from src.utils.df import reload_game_configs
|
|
reload_game_configs()
|
|
except ImportError:
|
|
# Prevent circular import crash during initialization
|
|
pass
|
|
|
|
try:
|
|
from src.classes.name import reload as reload_names
|
|
reload_names()
|
|
except ImportError:
|
|
pass
|
|
|
|
|
|
def __str__(self):
|
|
return self._current.value
|
|
|
|
# 全局单例
|
|
language_manager = LanguageManager()
|