Word Body Translated but the Header Wasn't? Here's Why

When translating multi-chapter Word documents, a common issue is this: the main text has been perfectly replaced with the target language, yet the headers and f

Word headers and footers are easy to miss when you translate a long document. The body text changes, but the header still shows the original language, or a script that tries to fix it adds content where it shouldn't go. This guide explains why that happens and how to handle headers safely.

You will learn how Word stores headers per section, why is_linked_to_previous matters, and how to skip linked headers so you don't break the layout. The guide also includes a worked example, a Python sample, and a checklist for reviewing the result.

Keep backups of your files and check every result against the criteria below before you deliver a document.

Why does a Word header stay untranslated? The short answer

The header is attached to each section, and a section that is linked to the previous section has no text of its own, so translating it blindly can break the document's layout.

Your situationWhat to doWhy
A section's header is linked to the previous sectionSkip it; do not translate itIts text is inherited, so writing to it creates a new header definition
A section has its own headerTranslate it, then check the resultOnly independent headers have source text that needs translating
You need a different header from a certain section onwardSet is_linked_to_previous to False first, then replace the textThis mirrors Word's "unlink" action and keeps the inheritance chain intact
Headers contain page numbers or datesTranslate only the plain text runsField codes such as page numbers and dates should stay as they are
The document is protected by IRM or uses VBA-generated header contentSkip automated processing and flag it for manual reviewThese cases fall outside what the script handles

Why headers go wrong in multi-chapter documents

When you translate a multi-chapter Word document, you may see one of two problems:

  • The header keeps the original language. The main text is fully translated, but headers and footers still show the source language.
  • Redundant content appears. To fix the first problem, a script loops through every section header and translates it. Pages that were meant to inherit the previous section's header now receive their own content, which disrupts the layout.

This is not a fault of the OCR or machine translation engine. It comes from how OpenXML handles the is_linked_to_previous property.

How python-docx stores headers

In python-docx and the underlying XML, a header does not belong to each page. It belongs to the Section object.

  • When a section's header is linked to the previous section, it contains no text definition. It only refers to the effective header of the section before it.
  • If you read paragraph text from that Header object, you may get inherited content, not the section's own text.
  • If you write translated text into that header without checking first, python-docx creates a new header definition. This breaks the original inheritance chain, wastes translation effort, and means later layout changes no longer carry through the document.

Understanding the inheritance trap of is_linked_to_previous

_Header.is_linked_to_previous is the key switch for this problem.

  • When the value is True, the section has no independent header. Its content is inherited from the nearest earlier section that does have a definition.
  • In new documents, or in sections where no header has been set, the value defaults to True.
  • This behaviour is easy to overlook: accessing header.paragraphs or changing the text creates an empty header definition automatically and sets is_linked_to_previous to False.

So the simple strategy of "loop through all sections and translate the headers" is risky. For linked headers, the correct approach is to skip them.

Only when is_linked_to_previous == False does the section have its own original text that belongs in the translation pipeline. If a particular section must start using a different header from a certain point onward, first set is_linked_to_previous to False, then replace the content. This reproduces Word's "unlink" action in code.

Synthetic example: correct and incorrect boundary handling

To test the logic, the following example uses three header states. These are synthetic samples for demonstration and do not represent real customer files. To test real documents, prepare a .docx file with at least three section breaks, a mix of linked and independent headers, and no IRM protection or VBA-generated header content.

Input setting:

  1. Section 0: independent header with the text "Chapter One".
  2. Section 1: linked to the previous section (is_linked_to_previous=True), with no independent definition.
  3. Section 2: independent header with the text "Appendix".

Expected correct output:

  • Section 0's header is translated to "Chapter 1".
  • Section 1 stays linked and is not translated, so it displays the inherited "Chapter 1".
  • Section 2's header is translated to "Appendix".

Error and boundary cases:

If the script ignores the link state and writes paragraph.text = translate(...) for Section 1, that section gets a new header definition. It may look correct for now, but the document structure has already been damaged.

An edge case that needs special care is a document where every section is linked and none has a definition. Accessing its paragraphs triggers creation. Your code should check the boolean flag before reading or writing, and handle "fully linked with no source text" as its own case instead of assigning values blindly.

Python implementation of secure header extraction and link breaking

The code below builds the sample in memory and handles header translation safely. It uses the python-docx library. Run it in a locked dependency environment, with a version compatible with API 0.8.11 or higher.

Note: This code is for educational demonstration only. It does not preserve formatting at the Run level or protect field codes, so do not use it directly in production.

from docx import Document
from docx.shared import Pt

def safe_translate_headers(doc, translate_fn):
    """
    安全翻译页眉:仅处理独立定义的页眉,保留继承关系。
    translate_fn: 接受字符串返回译文的函数
    """
    processed_count = 0
    for i, section in enumerate(doc.sections):
        header = section.header
        # 核心守卫:仅当存在独立定义时才处理
        if header.is_linked_to_previous:
            print(f"Section {i}: Linked, skipping to preserve inheritance.")
            continue

        # 此时才安全访问 paragraphs,不会意外创建新定义
        for para in header.paragraphs:
            original_text = para.text.strip()
            if original_text:
                new_text = translate_fn(original_text)
                # 安全替换:保留run格式,避免直接赋值para.text
                # 实际生产环境应增加域代码(Field)检测与跳过逻辑
                full_text = ''.join(run.text for run in para.runs)
                if full_text.strip() == original_text:
                    # 简单场景:文本完全由runs组成
                    for run in para.runs:
                        run.text = ""
                    if para.runs:
                        para.runs[0].text = new_text
                    else:
                        para.add_run(new_text)
                else:
                    # 复杂场景:包含域代码或其他元素,此处仅作标记
                    print(f"Warning: Section {i} contains complex elements, manual review needed.")
                    continue

                processed_count += 1
                print(f"Section {i}: Translated '{original_text}' -> '{new_text}'")
    return processed_count

# --- 合成示例构建与断言 ---
doc = Document()
# Sec 0: 独立页眉
doc.sections[0].header.is_linked_to_previous = False
doc.sections[0].header.paragraphs[0].text = "Original Title"

# Sec 1: 添加新节并保持链接(默认即为True)
new_section = doc.add_section()
assert new_section.header.is_linked_to_previous is True

# Sec 2: 添加新节并断开链接
appendix_sec = doc.add_section()
appendix_sec.header.is_linked_to_previous = False
appendix_sec.header.paragraphs[0].text = "Appendix Data"

# 模拟翻译函数
mock_translate = lambda x: f"[ZH]{x}"
count = safe_translate_headers(doc, mock_translate)

# 验收断言
assert count == 2, "Should only translate 2 independent headers"
assert doc.sections[1].header.is_linked_to_previous is True, "Link must be preserved"
assert "[ZH]Original Title" in doc.sections[0].header.paragraphs[0].text
print("Logic validation passed.")

Acceptance criteria and manual review red lines

Passing the code does not mean the document is ready to deliver. Headers involve layout, so use a separate checklist for them, apart from the body text. The table below lists the main checks after automated processing. It separates what the code demonstrates from what a finished delivery needs.

Check dimensionExpected observationProcessing decisionNote
Inheritance integrityA linked section did not create a new XML node✅ Pass / ❌ ReworkUnzip the .docx and check whether the number of word/header*.xml files has increased abnormally
Translation length fitThe translation does not overflow the margins or cover the main text⚠️ Adjust font size or tab stops manuallyThe code cannot see the rendered page, so review it by eye
Field codes keptPage numbers, dates and other fields are not translated✅ Pass / ❌ FixTranslate only plain text runs and skip FieldRun
Odd/even and first-page headersSpecial header types are correctly identified⚠️ Manual reviewpython-docx has limited support for features such as even_page_header
Blank headersA section that is meant to be blank has not been filled with content❌ Roll backCheck the context to confirm the blank is intentional

Where this logic does not apply: It covers standard documents with continuous section breaks only. For documents with complex nested table headers, headers generated by VBA macros, or IRM protection, automated scripts should skip them and flag them for manual review. A script that runs without errors has not necessarily covered every edge case.

Common Word translation mistakes to check

Word translation work often mixes up content problems with formatting problems. Keep checks for styles, headers, tables and other elements in the delivery checklist, so reviewers know where to look.

References and next steps

OmniDoc translates PDF, Word, PowerPoint and Excel files: scanned pages are recognized first, table cells are translated one by one so tables keep their rows and columns, and a PDF comes back as both a bilingual and a translation-only file. Paid translation adds a glossary and context translation. Test it with real samples and check the results against the checklist above.

📊 At a glance

ApproachWhat happens to linked headersResult
Translate every section headerWrites to inherited headers, creating new header definitionsBreaks the inheritance chain and disrupts the layout
Check is_linked_to_previous first (skip linked)Leaves linked headers untouchedKeeps inheritance intact; only independent headers are translated
Set is_linked_to_previous to False before replacing textUnlinks the section deliberatelyGives a section its own header when the design requires it

🎯 Which approach fits you?

If you have a multi-chapter document with mostly linked headers

Skip the linked sections and translate only the independent headers. Then review the inheritance integrity check in the table above.

If one section needs a different header from a certain point onward

Set is_linked_to_previous to False for that section first, then replace the text. This works the same way as Word's unlink action.

If your file is IRM-protected or uses VBA-generated headers

Do not run the automated script on it. Flag the file for manual review.

❓ FAQ

1. Why does my translated Word document still show the original language in the header?

Linked sections inherit their header from an earlier section, so the translation may have skipped or never reached the header that is actually displayed. Check which section holds the independent header.

2. Why does translating every header sometimes add content to pages that should have none?

Writing to a linked header creates a new header definition and sets is_linked_to_previous to False. That breaks the inheritance chain.

3. Should I always set is_linked_to_previous to False before translating a header?

No. Only do this when a section must start using its own header from a certain point. For linked headers, skip them.

4. Can the script handle page numbers and date fields in headers?

No. The demonstration code does not protect field codes. Translate only plain text runs and check fields during review.

📝 Summary

Headers in Word belong to sections, and a linked header has no text of its own, so translating it without checking can break the layout. Skip linked headers, translate only the independent ones, and check the result against the acceptance criteria before you deliver it.

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

Updated 2026-11-29