Rendering and translations
Events are machine records — USER_LOGIN on user/42 by igor — and people read text.
memento renders every event into a rendered sentence with a Handlebars template chosen per
tenant and per locale, and keeps the vocabulary of types in a lookup file that is validated,
translated and turned into TypeScript types.
When an event is rendered
Section titled “When an event is rendered”| moment | what is rendered | where it goes |
|---|---|---|
POST /memento/events?locale=sr |
the new event, in ?locale or MEMENTO_DEFAULT_LOCALE (en) |
stored in rendered, its locale in rendered_locale, published with the event |
a read with a locale: GET /events?locale=sr, "locale" in a Filter DSL body, entity history, the UDC collections events and cpu_load with the header X-Memento-Locale: sr |
events whose stored text is in another locale, or that have none | the response only: rows are immutable and never updated |
The entity history of the event pushed in Events and instances, read with
?locale=sr:
{ "ok": true, "data": [ { "id": "0cba06fc…", "occurred_at": "2026-11-02T00:41:20.166Z", "received_at": "2026-11-02T00:41:20.169Z", "event_type": "USER_LOGIN", "instance_type": "user", "instance_id": "42", "actor_id": "igor", "payload": { "client": "web", "method": "password" }, "rendered": "Korisnik igor se prijavio.", "rendered_locale": "sr", "archived_at": null, "api_key_id": "44cebcf6…" } ], "meta": { "limit": 1, "count": 1, "next_cursor": "WyIyMDI2LTExLTAyVDAwOjQxOjIwLjE2NloiLCIwY2JhMDZmYy1kM2VhLTQ5ODItYTVlMi02Zjg4ZWM2N2Q0YTIiXQ" }}Three rules decide what a reader gets:
- Producer text wins. A
renderedsent with the event is stored verbatim withrendered_locale: null, and never re-rendered or translated. NOTEis free text. Its text ispayload.text, stored verbatim withrendered_locale: null, the same in every locale. No template.- Snapshot at push. When the stored text is already in the requested locale it is returned as stored, even if the tenant changed its template since. Other locales use the current templates.
Where the template comes from
Section titled “Where the template comes from”For an event of type T read in locale L, the locale chain is L, its parents, then the
default locale: sr-Latn-RS → sr-Latn → sr → en. memento tries, in order:
T.<each locale of the chain> tenant template → bundled template_generic.<each locale of the chain> tenant template → bundled templatebuilt-in "{{event_type}}: {{instance_type}}/{{instance_id}}"So for ?locale=sr: T.sr, T.en, _generic.sr, _generic.en. At every step a tenant’s own
template (a row of memento_template) beats the bundled one, and locale beats source: a tenant
that customised only USER_LOGIN.en still gets the bundled Serbian USER_LOGIN.sr for Serbian
readers. A template that fails at render time is logged and the built-in line is used —
rendering never fails a push or a query.
Bundled templates
Section titled “Bundled templates”packages/server/templates/<EVENT_TYPE>.<locale>.hbs, in en and sr, for the event types of
lookups.yaml (users, tickets, chats, CPU_LOAD, the APIKEY_* lifecycle) and _generic.
They use actor_id when there is one and an impersonal sentence when there is not.
User {{default actor_id instance_id}} logged in{{#if payload.ip}} from {{payload.ip}}{{/if}}.Korisnik {{default actor_id instance_id}} se prijavio{{#if payload.ip}} sa adrese {{payload.ip}}{{/if}}.{{label "EventTypes" event_type}}: {{lower (label "InstanceTypes" instance_type)}} {{instance_id}}{{#if actor_id}} (by {{actor_id}}){{/if}}.A template sees the event’s fields (event_type, instance_type, instance_id, actor_id,
occurred_at), payload, the whole event, and @locale. It can call only memento’s
helpers — default, eq / ne / and / or / not, upper / lower / capitalize,
truncate, join, json, date, number, plural (the locale’s plural rules), label (a
translated lookup label) — and Handlebars’ if, unless, each, with, lookup.
- Sandboxed. Each server has its own Handlebars environment. Unknown helpers, partials and
decorators are rejected when a template is saved (
422), as are syntax errors; at render time the data is a JSON copy of the event, prototype properties are not reachable, and the output is capped at 10 000 characters. - Plain text. The output is not HTML-escaped. A UI that puts
renderedinto HTML escapes it like any other user text.
A tenant’s override is one CLI command:
memento create-template --tenant acme --event-type USER_LOGIN --locale en --body '{{upper actor_id}} signed in to Acme'
(--file instead of --body, --replace to overwrite; list-templates, delete-template).
The Rendering & translations example shows an event next to both
bundled sources and the two sentences the server renders from them.
Lookups
Section titled “Lookups”The vocabulary lives in three files:
| file | |
|---|---|
lookups.yaml |
the terms: EventTypes, InstanceTypes, ActorTypes, UPPER_SNAKE_CASE |
i18n/translations.csv |
a label per term and locale: section,term,en,sr |
var/candidates/ |
unknown values seen at ingestion, written by the server |
# JSMemento — controlled vocabulary for event_type / instance_type / actor_type.## Terms are UPPER_SNAKE_CASE. Wire values: event types as written (USER_LOGIN),# instance and actor types in lower case (USER → "user").## Unknown values seen on POST /memento/events are NOT rejected (unless# MEMENTO_LOOKUPS_STRICT=true): they are recorded under var/candidates/ for review.# To promote one: add it here, add its row to i18n/translations.csv, then run# `pnpm memento lookups validate` and `pnpm memento lookups codegen`.
EventTypes: - USER_LOGIN - USER_LOGOUT - USER_CREATED - TICKET_CREATED - TICKET_MODIFIED - TICKET_CLOSED - CHAT_MESSAGE_SENT - CHAT_MESSAGE_SEEN - CHAT_PARTICIPANT_ADDED - NOTE - CPU_LOAD # API key lifecycle (self-service, MEMENTO_ACCOUNTS): written by the server into the key # owner's tenant when a signed-in user creates, pauses, resumes, deletes a key or changes # its daily limit — instance_type api_key, instance_id the key's prefix, actor_id the # user's email. The CLI's create-key / revoke-key write none (there is no user). - APIKEY_CREATED - APIKEY_DISABLED - APIKEY_ENABLED - APIKEY_DELETED - APIKEY_LIMIT_CHANGED
InstanceTypes: - USER - TICKET - CHAT - SERVER # An API key of the tenant (its prefix is the instance_id): see the APIKEY_* events. - API_KEY
ActorTypes: - USER - BOT - SYSTEMOn the wire, event types are sent as written (USER_LOGIN), instance and actor types in lower
case (USER → user); the actor type is read from payload.actor_type. The server loads both
files at startup: an invalid YAML or a translation sheet with errors stops the start, a missing
lookups.yaml turns lookups off with a warning.
- By default, an unknown type is accepted and recorded as a candidate: a count, first
and last seen per value in
var/candidates/<Section>.yaml, and a row ready to paste intranslations_candidate.csv. Recording is best effort and never fails a push. - Strict (
MEMENTO_LOOKUPS_STRICT=true): such an event is refused,422 validation_errorwithdetails: [{section, value, message}].
translations.csv may be edited in a spreadsheet: a BOM, CRLF, , ; or tab delimiters and
quoted cells are read. memento lookups validate reports file:line errors and warnings.
Typed lookups
Section titled “Typed lookups”memento lookups codegen turns lookups.yaml into @jsmemento/core’s
lookups.generated.ts: EVENT_TYPES and the EventType enum, KnownEventTypeSchema
(z.enum), and the same for instance and actor types. A test, and codegen --check, fail when
it is out of date. The open EventTypeSchema (any SCREAMING_SNAKE_CASE) stays the push
contract; the Known… schemas are for clients that want to restrict themselves to the
vocabulary.
- The full template and lookup manual: docs/TEMPLATES.md.
- The CLI commands: CLI.
v1.1.0released built 663143e