diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-23 21:51:40 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-23 21:51:40 +0200 |
| commit | 4c776396115c8120c3e1cb8fda993449fcdcd326 (patch) | |
| tree | 0144fb325663dde063057a5ec568c59d4cbe79da /internal/config | |
| parent | bfa8df7b36ccbd44703e0705d51a2ed553a23164 (diff) | |
| download | lectio-4c776396115c8120c3e1cb8fda993449fcdcd326.tar.gz lectio-4c776396115c8120c3e1cb8fda993449fcdcd326.zip | |
i18n: ui_language config (default en) for UI chrome across cli/tui/web; version labels localised
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 20 | ||||
| -rw-r--r-- | internal/config/config.toml | 1 | ||||
| -rw-r--r-- | internal/config/config_test.go | 37 |
3 files changed, 58 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index e501cf8..dd81544 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -51,6 +51,23 @@ func NormalizeDisplay(display string) string { return d } +// validUILanguages are the two UI chrome languages lectio understands. +var validUILanguages = map[string]bool{ + "en": true, + "pl": true, +} + +// NormalizeUILanguage lower-cases lang and falls back to "en" when it is not +// one of validUILanguages -- the same lenient style as NormalizeDisplay (no +// error, just a safe default). +func NormalizeUILanguage(lang string) string { + l := strings.ToLower(lang) + if !validUILanguages[l] { + return "en" + } + return l +} + // Config holds lectio's user-configurable settings. type Config struct { SchemaVersion int `toml:"schema_version"` @@ -61,6 +78,7 @@ type Config struct { Width int `toml:"width"` All bool `toml:"all"` Offline bool `toml:"offline"` + UILanguage string `toml:"ui_language"` WebTheme string `toml:"web_theme"` WebPort int `toml:"web_port"` WebDisplay string `toml:"web_display"` @@ -91,6 +109,7 @@ func Default() Config { Width: 0, All: false, Offline: false, + UILanguage: "en", WebTheme: "transfiguration", WebPort: 0, WebDisplay: "horizontal", @@ -162,6 +181,7 @@ func Load() (Config, error) { return def, nil } cfg.WebDisplay = NormalizeDisplay(cfg.WebDisplay) + cfg.UILanguage = NormalizeUILanguage(cfg.UILanguage) if err := validate(cfg); err != nil { return Config{}, err diff --git a/internal/config/config.toml b/internal/config/config.toml index 3554435..c1f97db 100644 --- a/internal/config/config.toml +++ b/internal/config/config.toml @@ -6,6 +6,7 @@ default_version = "pl" # TUI start / `lectio show` default width = 0 # CLI wrap width; 0 = detect terminal all = false # default to all parts (true) or just the gospel (false) offline = false # true = never fetch; read only harvested sigla + cache +ui_language = "en" # interface language (labels/keybar/banner): "en" or "pl". Readings stay source-language. web_theme = "transfiguration" # default lectio-web theme (built-in order/season name, or a user theme in ~/.config/lectio/themes/) web_port = 0 # lectio-web port; 0 = try 1099, then any free port web_display = "horizontal" # default lectio-web layout ("uklad"): "horizontal" (stacked), "vertical" (columns), "interlinear" (verse-by-verse) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index ff513ea..616f0cd 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -107,6 +107,43 @@ func TestWebDisplayNormalizesUnknown(t *testing.T) { } } +func TestUILanguageDefault(t *testing.T) { + def := Default() + if def.UILanguage != "en" { + t.Errorf("UILanguage default wrong: got %q, want %q", def.UILanguage, "en") + } +} + +func TestUILanguageLoadsPL(t *testing.T) { + dir := t.TempDir() + t.Setenv("XDG_CONFIG_HOME", dir) + os.MkdirAll(filepath.Join(dir, "lectio"), 0o755) + os.WriteFile(filepath.Join(dir, "lectio", "config.toml"), + []byte("ui_language = \"pl\"\n"), 0o644) + cfg, err := Load() + if err != nil { + t.Fatal(err) + } + if cfg.UILanguage != "pl" { + t.Errorf("UILanguage = %q, want %q", cfg.UILanguage, "pl") + } +} + +func TestUILanguageNormalizesUnknown(t *testing.T) { + dir := t.TempDir() + t.Setenv("XDG_CONFIG_HOME", dir) + os.MkdirAll(filepath.Join(dir, "lectio"), 0o755) + os.WriteFile(filepath.Join(dir, "lectio", "config.toml"), + []byte("ui_language = \"bogus\"\n"), 0o644) + cfg, err := Load() + if err != nil { + t.Fatal(err) + } + if cfg.UILanguage != "en" { + t.Errorf("UILanguage = %q, want %q (normalized from bogus)", cfg.UILanguage, "en") + } +} + func TestPartShown(t *testing.T) { var empty Config if !empty.PartShown("new", "psalm") { |
