OPEN SOURCE
software/src/config/style_config.py
Read on this site and download the files you need.
Nichijoyaku was created using AI. A complete review by human biblical-language and biblical-studies specialists has not been established. Read alongside established translations and original-language resources.
← Back to the open-source guide
1"""Style configuration management."""23from __future__ import annotations45import json6from pathlib import Path78from src.models.style import TranslationStyle91011class StyleConfigManager:12"""Manages translation style configuration persistence."""1314def __init__(self, config_path: Path | str | None = None) -> None:15"""Initialize the style config manager.1617Args:18config_path: Path to the style configuration file.19If None, uses default location.20"""21if config_path is None:22# Default to data/config/style.json relative to project root23self._config_path = Path("data/config/style.json")24else:25self._config_path = Path(config_path)2627self._style: TranslationStyle | None = None2829@property30def config_path(self) -> Path:31"""Get the configuration file path."""32return self._config_path3334def load(self) -> TranslationStyle:35"""Load style configuration from file.3637Returns:38TranslationStyle configuration. Returns default if file doesn't exist.39"""40if self._style is not None:41return self._style4243if not self._config_path.exists():44self._style = TranslationStyle()45return self._style4647with self._config_path.open("r", encoding="utf-8") as f:48data = json.load(f)4950self._style = TranslationStyle.from_dict(data)51return self._style5253def save(self, style: TranslationStyle | None = None) -> None:54"""Save style configuration to file.5556Args:57style: Style to save. If None, saves the currently loaded style.58"""59if style is not None:60self._style = style6162if self._style is None:63self._style = TranslationStyle()6465# Ensure directory exists66self._config_path.parent.mkdir(parents=True, exist_ok=True)6768with self._config_path.open("w", encoding="utf-8") as f:69json.dump(self._style.to_dict(), f, ensure_ascii=False, indent=2)7071def get_style(self) -> TranslationStyle:72"""Get the current style configuration.7374Loads from file if not already loaded.7576Returns:77Current TranslationStyle configuration.78"""79if self._style is None:80return self.load()81return self._style8283def set_style(self, style: TranslationStyle) -> None:84"""Set the current style configuration (in memory only).8586Call save() to persist to file.8788Args:89style: The new style configuration.90"""91self._style = style9293def reset_to_default(self) -> TranslationStyle:94"""Reset to default style configuration.9596Returns:97The default TranslationStyle.98"""99self._style = TranslationStyle()100return self._style101102def reload(self) -> TranslationStyle:103"""Force reload from file, discarding in-memory changes.104105Returns:106Freshly loaded TranslationStyle.107"""108self._style = None109return self.load()110