Skip to content

Intermediate Layer Translator

Note

This documentation may contain AI-generated content. While we strive for accuracy, there might be inaccuracies. Please report any issues via:

Background

After formula and style processing, we need to translate the document while preserving all formatting, formulas, and styles. The intermediate layer translator handles this complex task by using placeholders and style preservation techniques.

Goal

  1. Translate text while preserving document structure
  2. Maintain formulas and special formatting
  3. Handle rich text with different styles
  4. Support concurrent translation for better performance

Specific Implementation

The translation process consists of several key steps:

Step 1: Translation Preparation

  1. Process paragraphs:
  2. Skip vertical text
  3. Handle single-component paragraphs directly
  4. Process multi-component paragraphs with placeholders

  5. Create placeholders:

  6. Formula placeholders for mathematical expressions
  7. Rich text placeholders for styled text
  8. Ensure placeholder uniqueness within each paragraph

Step 2: Translation Input Creation

  1. Analyze paragraph components:
  2. Regular text components
  3. Formula components
  4. Styled text components

  5. Handle special cases:

  6. Skip pure formula paragraphs
  7. Preserve original text when style matches base style
  8. Handle font mapping cases

Step 3: Translation Execution

  1. Concurrent translation:
  2. Use thread pool for parallel processing
  3. Control QPS (Queries Per Second)
  4. Track translation progress

  5. Translation tracking:

  6. Record original text
  7. Record translated text
  8. Save tracking information for debugging

Step 4: Translation Output Processing

  1. Parse translated text:
  2. Extract text between placeholders
  3. Restore formulas at placeholder positions
  4. Restore rich text with original styles

  5. Create new paragraph components:

  6. Maintain style information
  7. Preserve formula positioning
  8. Handle empty text segments

Additional Features

  1. Style preservation:
  2. Maintains original text styles
  3. Handles font size variations
  4. Preserves formatting attributes

  5. Formula handling:

  6. Preserves formula integrity
  7. Maintains formula positioning
  8. Supports complex mathematical expressions

  9. Debug support:

  10. Translation tracking
  11. JSON output for debugging
  12. Detailed logging

Limitations

  1. Vertical text is not supported

  2. Complex nested styles might not be perfectly preserved

  3. Placeholder conflicts could occur in rare cases

  4. Translation quality depends on external translation engine

Configuration Options

The translation process can be customized through TranslationConfig:

  1. qps: Maximum queries per second for translation
  2. debug: Enable/disable debug mode and tracking
  3. Translation engine specific settings