Labels, metadata and languages
Your application needs readable information to present a graph: a heading for the current step, instructions and names for the choices. Node metadata describes the step; edge labels describe the choices leaving it. ExecKernel selects those records when preparing the payload that your application uses to build its interface.
Payloads and presentation explains that relationship. Here we will configure the records and their languages using the graph from Anatomy of a graph: node 10 offers a guide through edge 101 and browser practice through edge 102. The IDs and destinations stay the same in both languages.
The complete JSON definition contains the records shown below, plus the terminals and their outputs. Each fragment selects the part being discussed.
Describe the step and its choices
Section titled “Describe the step and its choices”Start with the English presentation of node 10:
{ "metadata": [ { "node_id": 10, "lang": "en", "title": "How would you like to learn?", "description": "Choose a guide to read or an exercise to try.", "extras": { "screen": "learning-choice" } } ], "labels": [ { "edge_id": 101, "lang": "en", "text": "Read the guide" }, { "edge_id": 102, "lang": "en", "text": "Practise in the browser" } ]}node_id associates the metadata with the step, while each edge_id associates a label with a choice. The application can present the title, put the description beneath it and use the label text for its buttons.
The metadata fields provide different kinds of information:
| Field | What your application can use it for |
|---|---|
title |
Identify the step or terminal result. |
subtitle |
Add a short secondary heading when the step needs one. |
description |
Explain what the person needs to decide or what the result means. |
extras |
Carry application-defined data alongside the description. |
In this example, extras.screen gives the application a stable value it can use to select a view component. The name learning-choice is a convention defined by this application; ExecKernel carries it in the payload. A label can also include its own description and extras when a particular choice needs additional information.
Add a second language
Section titled “Add a second language”Add Spanish records to the same metadata and labels collections, keeping the English records already declared:
{ "metadata": [ { "node_id": 10, "lang": "es", "title": "¿Cómo quieres aprender?", "description": "Elige una guía para leer o un ejercicio para practicar.", "extras": { "screen": "learning-choice" } } ], "labels": [ { "edge_id": 101, "lang": "es", "text": "Leer la guía" }, { "edge_id": 102, "lang": "es", "text": "Practicar en el navegador" } ]}A node’s metadata is selected by node and language; a label is selected by edge and language. This makes the Spanish label for edge 102 another description of the same choice. The graph still has two edges, not four.
Keep application-defined values consistent where they have the same meaning. Both metadata records use "screen": "learning-choice" so the application can select the same view regardless of its visible wording. ExecKernel does not translate the values in extras or the session context.
The graph also declares its language configuration:
{ "default_lang": "en", "allowed_langs": ["en", "es"]}default_lang provides a fallback when a requested translation is missing. allowed_langs declares the languages accepted by the graph. The request must also satisfy the engine’s language policy. With this definition, requesting fr is rejected with UnknownLanguageException; it does not select the English fallback merely because French is unavailable.
Request the translated step
Section titled “Request the translated step”Once the definition is loaded as $graph and an engine is available as $engine, start a session in Spanish:
use ExecKernel\Domain\Session\Context;
$result = $engine->start( $graph, 'es', new Context(['practiceEnabled' => true]));The language argument selects presentation text. The context value satisfies the separate condition on browser practice, so both choices are available. These selected fields appear in $result->payload:
{ "type": "node", "node_id": 10, "title": "¿Cómo quieres aprender?", "description": "Elige una guía para leer o un ejercicio para practicar.", "extras": { "screen": "learning-choice" }, "edges": [ { "id": 101, "labels": [{ "text": "Leer la guía" }] }, { "id": 102, "labels": [{ "text": "Practicar en el navegador" }] } ]}This extract omits the availability fields and other presentation fields. Your application uses the IDs to request an edge and the selected texts to present it.
To show the same session in English, request another payload for its existing state:
$englishPayload = $engine->getPayload($graph, $result->state, 'en');That query leaves the position and recorded path unchanged. The following two views illustrate how your application could present the resulting texts:
When a translation is missing
Section titled “When a translation is missing”For each node’s metadata and each edge’s label, the payload selects a record in this order:
- The requested language, if present.
- The graph’s default language, if present for that record.
- The first available language for that record.
If there is no metadata at all, the payload has an empty title; if there is no label, that edge has an empty labels list. Complete the descriptions your application needs, and validate the definition before using it.
For example, remove only the Spanish label of edge 102 from the complete definition and request Spanish. The heading and the guide option remain Spanish, while the practice option uses the English label “Practise in the browser”. Selection happens independently for each record, so a partially translated graph can produce a screen containing both languages.
Provide the complete set of texts for each language you intend to offer. The selected metadata record supplies its own fields; an omitted description in that record is not filled from another translation.
Explore the same position in the Showcase
Section titled “Explore the same position in the Showcase”Open Labels and metadata, advance through its introductory tour and switch EN/ES in the header. Observe the heading, description and choices while checking that the current node and path stay the same.
For messages and links associated with the end of navigation, continue with Terminal outputs. The graph definition schema and payload reference provide the complete fields.