CAT here means computer-assisted translation software, not the Lisp textbook or a feline. If you want to extend a CAT tool with your own checkers, converters, or formatting utilities, the reliable path is to treat each program as two halves that must agree: an internal model of the bilingual document and a set of plain-text or XML rules that operate on it. Translation memories, glossaries, tag placement, and segment state all live in strict formats, so a program that ignores those constraints will pass a quick demo and then corrupt a client's project. The workflow below covers scoping, data modeling, parsing, testing, and packaging, and it assumes you already know basic programming but have never built against a CAT file format.
Start by Naming the Output, Not the Feature
The most common failure in CAT programming is starting from "I'll write a QA checker" and only later discovering that the checker needs to read five file formats and reconstruct tag positions the tool never exposed cleanly. Invert that order. Write down the exact artifact your program must produce: a report, a modified bilingual file, a glossary in a specific column layout, or a set of warnings attached to segment numbers. Then work backward to the minimum data you must read.
A defensible one-sentence scope looks like: "Given a bilingual XLIFF file exported from a CAT tool, write a CSV listing every target segment where a term from a supplied two-column glossary appears in the source but not the target, with the segment ID and checkable text." That sentence fixes the input format, the output format, the rule, and the evidence. It also tells you what you can refuse to handle, which is the single biggest time-saver in this domain.
Set explicit exclusions from day one. If your program targets XLIFF only, say so and fail loudly on TMX or native formats. If it checks terminology but not grammar, do not quietly emit a "quality score." A scope statement that fits on an index card beats a feature list that fits on a slide, because translation file formats contain far more variety than a demo file will show you.
Learn the Two-Layer Data Model Before Writing Code
Almost every CAT workflow separates presentation from content, and your program should mirror that split. The outer layer is the container: TMX for translation memories, TBX or tab-delimited text for glossaries, XLIFF or the tool's native bilingual format for in-progress documents. The inner layer is the segment: a source string, a target string, a status, and inline markup that marks where formatting and placeholders sit.
You need two separate in-memory representations because you will do different work on each. Container handling is about IDs, languages, and matching source segments across files. Segment handling is about text transformation: normalizing whitespace, locating terms, and comparing tag positions. Mixing them produces code where a regex over the whole file accidentally rewrites an attribute inside a header. Keep a document object that owns segments, and let each segment own its source and target runs.
Terminology deserves its own small structure: the term, the source and target language codes, part of speech if present, case sensitivity, and a flag for whether matching should be exact or stemmed. Case sensitivity is not a detail you can defer. A glossary entry for "CAT" will fire on the word "cat" in running prose, and a checker that flags every lowercase animal is worse than no checker.
Working schema for a segment
| Field | Purpose | Typical source |
|---|---|---|
| Segment ID | Stable reference for reports and edits | Container (XLIFF id, TMX tuid) |
| Source text | Language to check against | Container |
| Target text | Language being checked | Container |
| Inline tags | Formatting and placeholders | Container, often opaque |
| Status | Draft, translated, approved | Container attributes |
| Term matches | Computed | Your program |
The computed column is the point. Never store your analysis back into the source file unless the user explicitly asked for it, and never overwrite the status field to express "I checked this." Status belongs to the translation tool.
Get One Real File Before You Design Anything
Synthetic test data in CAT programming is a trap. A hand-typed XLIFF with three segments will omit the namespace prefixes, the empty target elements, the inline tags with IDs that reference external skeleton files, and the stray whitespace that real exports carry. Ask for a genuine export from the tool you intend to support, with permission to use it as a test fixture, and ideally a second export from a different project.
Read that file with a text editor before reading it with code. Note the namespace declarations, whether targets are or absent when untranslated, how placeholders are encoded, and whether the file declares its source language in an attribute or a element. These facts determine your parser's shape, and they are almost never documented fully in the tool's help pages.
Follow the same discipline with glossaries and memories. A client's tab-delimited glossary may use tabs inside a term, quote characters as delimiters, or a header row that starts on line five after a title block. Your importer must decide, and state in its documentation, whether it treats the first row as headers, what encoding it assumes (UTF-8, UTF-16, or a legacy single-byte code page), and what it does with duplicate entries that differ only in case.
Minimal import routine
Prerequisites: one real export, one real glossary, and a decision about encoding. Then:
1: Detect the file type by root element and namespace, not by extension. 2: Parse the container into a document object, preserving segment order and IDs. 3: Load the glossary into term objects, recording the encoding and delimiter you detected. 4: Normalize text only for matching: collapse whitespace, decide case handling, and fold accents only if the user opted in. 5: Run the rule and store results per segment ID with the matched evidence substring. 6: Serialize the report separately from any modified file.
You know step 2 succeeded when the count of parsed segments equals the number of translatable units the tool shows for that file. If it doesn't, the parser is dropping untranslated segments, which is the classic silent bug: your checker reports zero issues because it never saw the empty targets.
Decide How to Represent Inline Tags
Inline tags are where CAT programming stops being text processing and becomes structural work. In XLIFF, translated text is interleaved with , , and elements that correspond to formatting in the original document. A program that extracts plain text, checks it, and writes it back without the tags destroys the document's formatting.
Pick one of two policies and enforce it. The read-only policy extracts text with tag positions recorded as offsets in the segment's plain-text projection, then reports findings without touching the file. The write policy must reconstruct the tagged string exactly, which means the checker's replacement text has to be re-embedded at the correct offsets, and the tag balance validated before writing.
For most first programs, choose read-only. Term checks, number checks, and tag-balance checks all work fine on a projection, and you avoid every risk of corrupting a client's file. If your scope genuinely requires writing, validate balance twice: once after parsing and once after reconstruction, comparing the multiset of tag IDs the way a lock and key must match.
Write the Rule Engine so Rules Are Data
Hard-coding each check produces a program you cannot explain to a translator, and translators are the people who will tell you whether your checker is right. Represent each check as a small record: a name, a predicate over a segment, a severity, and a message template. Then the whole product becomes a container reader, a rule list, and a reporter.
Consider three rules that cover most first projects. A term-consistency rule flags a glossary source term present in the source segment whose approved target term is absent from the target. A number rule extracts digit runs, including decimals, percentages, and thousands separators, from source and target and flags mismatches, after normalizing separator conventions per locale. A tag-balance rule compares the tag ID sequence of source and target and flags segments where a paired tag appears without its counterpart.
Test each rule against a segment you wrote by hand and a segment drawn from the real project. The hand-written one proves the logic; the real one proves the normalization. Expect the number rule to fire on legitimate differences, such as "1,000" in English becoming "1 000" with a non-breaking space in French. That is not a bug in the rule but a missing locale setting, and the fix belongs in configuration, not in logic.
Handle Placeholders and Shortcodes as Their Own Category
Software strings, help topics, and legal templates carry placeholders that must survive translation exactly: %s, {0}, {{username}}, , and variables like $total. A CAT program that treats these as ordinary text will happily let a translator reorder or delete them, and the resulting build fails.
The supported approach is to tokenize the segment before matching. Replace each recognized placeholder with a unique sentinel that no natural language contains, run your checks on the tokenized text, then map sentinels back to originals for reporting. Because the placeholder grammar varies by platform, make the pattern list a configuration file with a documented default set, and let users add their own.
Check success by round-tripping: tokenize a segment, detokenize it, and assert the result equals the original byte for byte. If your round-trip fails, the sentinel scheme is lossy, and every downstream check is suspect.
Build the Resource Layer: Memories, Glossaries, and Fragments
Translation memories are the largest data structure a beginner will touch, and the naive implementation (load everything into a dictionary) collapses on real memories of hundreds of thousands of units. Design for the working set instead. For exact matching, a hash map keyed on a normalized source string with the language pair in the key is fine. For fuzzy matching, you need an index, and a token-based inverted index or an edit-distance search over a candidate set is the standard shortcut.
Be precise about what "match" means in your program, because CAT tools use their own matching algorithms and yours will not reproduce them. State whether you perform exact, normalized exact (case and whitespace folded), or fuzzy matching, and report the match type alongside every hit. Users who expect a 75% fuzzy match will distrust a program that silently reports exact matches on lightly edited segments.
Glossary size is usually manageable, but matching cost is not: a 50,000-term glossary times 20,000 segments times a naive substring search is a billion operations. Index by first token or by length bucket, and skip segments shorter than the shortest relevant term.
Separate the Report from the Fix
Programs that both diagnose and repair are hard to trust, because a wrong fix is invisible after the fact. Build the report first: one row per finding, with segment ID, rule name, severity, the matched evidence, and a suggestion. A CSV or JSON report is enough, and it has the virtue of being checkable by a human before anyone touches the file.
If you later add a fix mode, route it through a diff. Produce a proposed change per finding, write the changed file to a new path, and emit a unified diff so the user can review every edit. Never mutate in place on the first run, and never apply a fix for a rule that has not been validated against a real project.
Treat the report as a test artifact too. Save expected reports for your fixture files and compare new runs against them; a rule that quietly changes its output gets caught, and a rule that starts failing on a previously clean file surfaces a regression.
Test With Fixtures, Not Feelings
A workable test suite for a CAT program has four layers. Unit tests cover normalization, placeholder tokenization, and each rule against small hand-written segments. Parser tests assert segment counts and IDs against the real export. Golden-file tests compare full reports for the fixture project. And a negative test asserts that a deliberately broken file (mismatched tag IDs, truncated XML) produces a clear error rather than a partial success.
Make the fixtures small but real. One XLIFF with ten segments that includes an untranslated segment, a segment with paired inline tags, a segment with a placeholder, and a segment containing a glossary term in both languages is enough to catch most parser bugs. Keep the fixtures in version control with a note about their origin and licensing, and anonymize client content before committing anything.
You know the suite is adequate when deleting any single normalization step causes at least one test to fail. If it doesn't, that step is untested, and it will break quietly in production.
Know When to Stop and Escalate
Some problems exceed a small program's remit. If your parser encounters a file whose namespace or version is not in your supported list, stop and report the unsupported version rather than guessing at its structure. If tag structure is unbalanced in the source file itself, that is a defect in the export or the original document, and repairing it belongs to the CAT tool or the document owner, not to your script. If a project's TM contains confidential material you were not cleared to process, stop processing immediately and ask the project owner how the data may be handled.
The general stop condition: when the fix requires understanding the CAT tool's internal segmentation or the client's contractual quality criteria, hand it back. Your program's job is bounded and explicit.
Package, Document, and Version the Thing
A CAT program is used by people who will not read your code, and its life is measured in project cycles. Ship a single runnable artifact with a plain configuration file, a sample fixture, and a README that states supported formats and versions, encoding assumptions, and the exact limitation of each rule. Record the tool name and version in every report header; a report from last year's export is not evidence about this year's project.
Version your data, not just your code. If a glossary format or rule set changes, bump the version and note it in the report. When a translator files a bug, the report header tells you which behavior they saw, and the fixture tells you whether you can reproduce it.
One last practical note: watch for licensing. CAT tools, their file formats, and the glossaries you process may carry terms that restrict redistribution. Your README should say plainly that fixture files are anonymized and that the program makes no claim about the ownership of processed content. That sentence takes a minute to write and prevents an awkward conversation six months later.
The design that survives contact with real projects is modest: one container parser per format, one segment model with inline tags treated as first-class, a data-driven rule engine, a report you can diff, and a test suite built from real exports. Build that skeleton and each new check is a small addition; build features first and the skeleton never forms.