A Glossary Isn't Find-and-Replace: Define Word Boundaries

The glossary contains API, does not mean that every word in the document containing these three letters should be replaced.APIs is morphological variation,apiga

If you localise documents with a terminology list, this guide is for you. A glossary entry such as API can quietly change words you never meant to touch, like APIs, or break a code identifier in the middle of a paragraph. Below, you'll learn why simple substitution fails and how to set word boundaries that keep your terms consistent.

Global substitution is tempting because it is fast. It treats every string that contains three letters as the same term, so it also changes plurals, code identifiers and words that merely contain the term. The result looks correct at a glance but carries errors that a reviewer has to hunt down.

The fix is to decide where a term starts and ends, identify candidates first, and then decide what to translate. You'll see how English and Chinese need different rules, how to test a term against near-miss strings, and how to keep a glossary verifiable over time.

How do you apply a glossary without breaking words? The short answer

Identify candidates first, then decide which ones to translate, using word boundaries that match each language.

Your situationWhat to doWhy
You find API as a standalone wordMark it as a candidate and review it against the glossary and contextStandalone matches still need a decision before replacement
You find APIsHandle it through explicit morphological rules, not a plain matchAPIs is a morphological variation, so a plain match does not cover it
You find api_gateway in codeProtect the identifier and leave it unchangedIdentifiers are generally protected
You work with Chinese termsUse Chinese-specific tokenisation or rulesEnglish word boundaries cannot simply be applied to Chinese

Why a glossary isn't find-and-replace

A glossary entry does not mean that every string containing those letters should be replaced. Three common cases show why:

  • Plurals and variations: APIs is a morphological variation of API, so it needs its own rule.
  • Code identifiers: api_gateway may be a code identifier, not prose.
  • Language differences: Chinese terminology cannot simply follow English word boundaries.

Global substitution ignores all three cases. Instead, identify candidates first, then decide whether each one should be translated. This approach is more reliable than global substitution.

Note: This guide uses synthetic samples to demonstrate the processing method. Before processing important files, keep the original copies and check the results against the boundaries and acceptance criteria you have set.

Each language needs its own matching convention

An English example with deliberately strict rules

The example in this guide is intentionally conservative:

  • An independent API is matched, and case-sensitive matching is ignored.
  • Letters, digits and underscores that appear consecutively are not matched.

This is not a complete word-segmentation rule for natural language. It does not handle plurals, possessives or contextual disambiguation.

Test with a string that is close but should not match

Before you trust a rule, test it against strings that look similar but should not match. Here is the test:

import re

def english_candidates(text, term):
    if not term:
        raise ValueError("empty term")
    pattern = re.compile(r"(?<!\w)" + re.escape(term) + r"(?!\w)", re.IGNORECASE)
    return [(m.start(), m.end(), m.group()) for m in pattern.finditer(text)]

text = "API and api; APIs, rapid, api_gateway."
found = english_candidates(text, "API")
assert [item[2] for item in found] == ["API", "api"]
assert all(text[start:end] == raw for start, end, raw in found)
assert english_candidates("api_gateway", "API") == []
assert english_candidates("APIs", "API") == []
assert english_candidates("(API)", "API")[0][2] == "API"
try:
    english_candidates(text, "")
except ValueError:
    pass
else:
    raise AssertionError("empty glossary term accepted")

Mark candidates before replacing

Keep code in place and map positions

Matched candidates should keep their original position and text. Do not edit the content directly at this stage. This lets reviewers tell body text, links and code sections apart, and decide whether an original term should stay as it is.

In HTML or Word files, you must also map each candidate position to its structural node. Writing back the whole concatenated string based on position is not enough.

Compare the scenarios

The table below shows what this example selects and what each scenario needs next.

ScenarioWhat this example selectsFurther strategy
Independent APISelected as a candidateReviewed against the glossary and context
APIsNot matchedMorphological rules are maintained explicitly
api_gatewayNot matchedIdentifiers are generally protected
Chinese termNot covered by this exampleUses Chinese-specific tokenisation or rules

Case handling and boundaries

Unicode case rules and linguistic conventions do not always match one-to-one. This example focuses on simple English terminology. It should not be generalised into a term recogniser that works correctly for every language.

For large term lists, you also need to handle:

  • Overlapping candidates, so one match does not block another.
  • Longest-match parsing, so longer terms win over shorter ones.
  • Version management, so the same paragraph does not produce repeated conflicts.

For regular-expression details, see the Python re documentation.

Make the glossary a verifiable convention

The OmniDoc (Product Entry) website introduces its terminology list feature. When you evaluate it, select real samples that include main text, code identifiers and morphological variations. Then compare the output with the translation to check that each term is used in the right context.

A terminology list is valuable because it keeps your team's word choices consistent, not because it replaces more words mechanically.

📊 At a glance

The two approaches differ in how they treat the cases this guide covers.

ApproachPlurals and variationsCode identifiersChinese terms
Global substitutionChanged without a ruleChanged along with proseFollows English word boundaries
Candidate-first with explicit rulesHandled by morphological rulesProtected and left unchangedUses Chinese-specific tokenisation or rules

🎯 Which approach fits you?

If you translate documents with code or identifiers

Protect identifiers such as api_gateway and check that they are left unchanged before you accept any replacement.

If your documents include plurals or variations

Write explicit morphological rules for forms such as APIs rather than relying on a plain match.

If your work is in Chinese

Use Chinese-specific tokenisation or rules, because English word boundaries do not apply.

If you manage a large term list

Plan for overlapping candidates, longest-match parsing and version management from the start.

❓ FAQ

1. Why does a glossary entry like API need word boundaries?

Without boundaries, a plain match also changes strings that merely contain the letters, such as APIs or code identifiers. Boundaries let you decide which occurrences are real candidates.

2. Does this English example cover plurals and possessives?

No. The example is deliberately strict and does not handle plurals, possessives or contextual disambiguation. Plural forms need explicit morphological rules.

3. Should I replace matches directly in the document?

Not at the candidate stage. Keep matched candidates in their original position and text, so reviewers can check body text, links and code sections before any change.

4. Can I use the same rules for Chinese terms?

No. Chinese terminology cannot simply follow English word boundaries, so it needs Chinese-specific tokenisation or rules.

📝 Summary

A glossary is a set of rules about where terms begin and end, not a list of strings to swap. Identify candidates first, protect code and identifiers, and keep each language's matching conventions separate. Test your rules against near-miss strings before you trust them with important files.

Try it now: upload a document and get it translated with the layout intact

Updated 2026-11-29