feat: add config loader for keywords
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
"""Load keyword mappings from JSON config."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_KEYWORDS = {
|
||||||
|
"print": "இருப்பு",
|
||||||
|
"if": "இணை",
|
||||||
|
"else": "இல்லை",
|
||||||
|
"for": "ஒவ்வொரு",
|
||||||
|
"while": "வரை",
|
||||||
|
"def": "வரையறை",
|
||||||
|
"return": "திரும்ப",
|
||||||
|
"import": "மேற்கோள்கள்",
|
||||||
|
"from": "இருந்து",
|
||||||
|
"as": "இவ்வாறு",
|
||||||
|
"class": "சாம்பியன்",
|
||||||
|
"try": "கோட்பாடு",
|
||||||
|
"except": "வெளியே",
|
||||||
|
"with": "உடன்",
|
||||||
|
"True": "சரி",
|
||||||
|
"False": "தவறு",
|
||||||
|
"None": "ஒன்றுமில்லை",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def load_keywords(config_path: Path | str) -> dict[str, str]:
|
||||||
|
"""Load keywords from JSON file, merge with defaults."""
|
||||||
|
defaults = DEFAULT_KEYWORDS.copy()
|
||||||
|
|
||||||
|
path = Path(config_path) if isinstance(config_path, str) else config_path
|
||||||
|
if path.exists():
|
||||||
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
|
user_keywords = json.load(f)
|
||||||
|
defaults.update(user_keywords)
|
||||||
|
|
||||||
|
return defaults
|
||||||
|
|||||||
Reference in New Issue
Block a user