Translate an app
You write an application in one language. A translation is a separate file, i18n/<locale>.mtd,
next to app.mtd. You never change a page or a table to add a language. Two commands do the
routine work: matterdata i18n sync writes the file, and matterdata i18n check counts what is
left.
This guide follows one language, German, from the first line to a release check. Read Set the language for how a reader chooses a language.
Add the language to the app block
Section titled “Add the language to the app block”List the languages the application can be drawn in. locale: stays the language of your own text,
and it must be in the list.
locale: enlocales: [en, de]The engine can draw en, de, es, fr, pt and tr. Any other value is a compile error.
Write the translation file
Section titled “Write the translation file”Run sync with the directory of the application and the language:
matterdata i18n sync dsl/examples/school deThe command creates i18n/de.mtd. It holds one entry for each text the reader can see: labels,
help texts, empty states, button texts, role names and hook messages.
It also holds a text you left out where the engine draws the name of a column or a state. You do
not choose the key of an entry. The compiler works it out from where the text is written.
Each new entry has the source text as its translation. The word todo at the end of the line
marks it:
i18n de { page.course.list.enrolments.label "Enrolments" was "Enrolments" todo}- The text in quotes is the placeholder. It is a copy of your text.
wasis the source text the translator saw. The tool writes it, and you do not change it.todosays that nobody translated the entry. The engine draws your source text for it.
The command prints what it did:
i18n/de.mtd: createdadded 502, moved 0, refreshed 0, stale 0, pruned 0, ambiguous 0Translate the entries
Section titled “Translate the entries”Open i18n/de.mtd. For each entry, write the translation in place of the copy and delete the word
todo. Keep the was text as it is.
i18n de { page.course.list.enrolments.label "Einschreibungen" was "Enrolments"}A translation must have the same {:placeholders} as its source. The text
"{:course.name} has {:count} places" needs {:course.name} and {:count} in the German text as
well. The compiler refuses a translation that drops or adds one.
You can sort the entries, add comments and split a long entry over two lines. sync keeps all of
this.
Count what is left
Section titled “Count what is left”matterdata i18n check dsl/examples/schoolThe command prints one block for each language:
de i18n/de.mtd strings 502 translated 400 79.6% todo 60 11.9% missing 42 8.3% stale 0 no-was 0 unknown 0| Line | Meaning |
|---|---|
strings |
the number of texts in the application |
translated |
entries that are not marked todo. The engine draws these in the language. |
todo |
entries that still carry the word todo |
missing |
texts that have no entry. Run sync to add them. |
stale |
translated entries whose source text changed after they were written |
no-was |
translated entries without a was |
unknown |
entries whose key names no text of the application |
The command exits with status 0 unless the application does not compile. An entry with an unknown key is a compile error. The other lines are warnings while a translator catches up, and the application stays deployable. It draws the source text for a text that has no translation.
Stop a release that is not fully translated
Section titled “Stop a release that is not fully translated”Add -strict. Now a missing text, an entry marked todo, a stale entry and an entry with no
was are errors, and the command exits with status 1:
matterdata i18n check dsl/examples/school -strictmatterdata validate <dir> -strict does the same for the whole application, and it also refuses a
hook that refuses a write with a sentence instead of a declared message name. Run one of them in
your CI. The repository does this for its own examples with make i18n-check.
Keep the translation current
Section titled “Keep the translation current”Change your source text and run sync again. It changes only what a person did not write:
| What happened | What sync does |
|---|---|
| You added a text | It adds a new entry after the entry of the text before it, marked todo. |
| You changed a text that someone translated | It changes nothing and lists the key as stale. The translation stays in use. |
You changed a text that nobody translated yet (todo, and the text is still the copy) |
It writes the new source text and the new was. This is refreshed. |
| You renamed a column, a page or another name | It moves the entry to the new key. This is moved. |
| You removed a text | It keeps the entry and lists it as unknown. |
To answer a stale entry, read the translation against the new source. Correct the translation
when it needs it. Then set was to the new source text. The check command shows the new source
text in its warning.
sync never removes an entry unless you add -prune:
matterdata i18n sync dsl/examples/school de -prune-prune removes the entries whose key no longer exists and that no key took over. A comment above a
removed entry stays.
How a moved entry is found
Section titled “How a moved entry is found”When a key disappears, sync looks at the was text of its entry. If exactly one new key has
that source text now, and no other disappeared entry has it, the entry is moved: it gets the new
key and keeps its translation. Renaming a column sku to code keeps its German label.
Two entries or two keys with the same source text, such as several columns labeled “Name”, are
ambiguous. sync leaves them as they are and lists them. Rename the key of the entry by
hand, or delete the entry and translate the new key.
The tool does not follow a key that shifts its number. When you add a check or a button
before others, the keys of the later ones change. The entries then show as stale, and you move
them by hand.
Read the report
Section titled “Read the report”sync prints one line with six counts and one line for each key it touched or left for you:
i18n/de.mtd: updatedadded 1, moved 2, refreshed 0, stale 1, pruned 0, ambiguous 0 added items.sku moved items.unique.name+sku -> items.unique.name+code stale items.name.helpRunning sync a second time changes nothing.
What the tool refuses
Section titled “What the tool refuses”| Situation | Result |
|---|---|
a language the engine cannot draw, the application’s own locale:, or a language not in locales: |
the same message the compiler gives. No file is written. |
| a translation file that does not parse, or has a key twice | The command names the line and does not edit the file. |
| an application that does not compile | The command shows the errors first. It cannot know the texts. |
The command edits the file in place. It parses its result again before it writes, and it writes a new file next to the old one and renames it, so an interrupted run leaves your file as it was.