Skip to main content

Crate cgreet

Crate cgreet 

Source
Expand description

Deterministic locale-correct greeting and salutation helpers.

cgreet owns every salutation rule: which honorifics and academic titles render, how the surname is found, and which regions punctuate the German salutation with a comma. The rules live as data in tables/*.json (see tables/README.md for the schema and the normative token normalization); tests/vectors/*.json is the executable contract every language port runs. The Typst module in typst/greet.typ reads the same canonical table; consumers share these helpers rather than mirror salutation rules in their own renderers.

Rules are sourced from the national correspondence norms (SN 010130 for ch/li, DIN 5008 for de/at; at follows DIN since ÖNORM A 1080 was withdrawn in 2018). Same input always yields the same output: no models, no I/O.

Enums§

Region
German correspondence region. Only lowercase codes: ch, li, de, at.

Functions§

de_honorific_warning
Non-blocking advisory for German records whose recipient name carries no parsable Herr/Frau honorific: the letter falls back to the generic salutation, so a human should supply the full address form (e.g. “Frau Dr. Müller”). Returns None for empty names (already covered by recipient_salutation_warning) and for complete names.
de_salutation
Locale-correct German salutation. Without a parsable honorific or surname it falls back to the generic “Sehr geehrte Damen und Herren” so the letter stays formally safe.
recipient_salutation_warning
Non-blocking advisory when the recipient name is missing: the letter still renders with the generic salutation, but a tailored opportunity should name a person. Returns None when a last name is available.
salutation_honorific
Honorific of a recipient name for the German salutation: “frau” for “Frau”, “herr” for “Herr”/“Herrn”, “” when unparsable. Abbreviations (“Hr.”, “Fr.”) are rejected: the Anrede always uses “Herr” (never the accusative “Herrn”, which belongs only in the postal address) and never abbreviates “Frau”.
salutation_last_name
Last whitespace-separated token of a recipient name for the salutation. “Dr. Jane Doe” -> “Doe”; single-token and hyphenated names survive; empty/whitespace yields “” for the generic greeting.
salutation_surname
Surname for the German salutation: last significant token after dropping the honorific, academic titles, and post-nominal grades.
salutation_titles
Academic titles preserved in the German salutation: “Dr.” stays abbreviated, “Prof.” normalises to the spelled-out “Professor”, “Dipl.-Ing.” and “Mag.” survive. Protocol keeps only the highest title, so Professor suppresses Dr.