创建工程

This commit is contained in:
2026-06-03 21:53:25 +08:00
parent 5f33329cfd
commit 37199970c9
41 changed files with 5742 additions and 0 deletions

40
src/config.py Normal file
View File

@@ -0,0 +1,40 @@
"""Configuration loader."""
import json
from pathlib import Path
CONFIG_PATH = Path(__file__).parent.parent / "config.json"
DEFAULT_CONFIG: dict[str, str] = {
"language": "Chinese",
"raw_dir": "raw",
"wiki_dir": "wiki",
}
def load_config() -> dict[str, str]:
"""
加载项目配置。
返回
-------
dict[str, str]
配置字典,包含 language、raw_dir、wiki_dir 等键。
"""
if CONFIG_PATH.is_file():
with CONFIG_PATH.open(encoding="utf-8") as f:
user_config = json.load(f)
config = {**DEFAULT_CONFIG, **user_config}
else:
config = DEFAULT_CONFIG.copy()
return config
def get_language() -> str | None:
"""获取配置的语言设置,"auto" 返回 None 以启用自动检测。"""
config = load_config()
language = config.get("language", "auto")
if language.lower() == "auto":
return None
return language