Add format_text(text, params) to fill placeholders of a resolved text #22

Open
opened 2026-11-15 21:25:50 +01:00 by michael · 0 comments
Owner

Problem

resolve_resource() returns the raw catalog text with its {name}
placeholders. Every consumer fills them itself (fragjan has its own
fill, which leaves a missing value as {name} in the output). The
adapters (cli, web, api) all need the same step, so it belongs in core.
Waiting for it: DAW/daw-modul-berhtjan-cli#13 and the question text of
the first decision_required event (DAW/daw-modul-berhtjan-cli#15).

Scope

  • one public function format_text(text, params) -> text | nil, daw_error/v1
  • {name} is replaced by params[name]; a string is inserted as given,
    an integer in base-10 notation without grouping (daw_i18n/v1, section 5)
  • a value of any other type is an error
  • a placeholder without a value is an error (no silent leaving of {name})
  • values in params that the text does not use are allowed
  • errors as daw_error/v1, one resource_id per error site

Provisional (marked as such until the contract decides)

daw_i18n/v1 does not define the form of a placeholder name nor how to
write a literal brace. Until then:

  • a placeholder is {name} with letters, digits and _ in the name
    (the form all existing catalogs use)
  • every other { or } is plain text and is output unchanged
  • a literal {name} that is not a placeholder cannot be written

See the companion issue in DAW/daw-contracts. Known texts with plain
braces today: "sources must be a list of { name, priority, catalogs }"
(DAW/daw-modul-berhtjan-core) and "... [...] oder {...} ..." (DAW/daw-lua-common).

Not in this issue

  • checking at catalog generation that translations use the same set of
    placeholders as the canonical text (daw_i18n/v1, section 5); a
    follow-up once the contract is clear

Acceptance criteria

  • signature agreed before implementation
  • tests first: string, integer, missing value, wrong type, unused
    value, plain braces, repeated placeholder
  • own texts as daw_i18n/v1 resources
  • fragjan code . and make test (Lua 5.1 and 5.4) pass
  • README documents the function

DAW/daw-contracts (daw_i18n/v1), DAW/daw-modul-berhtjan-cli#13,
DAW/daw-modul-berhtjan-cli#15

## Problem `resolve_resource()` returns the raw catalog text with its `{name}` placeholders. Every consumer fills them itself (fragjan has its own `fill`, which leaves a missing value as `{name}` in the output). The adapters (cli, web, api) all need the same step, so it belongs in core. Waiting for it: DAW/daw-modul-berhtjan-cli#13 and the question text of the first decision_required event (DAW/daw-modul-berhtjan-cli#15). ## Scope - one public function `format_text(text, params)` -> text | nil, `daw_error/v1` - `{name}` is replaced by `params[name]`; a string is inserted as given, an integer in base-10 notation without grouping (`daw_i18n/v1`, section 5) - a value of any other type is an error - a placeholder without a value is an error (no silent leaving of `{name}`) - values in `params` that the text does not use are allowed - errors as `daw_error/v1`, one `resource_id` per error site ## Provisional (marked as such until the contract decides) `daw_i18n/v1` does not define the form of a placeholder name nor how to write a literal brace. Until then: - a placeholder is `{name}` with letters, digits and `_` in the name (the form all existing catalogs use) - every other `{` or `}` is plain text and is output unchanged - a literal `{name}` that is not a placeholder cannot be written See the companion issue in DAW/daw-contracts. Known texts with plain braces today: "sources must be a list of { name, priority, catalogs }" (DAW/daw-modul-berhtjan-core) and "... [...] oder {...} ..." (DAW/daw-lua-common). ## Not in this issue - checking at catalog generation that translations use the same set of placeholders as the canonical text (`daw_i18n/v1`, section 5); a follow-up once the contract is clear ## Acceptance criteria - [ ] signature agreed before implementation - [ ] tests first: string, integer, missing value, wrong type, unused value, plain braces, repeated placeholder - [ ] own texts as `daw_i18n/v1` resources - [ ] `fragjan code .` and `make test` (Lua 5.1 and 5.4) pass - [ ] README documents the function ## Related DAW/daw-contracts (`daw_i18n/v1`), DAW/daw-modul-berhtjan-cli#13, DAW/daw-modul-berhtjan-cli#15
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-modul-berhtjan-core#22
No description provided.