aboutsummaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 55abd72..91fd8c3 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -18,6 +18,7 @@ import (
"github.com/pelletier/go-toml/v2"
+ "github.com/lukaszkasprzak/lectio/internal/bible"
"github.com/lukaszkasprzak/lectio/internal/calendar"
"github.com/lukaszkasprzak/lectio/internal/ini"
)
@@ -38,6 +39,8 @@ const configHeader = `# lectio configuration (INI). Full-line comments only (# o
# all true | false (all readings, or just the gospel)
# offline true | false (never fetch; cache/sigla only)
# ui_language en | pl (interface chrome; readings stay source-language)
+# reading_lang language for offline reading text (e.g. en, pl); blank follows ui_language
+# reading_version force a specific bible corpus code (e.g. drb, wuj); blank = auto-resolve
# sigla_style auto | polish | english | latin (citation dialect; auto follows ui_language)
# web_theme a theme name (see docs/THEMES.md)
# web_port integer; 0 = try 1099, then any free port
@@ -156,6 +159,8 @@ type Config struct {
All bool `toml:"all"`
Offline bool `toml:"offline"`
UILanguage string `toml:"ui_language"`
+ ReadingLang string `toml:"reading_lang"`
+ ReadingVersion string `toml:"reading_version"`
SiglaStyle string `toml:"sigla_style"`
WebTheme string `toml:"web_theme"`
WebPort int `toml:"web_port"`
@@ -204,6 +209,28 @@ func (c Config) SiglaLang() string {
}
}
+// ReadingCorpus resolves which bible corpus renders offline reading text:
+// an explicit reading_version, else the first corpus matching reading_lang,
+// else the first matching ui_language, else "" (caller uses the Latin vul).
+func (c Config) ReadingCorpus() string {
+ if c.ReadingVersion != "" {
+ if _, ok := bible.Meta(c.ReadingVersion); ok {
+ return c.ReadingVersion
+ }
+ }
+ for _, lang := range []string{c.ReadingLang, NormalizeUILanguage(c.UILanguage)} {
+ if lang == "" {
+ continue
+ }
+ for _, m := range bible.CorporaForLang(lang) {
+ if m.Autoselect { // skip explicit-only corpora (e.g. the incomplete wuj)
+ return m.Code
+ }
+ }
+ }
+ return ""
+}
+
// Selection maps the config onto the calendar engine's Selection: the form
// (from Lectionary: "new" -> OF, "traditional" -> EF) plus the national
// placement options, each falling back to the Universal Roman default.
@@ -507,6 +534,10 @@ func applyScalar(cfg *Config, key, val string) {
cfg.Offline = val == "true"
case "ui_language":
cfg.UILanguage = val
+ case "reading_lang":
+ cfg.ReadingLang = val
+ case "reading_version":
+ cfg.ReadingVersion = val
case "sigla_style":
cfg.SiglaStyle = val
case "web_theme":
@@ -589,6 +620,8 @@ func renderConfigINI(cfg Config) []byte {
fmt.Fprintf(&b, "all = %t\n", cfg.All)
fmt.Fprintf(&b, "offline = %t\n", cfg.Offline)
fmt.Fprintf(&b, "ui_language = %s\n", cfg.UILanguage)
+ fmt.Fprintf(&b, "reading_lang = %s\n", cfg.ReadingLang)
+ fmt.Fprintf(&b, "reading_version = %s\n", cfg.ReadingVersion)
fmt.Fprintf(&b, "sigla_style = %s\n", cfg.SiglaStyle)
fmt.Fprintf(&b, "web_theme = %s\n", cfg.WebTheme)
fmt.Fprintf(&b, "web_port = %d\n", cfg.WebPort)