summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-19 23:48:35 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-19 23:48:35 +0200
commitecadd969e1d96918820a1fdac0cf0d520d96ba06 (patch)
treea06ed1160bfd28ae4578d9445242e48ac9ac3ea4 /bin
parent6762ce46af3cb12bc6ae37cda762c5d95add7903 (diff)
parent329d07b49e397cb65ab52e7ca019b47313027136 (diff)
downloadcolitur-ecadd969e1d96918820a1fdac0cf0d520d96ba06.tar.gz
colitur-ecadd969e1d96918820a1fdac0cf0d520d96ba06.zip
feat: naming, localisation and the rebuilt printed output
colitur computed the calendar correctly and could not say what it had computed. A printed ordo read ef-septuagesima-sunday-2 where a reader expects Dominica in Sexagesima, and the wall calendar showed slugs in every cell. lib/naming a language table and a config file, both pure and total, parsing the INI reader Overlay_ini already had lang/ la.ini and en.ini -- 725 names, every one transcribed from the 1962 Missal and citing the line it came from templates the ordo rebuilt as an A5 booklet: one week per page, a table of contents, framed days, a colour swatch; the wall calendar now fills its sheet instead of a quarter of it tools check_citations.py verifies all 400 citations resolve, with 33 self-tests of its own Names resolve through lang -> declared fallback -> the slug, so a partial translation is usable from its first line and the fully degraded case is the old output rather than a blank page. colitur day and colitur readings are BYTE-IDENTICAL to before, verified against main rather than asserted; --lang, --raw and the lang/config subcommands are still to come, and man/colitur-templates.5 still documents the pre-naming view, so writing a custom template needs the source until that lands.
Diffstat (limited to 'bin')
-rw-r--r--bin/dune2
-rw-r--r--bin/main.ml43
2 files changed, 40 insertions, 5 deletions
diff --git a/bin/dune b/bin/dune
index 856dafe..28c04d7 100644
--- a/bin/dune
+++ b/bin/dune
@@ -6,4 +6,4 @@
; colitur.opam's frozen depends, only a new library this executable links
; against. Used by Task 12's [mkdir_p] (colitur publish, recursive
; directory creation) and nowhere else.
- (libraries colitur_kernel rite_ef colitur_render unix))
+ (libraries colitur_kernel rite_ef colitur_render colitur_naming unix))
diff --git a/bin/main.ml b/bin/main.ml
index 6f64582..b2eef28 100644
--- a/bin/main.ml
+++ b/bin/main.ml
@@ -131,6 +131,41 @@ let data_dir () =
end
| _ -> if has_data installed then installed else build_tree
+(* TEMPORARY BRIDGE (naming-and-config Task 5): [View.of_days] now takes
+ [~lang], but real CLI flag/config resolution (--lang, --raw,
+ Colitur_naming.Config) is Task 6's own scope, not this one's. Rather than
+ leave `emit`/`table`/`publish` showing bare slugs as their "resolved
+ name" -- which is precisely the defect this whole branch exists to fix --
+ this loads the shipped Latin table by default, using EXACTLY the probe
+ order [data_dir] above already uses (installed prefix, then the build
+ tree), so an installed binary finds its language file the same way it
+ finds its calendar data. Task 6 replaces this wholesale with
+ `--lang`/`--raw`/config resolution and per-command defaults; nothing
+ here is meant to survive that task unchanged. A missing or malformed
+ language file degrades to [Lang.raw] (name = slug) rather than crashing
+ the CLI -- Task 6 is what makes that case a proper, reported error. *)
+let lang_dir () =
+ let prefix = Filename.dirname (Filename.dirname Sys.executable_name) in
+ let installed = List.fold_left Filename.concat prefix [ "share"; "colitur"; "lang" ] in
+ if Sys.file_exists (Filename.concat installed "la.ini") then installed
+ else Filename.concat prefix "lang"
+
+let default_lang =
+ lazy
+ (let path = Filename.concat (lang_dir ()) "la.ini" in
+ match open_in_bin path with
+ | exception Sys_error _ -> Colitur_naming.Lang.raw
+ | ic -> (
+ match
+ Fun.protect ~finally:(fun () -> close_in_noerr ic) (fun () ->
+ really_input_string ic (in_channel_length ic))
+ with
+ | exception Sys_error _ -> Colitur_naming.Lang.raw
+ | text -> (
+ match Colitur_naming.Lang.of_string text with
+ | Ok t -> t
+ | Error _ -> Colitur_naming.Lang.raw)))
+
(* Loads the universal sanctoral layer and applies the one hand-authored
overlay over it (data/ef/adjustments.sexp -- see that file's own header):
[Overlay.apply]'s diagnostics are never silently dropped (Overlay.mli),
@@ -428,7 +463,7 @@ let emit_report ~format ~overlays ~dtstamp ~from_y ~to_y =
for y = from_y to to_y do
let days = resolved_year_days ~overlays y in
let v =
- Colitur_render.View.of_days ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y days
+ Colitur_render.View.of_days ~lang:(Lazy.force default_lang) ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y days
in
match format with
| "csv" ->
@@ -538,7 +573,7 @@ let table_report ~template ~flavour_opt ~overlays y =
exit 2
| Ok src -> (
let days = resolved_year_days ~overlays y in
- let v = Colitur_render.View.of_days ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y days in
+ let v = Colitur_render.View.of_days ~lang:(Lazy.force default_lang) ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y days in
match Colitur_render.Template.render_string ~flavour src v with
| Error e ->
(* The template is user input; a parse failure is reported with the
@@ -757,7 +792,7 @@ let publish_report ~from_y ~to_y ~out ~overlays ~dtstamp ~prune =
in
for y = from_y to to_y do
let days = resolved_year_days ~overlays y in
- let v = Colitur_render.View.of_days ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y days in
+ let v = Colitur_render.View.of_days ~lang:(Lazy.force default_lang) ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y days in
let ys = string_of_int y in
emit ("ef/" ^ ys ^ ".json") (Colitur_render.Emit_json.year v);
emit ("ef/" ^ ys ^ ".csv") (Colitur_render.Emit_csv.year v);
@@ -770,7 +805,7 @@ let publish_report ~from_y ~to_y ~out ~overlays ~dtstamp ~prune =
(fun d ->
let iso = D.to_iso8601 d.Colitur_kernel.Liturgical_day.date in
let mm = String.sub iso 5 2 and dd = String.sub iso 8 2 in
- let one = Colitur_render.View.of_days ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y [ d ] in
+ let one = Colitur_render.View.of_days ~lang:(Lazy.force default_lang) ~vocab:Rite_ef.Vocab_ef.vocab ~rite:"ef" ~year:y [ d ] in
emit (Printf.sprintf "ef/%s/%s/%s.json" ys mm dd) (Colitur_render.Emit_json.year one))
days
done;