Feat/i18n (#92)
* feat: add vue-i18n * feat: add vue-i18n * feat: add vue-i18n * feat: add language class * add: en templates and configs * add: en names * refactor: name gender id and sect id * feat(i18n): add gettext infrastructure for dynamic text translation (#81) * feat(i18n): add gettext infrastructure for dynamic text translation - Add src/i18n/ module with t() translation function - Add .po/.mo files for zh_CN and en_US locales - Update LanguageManager to reload translations on language change - Add comprehensive tests (14 tests, all passing) - Add implementation spec at docs/specs/i18n-dynamic-text.md Phase 1 of i18n dynamic text implementation. * feat(i18n): expand .po files with comprehensive translation entries Add translation messages for: - Battle result messages (fatal/non-fatal outcomes) - Fortune event messages (item discovery, cultivation gains) - Misfortune event messages (losses, damage, regression) - Death reason messages - Item exchange messages (equip, sell, discard) - Single choice context and option labels - Common labels (weapon, auxiliary, technique, elixir) Both zh_CN and en_US locales updated with matching entries. * test: add .po file integrity tests * feat: i18n for actions * feat: i18n for effects * feat: i18n for gathering * feat: i18n for classes * feat: i18n for classes * feat: i18n for classes * feat: i18n for classes * fix bugs * fix bugs * fix bugs * fix bugs * fix bugs * fix bugs * fix bugs * fix bugs * update csv * update world info * update prompt * update prompt * fix bug * fix bug * fix bug * fix bug * fix bug * fix bug * fix bug * fix bug * fix bug * update * update * update * update * update * update * update --------- Co-authored-by: Zihao Xu <xzhseh@gmail.com>
This commit is contained in:
43
src/classes/language.py
Normal file
43
src/classes/language.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from enum import Enum
|
||||
|
||||
class LanguageType(Enum):
|
||||
ZH_CN = "zh-CN"
|
||||
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
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self._current.value
|
||||
|
||||
# 全局单例
|
||||
language_manager = LanguageManager()
|
||||
Reference in New Issue
Block a user