Pre-publication review draft
日常訳NICHIJOYAKU日本語 ↗

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

software/src/config/style_config.py110 linesDownload this file ↓

This is the same source included in the download. Each line number is a link you can save or share.

File verification detailsSHA-256 f0a3a38f3ea4235bf8efe82be35c64581f9905cf4a4e1d975e7b639ca7edc754
1"""Style configuration management."""23from __future__ import annotations45import json6from pathlib import Path78from src.models.style import TranslationStyle91011class StyleConfigManager:12    """Manages translation style configuration persistence."""1314    def __init__(self, config_path: Path | str | None = None) -> None:15        """Initialize the style config manager.1617        Args:18            config_path: Path to the style configuration file.19                        If None, uses default location.20        """21        if config_path is None:22            # Default to data/config/style.json relative to project root23            self._config_path = Path("data/config/style.json")24        else:25            self._config_path = Path(config_path)2627        self._style: TranslationStyle | None = None2829    @property30    def config_path(self) -> Path:31        """Get the configuration file path."""32        return self._config_path3334    def load(self) -> TranslationStyle:35        """Load style configuration from file.3637        Returns:38            TranslationStyle configuration. Returns default if file doesn't exist.39        """40        if self._style is not None:41            return self._style4243        if not self._config_path.exists():44            self._style = TranslationStyle()45            return self._style4647        with self._config_path.open("r", encoding="utf-8") as f:48            data = json.load(f)4950        self._style = TranslationStyle.from_dict(data)51        return self._style5253    def save(self, style: TranslationStyle | None = None) -> None:54        """Save style configuration to file.5556        Args:57            style: Style to save. If None, saves the currently loaded style.58        """59        if style is not None:60            self._style = style6162        if self._style is None:63            self._style = TranslationStyle()6465        # Ensure directory exists66        self._config_path.parent.mkdir(parents=True, exist_ok=True)6768        with self._config_path.open("w", encoding="utf-8") as f:69            json.dump(self._style.to_dict(), f, ensure_ascii=False, indent=2)7071    def get_style(self) -> TranslationStyle:72        """Get the current style configuration.7374        Loads from file if not already loaded.7576        Returns:77            Current TranslationStyle configuration.78        """79        if self._style is None:80            return self.load()81        return self._style8283    def set_style(self, style: TranslationStyle) -> None:84        """Set the current style configuration (in memory only).8586        Call save() to persist to file.8788        Args:89            style: The new style configuration.90        """91        self._style = style9293    def reset_to_default(self) -> TranslationStyle:94        """Reset to default style configuration.9596        Returns:97            The default TranslationStyle.98        """99        self._style = TranslationStyle()100        return self._style101102    def reload(self) -> TranslationStyle:103        """Force reload from file, discarding in-memory changes.104105        Returns:106            Freshly loaded TranslationStyle.107        """108        self._style = None109        return self.load()110