Skip to main content

Learn kapi › The content engine

Any format, one model

A JSON catalog and a Markdown page, read into the same blocks.

The engine reads every format into one content model: blocks of runs, where inline codes, placeholders and plurals travel with the text. This lab inspects KapiMart's catalog and its About page, pseudo-translates the catalog without losing a placeholder, and re-expresses the page as HTML through the model.

  1. A storefront's contentls srcKapiMart's interface strings are a nested JSON catalog; its About page is Markdown. Three locales sit beside the source at different stages: French complete, German two thirds, Japanese one third.
  2. Measure the catalogkapi stats src/en.jsonThirty-six strings, two hundred words. The numbers a quote starts from.
  3. The catalog as blockskapi inspect src/en.json | head -30Every string is a block named by its key, with a revision of its text. The nesting of the JSON is kept in the key path.
  4. The page as blockskapi inspect src/about.md | head -34Prose is addressed by structure: the heading, then the paragraph under it. A role says what the block is, so a heading is a heading in every format.
  5. Inline structure travels with the textkgrep plural src/en.jsonAn ICU plural or select is one block whose runs the model keeps intact, so a translation cannot drop a branch unnoticed. kgrep finds it as text, with the structure visible.
  6. Pseudo-translatekapi pseudo-translate src/en.json -o src/qps.jsonPseudo-translation accents every letter and leaves every placeholder and plural branch as it was: a cheap test of a layout before a real translation exists.
  7. Placeholders survivegrep -n 'price_each|summary' src/qps.jsonThe price placeholder and the plural's branches are untouched inside the accented text.
  8. Re-express through the modelkconv src/about.md -o src/about.htmlkconv reads one format and writes another. The Markdown heading becomes an h1 because both are the same block with the same role.
  9. The resulthead -12 src/about.htmlHeadings, paragraphs and emphasis, carried across.
  10. What the engine reads and writeskapi formatsEach format has a reader and, where it can write back, a writer, with its edit fidelity named. A faithful writer changes only the bytes that carry the text that changed.