diff options
Diffstat (limited to 'internal/config/config.go')
| -rw-r--r-- | internal/config/config.go | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 616af97..8ee15e1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,7 +24,7 @@ var seedTOML []byte // Version is lectio's release version, shared by every binary's // -v/--version output (lectio, lectio-ui, lectio-web). -const Version = "0.6.0" +const Version = "0.7.0" // validVersions are the five scripture versions lectio understands. var validVersions = map[string]bool{ @@ -92,6 +92,20 @@ func NormalizeUILanguage(lang string) string { return l } +// NormalizeSiglaStyle maps a sigla_style setting to one of "auto", "polish", +// "english"; anything unrecognised (incl. "") falls back to "auto". Accepts the +// short aliases "pl"/"en" for convenience. +func NormalizeSiglaStyle(s string) string { + switch strings.ToLower(strings.TrimSpace(s)) { + case "polish", "pl": + return "polish" + case "english", "en": + return "english" + default: + return "auto" + } +} + // Config holds lectio's user-configurable settings. type Config struct { SchemaVersion int `toml:"schema_version"` @@ -103,6 +117,7 @@ type Config struct { All bool `toml:"all"` Offline bool `toml:"offline"` UILanguage string `toml:"ui_language"` + SiglaStyle string `toml:"sigla_style"` WebTheme string `toml:"web_theme"` WebPort int `toml:"web_port"` WebDisplay string `toml:"web_display"` @@ -122,6 +137,23 @@ func (c Config) PartShown(lectionary, partID string) bool { return true } +// SiglaLang resolves the book dialect (a books.toml section code, "en"/"pl") +// that `lectio --ref`/`--list` use: the explicit sigla_style, or -- when "auto" +// -- the UI language. +func (c Config) SiglaLang() string { + switch c.SiglaStyle { + case "polish": + return "pl" + case "english": + return "en" + default: + if c.UILanguage == "pl" { + return "pl" + } + return "en" + } +} + // Default returns lectio's built-in configuration, used when no config file // is found and as the base that a partial config file overrides. func Default() Config { @@ -135,6 +167,7 @@ func Default() Config { All: false, Offline: false, UILanguage: "en", + SiglaStyle: "auto", WebTheme: "transfiguration", WebPort: 0, WebDisplay: "horizontal", @@ -159,6 +192,17 @@ func configPath() (path string, isDefault bool, err error) { return filepath.Join(dir, "lectio", "config.toml"), true, nil } +// BooksPath returns the path to the optional user books.toml (in the same +// directory as the config file). There is no embedded seed on disk -- absence +// means "use the built-in defaults". +func BooksPath() (string, error) { + p, _, err := configPath() + if err != nil { + return "", err + } + return filepath.Join(filepath.Dir(p), "books.toml"), nil +} + // seedIfMissing writes the embedded default config to path if nothing is // there yet. func seedIfMissing(path string) error { @@ -208,6 +252,7 @@ func Load() (Config, error) { } cfg.WebDisplay = NormalizeDisplay(cfg.WebDisplay) cfg.UILanguage = NormalizeUILanguage(cfg.UILanguage) + cfg.SiglaStyle = NormalizeSiglaStyle(cfg.SiglaStyle) if err := validate(cfg); err != nil { return Config{}, err |
