Adding a Language Developer Guide - edmozley/freeitsm GitHub Wiki

Adding a language, and finishing one — developer guide

How FreeITSM gets a language from nothing, or from half-done, to 100%. Companion to Internationalisation for how t() and the fallback chain work, and i18n Audit for the checks.

⚠️ This page was rewritten on 2026-09-22 and the old version was dangerous

It described a workflow where each agent wrote a whole lang/<code>/<module>.php file with the Write tool. That destroys a partial locale. A locale file holding 358 of 2,049 keys is partial, not absent, and writing it wholesale discards what is there — including anything a native speaker has reviewed. French had 4,443 existing strings when this was noticed.

Everything below describes the pipeline that replaced it, in which no agent ever writes to lang/.


1. The shape of the job

One language is 24 files and roughly 12,550 keys. Too much for one agent, so it is fanned out — but the unit of work is a chunk (one screen), not a file, and the orchestrator does every destructive step.

i18n_chunk.php          → what is missing, split into chunks an agent can do
   ↓  agents translate, writing TSV only, never touching lang/
i18n_repair_chunk.php   → fix the one malformation that recurs
i18n_verify_chunk.php   → the gate. Exit 0 = safe to merge
i18n_merge.php          → the ONLY script that writes to lang/

i18n_gated_merge.php runs the last three together and cannot be invoked in a way that merges an unverified chunk — see §6.

🔑 The split of responsibility is the whole design. Translating agents read English and write a TSV. A bad agent therefore cannot damage anything. Every destructive step stays under one pair of hands.


2. Running it

# 1. What is missing, chunked, with per-locale byte budgets
php scripts/i18n_chunk.php fr --out C:/tmp/work

# 2. Fan out agents. Each reads scripts/i18n_BRIEF.md + a glossary + its chunks.
#    See §4 for the prompt, §5 for sizing.

# 3. Verify and merge — one command, cannot be got wrong
php scripts/i18n_gated_merge.php fr C:/tmp/work/chunks

# 4. Prove it
php scripts/i18n_audit.php --all
php scripts/i18n_drift.php nn nb      # only for close-language pairs
for f in lang/fr/*.php; do php -l "$f"; done

Re-running is safe at every step. i18n_merge.php never overwrites an existing value, and i18n_chunk.php recomputes the gap from scratch — so an interrupted run needs no bookkeeping. Just run it again.


3. 🔴 Give every agent a glossary, not a rule about consistency

Extract the terms the locale already uses and hand the same file to every agent. This is what stops twelve agents inventing twelve words for "ticket", and it removes the reason an agent goes wandering through lang/<code>/ — which is what once made one read for twenty minutes and write nothing.

Take every short English value that already has a twin in the locale, keep only those used twice or more where one rendering holds at least 60% of uses. A 35% locale yields ~400 terms; a 75% locale yields ~650.

⚠️ The glossary fixes terms per ENGLISH STRING, not per concept. Malayalam's plural "analysts" mapped to a Sanskritised coinage while the far commoner singular mapped to a transliteration, so the filter accepted the minority form. Check the glossary for clashes with your own rules before launching.

🔴 Settle contested terms BEFORE a wave, never during. Pinning a correction into the instructions mid-run left Malayalam calling one role two things, because ten bundles were already in flight. The glossary is extracted first, so every clash in it is knowable up front.


4. The prompt

The hard rules live in scripts/i18n_BRIEF.md — the reusable artefact, which works for a human translator or any AI tool. Put per-locale material in an INSTRUCTIONS.<locale>.md that every agent for that locale reads, and keep each agent's own prompt to its file list plus what is specific to those chunks.

Forty lines of rules retyped per agent is forty chances for one to drift out of step. Generate the instruction files rather than hand-copying them.

Model: Sonnet. The failure modes that matter are instruction-following, and §6 catches every one mechanically. Use one model for a whole locale.

Two things every prompt needs, learned the hard way:

  • "Read the file for its key count — do not trust a number in your prompt." Three agents correctly flagged that stated counts did not match their files; the chunker was right and the orchestrator's numbers were stale. A count in a prompt is redundant with the file and can only mislead.
  • "Write each output file as soon as that chunk is done." A rate limit killed eleven agents mid-run; every file already written was recovered, every unwritten one was lost.

5. 🔴 Sizing: four calibrations, each from a measured failure

The chunk size has been wrong four different ways. Every correction came from a real death, none from reasoning in advance.

5.1 Keys are not the unit — bytes are

A 597-key chunk of short labels completed in two minutes. A 358-key chunk of help prose killed its agent. Key count predicted neither.

5.2 The write-once rule is what actually buys the size

The fix for those deaths was not a smaller chunk. It was "write the file once, do not echo it back" — both deaths were agents producing the same content twice.

Proven deliberately: seven pt-BR bundles at ~45 KB, larger than a chunk that had died, with the rule. Six of six survived. That is why the rule lives in i18n_BRIEF.md, and why the chunker's comment says the limit assumes the brief is being followed. Translating without it? Halve the number.

5.3 ⚠️ The ceiling is on OUTPUT, and scripts expand differently

--maxbytes counts English bytes, but the 64,000-token limit is on what the agent writes. Measured output ÷ English bytes, over whole completed locales:

Locale Script Expansion
nb Latin ×1.04
ms Latin ×1.12
fr Latin ×1.18
uk Cyrillic ×1.64
gu Indic ×2.04
ml Indic ×2.42

A 45 KB English bundle is ~53 KB of French and ~109 KB of Malayalam. That is exactly how two Malayalam agents died at a size five other locales had completed comfortably. i18n_chunk.php now scales each locale's budget by its measured expansion — an Indic locale gets ~19,700 English bytes rather than 40,000.

🔑 Add a measured figure before running a new script family. An unknown locale gets the Latin default, which is only safe if it is Latin.

5.4 A section over budget is split at second-level key boundaries

tickets.settings is one section of 39 KB. settings.modals, settings.sla and settings.numbering are each a coherent screen. Cutting there keeps a dialogue whole; cutting at an arbitrary key count gives you half a screen in one register and half in another.


6. 🔴 An agent's self-verification claim carries no weight

This is the single most important thing on the page. The translation work has been consistently good. It is specifically the self-checking that cannot be trusted, and that is why the gate is mechanical.

Five distinct classes of confident-but-wrong hand-back in one day:

The claim The reality
"blank-English key written with its tab, verified with awk" No tab. Twice, each naming the exact key and quoting the command it ran.
"147 lines written" 144. Three keys dropped outright.
"same keys, same order" Four keys reordered.
"all HTML tags preserved in the same order" Both <code> tags gone from one line.
"only forms.php uses tú" Eleven of twenty-five modules did. It had read five files.

⚠️ The two false blank-tab reports were indistinguishable from the two agents who genuinely had fixed it. You cannot tell from the report. Run the check.

🔴 i18n_gated_merge.php exists because verify; merge was typed instead of verify && merge and a failing chunk was merged. The harm was nil that time, by luck. A gate that depends on remembering a shell operator is not a gate.


7. 🔴 Blank-English keys: the fault that is now impossible

Seven keys in the whole product have an empty English value. Eleven failures in one day were all on those seven.

The mechanism, found on the eleventh: the Write tool strips trailing whitespace, so a line whose correct content is key + TAB + nothing cannot survive being written. The agents were not careless — they verified content they had genuinely produced, and the tool discarded it on the way out. No prompt wording could ever have fixed it, which is what eleven attempts demonstrated.

So the pipeline stopped asking. i18n_chunk.php withholds those keys and i18n_merge.php fills them, because a blank English value has exactly one correct translation in every language. i18n_repair_chunk.php remains the net for chunks generated before that change, and also strips a leaked </content> tool-call fragment — the only tabless line it will ever delete, because a key never starts with <.


8. ⚠️ Close-language pairs drift invisibly

ms/id, nb/nn, and in principle any Portuguese, Spanish or Serbo-Croatian variants. The file parses, every key is present, every placeholder survives — and it is quietly the wrong language.

Use php scripts/i18n_drift.php nn nb, in both directions. And finish one side before starting the other: Malay completed with boleh 436 and bisa zero, so Indonesian now has a settled sibling to be warned against, rather than two half-done locales drifting toward each other.

🔴 Do not do this with grep. grep -E '\bfrå\b' finds 9 occurrences in lang/nn; the real number is 608. The word ends in a non-ASCII letter and grep does not treat å as a word character, so the boundary never matches. A drift check that under-counts reports CLEAN on a drifting locale. i18n_drift.php matches with an explicit alphabet, reads values only so key names cannot produce false hits, and has a --self-test.

⚠️ Pick word pairs that are genuinely distinctive. Nynorsk's 7 bruker against 88 brukar looks like drift and is not — those are the verb, which nynorsk permits both ways. Listing it would flag correct Norwegian.


9. What 100% does NOT mean

Read i18n Audit before quoting a figure. In short: the audit compares a locale to lang/en, so a locale cannot be more complete than its source. A screen never wired to t() is missing from lang/en itself, and no locale comparison can ever reveal it.

Run php scripts/i18n_unwired.php as well. As of 2026-09-22 it reports 60 files, including the whole Checklists module UI and problem-management, which has no lang/en namespace at all.


10. The bits that are not translation

  • includes/i18n.php — SUPPORTED_LOCALES, the allow-list. Native name, not the English name: a Nynorsk reader offered only "Norwegian" cannot tell which of the two standards they are about to get. This is also what stops the locale parameter being used for path traversal.
  • Register the locale LAST on a live install. An absent file falls back cleanly; a registered locale with a half-written, unparseable file is a fatal on that module, because the per-key fallback only rescues a file that loads.
  • CHANGELOG.local.md, and the language count in README.md — a number in prose that nothing will ever tell you has gone stale.
  • Module names. FreeITSM keeps "Watchtower" and "War Room" in English in seven of eight Indian locales; Malayalam transliterates. Check the glossary before asserting a rule, and prefer what the locale already does.

11. A brand-new locale: Greek, 2026-11-11

Everything above was learnt topping up locales that already had a voice. Greek started from zero - no lang/el/, no strings to extract terms from - and went to 100% (22,945 strings, 129 chunks, 84 Sonnet bundles, every chunk verified first time) in one session. What was different:

Topping up A new locale
Glossary i18n_glossary.php extracts it from the locale extracts nothing - write it by hand before the first wave (Greek started with ~175 terms)
Voice VOICE.<loc>.txt samples existing strings empty - write a handful of sentences in the register you want
Instructions "filling the last gaps in an established voice" wrong - override it in the agent prompt: there is no existing file; the glossary is the voice
Size the locale's measured expansion unknown - see below
  • 🔴 Two copies of the expansion table. i18n_chunk.php has EXPANSION, and i18n_pack.php has its own $exp ("keep the two in step"). Adding a locale to one and not the other packed Greek at the Latin budget (40,000) while the chunks were sized for Greek. Add a new locale to both.
  • Measure, then record. Greek was guessed at ×1.80 (above Cyrillic, to be safe) and measured at ×2.18 - closer to the Indic scripts than to Cyrillic. Nobody died at 1.80, but the figure is now 2.18 in both tables. Measure with output bytes ÷ English bytes over all chunks.
  • The glossary grows during the run. Translators report the terms they coined in their final notes. Adding each to the glossary as bundles come back keeps later bundles consistent; the bundles already in flight need a term fix afterwards. For Greek that was: link (Σύνδεση clashed with sign in → Συσχέτιση), group (clashed with team → Ομάδα χρηστών), project manager (three renderings → Υπεύθυνος έργου), health, baseline, approver, lesson.
  • Term fixes are scripted and scoped, never a blind sed over lang/: run them on the chunk TSVs before the merge, limited to the module's files and, where a word has several senses, to lines whose English has the sense being fixed (the Greek Σύνδεση is right for sign in and connection, wrong only for link a record; σύνδεσμος for a URL stays). A fix that changes a noun's gender (Greek lesson: ενότητα → κεφάλαιο) breaks articles, so send it back to the translator instead.
  • Register the locale last, as §10 says: Greek was added to SUPPORTED_LOCALES only after the gated merge, the audit at 100% and a headless render of the inbox in Greek.
  • What 100% still does not fix: strings the code glues together ({count} {word}, {name} with no gender, "(s)" plurals) cannot agree in Greek. The translators worked around each one (« » quotes, του/της, -(ες) forms) and listed them - they are code bugs, not translation ones.

12. Two new locales for three modules: Korean and Vietnamese, 2026-12-02

Asked for in discussion #490; Ed chose Tickets, Assets and Knowledge to start. 7,349 strings per locale (common included - without it every translated screen sits inside an English header and menu), 42 Korean and 37 Vietnamese chunks, 53 Sonnet bundles, run in waves of 6-10. 75 of 79 chunks passed the gate first time; the other four were one lost <em>, a repeated {into} and two &mdash; entities written where English has the character - each fixed by hand on the TSV and re-verified.

What was different from Greek:

  • A module subset. i18n_chunk.php has no module filter, so the worklist was filtered to the four namespaces (common, tickets, asset-management, knowledge) between i18n_chunk.php and i18n_pack.php. An absent namespace file falls back to English cleanly, so nothing else is needed.
  • 🔴 Screens outside the subset. Translators asked what to do with "System → Database Verification" in a translated help text. The rule given (INSTRUCTIONS.<loc>.md, "Screens outside your modules"): a screen in an untranslated module keeps its English name, because that is what the reader sees. One Vietnamese translator over-applied it and left the Tickets buttons in English too; that chunk was re-run with the rule spelt out (the four modules ARE translated, so their buttons are).
  • Measured expansion: Korean ×1.19, Vietnamese ×1.25 - far below the guesses (1.90, 1.45). Hangul is 3 bytes a character but Korean UI words are short. Both tables (i18n_chunk.php EXPANSION and i18n_pack.php $exp) now carry the measured figures.
  • Glossary clashes settled during the run (added to the glossary for later waves, and fixed on the earlier TSVs with a scoped script before the merge): Korean 관리자 means both administrator and manager, so Administrator → 관리자, a person's Manager → 매니저; Korean Discovery drifted three ways (→ 디스커버리); Vietnamese Lease (→ Hợp đồng thuê) and Retired (→ Đã ngừng sử dụng).
  • Code-glued strings the translators flagged (to fix in code, not translation): review.kind_hostname_reused reads garbled in English too; bulk.partial uses %f where %d looks meant; several {name} particles in Korean are written (을)를 / (으)로 so they read for any name.
  • Second wave, same day: Tasks, the self-service portal and auth (sign-in) - 1,858 strings each, 5 bundles a locale, all 22 chunks passed the gate first time. The instructions' "Screens outside your modules" list was widened first, so Tasks paths would be translated; two translators still kept a few Tasks labels in English, and drifting terms (Korean Contractor, Vietnamese Procedure, Involved, Occurrence) were unified by the scoped script before the merge. The portal and the sign-in page take their language from the browser (Accept-Language) - render them with Chrome's --accept-lang.
  • Third wave, same day: Forms, Checklists, Calendar and Change Management - 2,150 strings each, 5 bundles a locale, all 22 chunks passed the gate first time. The glossaries carried the terms settled in the first two waves (Task, Form, Approvals, Contractor, Procedure...). Five drifting terms were unified before the merge (Korean What happens next; Vietnamese What happens next, Submission, Collection, Rollback plan). Known rough edge: some translators keep a module's OWN settings path in English ("Forms → Settings → Approvals") - harmless, worth a native reviewer's eye.
  • Fourth wave, same day: Problem Management, Service Status, Software and Watchtower - 1,152 strings each, 3 bundles a locale, 13 of 14 chunks passed first time (one &mdash; again). The instructions now say a module's OWN settings paths are translated. 🔴 The Write tool strips a value's trailing space - English values that end in a space because the code glues a link or number after them lost it; the fix script restores leading and trailing spaces from the English before the merge (and one translator had used a no-break space instead). Rendering the modules also found four pages with a hard-coded <html lang="en"> (sign-in, Problem Management and its settings, change evidence) - now the reader's locale.
  • Fifth wave, same day: People, Contracts, Files and Morning Checks - 2,480 strings each, 6 bundles a locale, all 24 chunks passed first time (the trailing-space restore and term fixes run before verifying). A term can drift between waves as well as within one: Vietnamese amber was hổ phách in the Tickets/Watchtower waves and vàng in Morning Checks - fixed in the merged files, since hổ phách has no other sense there.
  • Sixth wave, same day: Workflows, Reporting, the LMS and Starters & leavers - 2,459 strings each, 7 bundles a locale, all 24 chunks passed the gate, but the gate is not the whole check. A scan of the translations for English module names found 70 lines where translators kept a translated module's screens in English (Tickets → Settings → Mailboxes, Users, Tasks, Assets, Forms, Change Management) - they assume a module outside their own is untranslated. Replace them with the exact strings the target screens use (look them up in lang/<loc>/<ns>.php, never guess). A merge code's inner text was translated once ({{merge codes}}) - the gate does not compare {{...}}, so check it separately. Korean used 작업 for both Task and a workflow Action: workflow actions are now 동작. Rendering the Workflows list found a hard-coded English "66 runs" under a column wrongly headed Actions - fixed in code, not translation.
  • Seventh wave, same day: Projects, the CMDB, Domains and the War Room - 4,622 strings each, 25 bundles (more than the 20 subagents a session may run at once, so the last five waited for slots). The instructions now list the few untranslated modules instead of the translated ones ("assume a module IS translated unless..."), and the English-screen-name scan found 6 real hits instead of wave 6's 70. A new check, labels.py: help text quotes buttons in bold (**Brief me**), and a translator who cannot see the button's own key guesses its translation - 42 bold labels differed from the real buttons. The fix swaps each one for the button's translation at the same bold position, and leaves a line alone when the bold count differs or the label is a word inside a sentence. One {timeboxes} written as {timebox} was the only gate failure. Terms unified before the merge: Korean Object (객체), Stage (단계, with Phase 페이즈), Capacity (용량), Change control (변경 통제, so it does not read as the Change Management module); Vietnamese Phase/Stage (Pha / Giai đoạn), look-alike, registrant, transfer lock, tolerance, and amber (vàng again).
  • Eighth wave, same day: the Network Mapper, Process Mapper, System Wiki, case report, Setup and help assistant - 1,435 strings each, 3 bundles a locale, every chunk passed the gate. The brief now says "every module except System is translated" and tells translators to take a quoted button name from their own chunk's keys; labels.py still found 20 bold labels to swap (versus 42). Earlier waves had been told the mappers were untranslated, so their module names had stayed English in the merged CMDB help - fixed in lang/<loc>/cmdb.php too. Rendering found hard-coded English in the Process Mapper (empty canvas, "No processes found", two tooltips, four toasts) - English in every language, fixed in code. The Process Mapper's step types (Process, Decision, Terminal, Document) are database rows an admin renames, like ticket statuses.
  • 🔑 Native review wanted. No Korean or Vietnamese speaker has read these yet. The reply on #490 invites corrections.

The drift problem, which never goes away

100% is a snapshot, not a state. Every feature that adds lang/en keys un-does parity for every locale at once. scripts/i18n_gate.php reports it, and RELEASING.md step 3a asks before a tag is cut.

See also

⚠️ **GitHub.com Fallback** ⚠️