Skip to content

Text transforms in QuickLauncher #18

@michaelbeijer

Description

@michaelbeijer

Summary

QuickLauncher now supports text transforms — local find-and-replace operations that run directly on the active target segment without calling an AI provider. This opens the door to a lightweight scripting layer inside Supervertaler for Trados.

What's implemented (v4.18.27)

  • New prompt type: type: transform — set this in the YAML frontmatter to mark a prompt as a text transform instead of an AI prompt
  • Find/replace rules in the content body — simple find: / replace: pairs with \uXXXX Unicode escape support and # comments
  • Built-in "Strip U+2028" transform — removes invisible Unicode LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) characters from the target segment; seeded automatically in QuickLauncher/Text operations/
  • Executed via ProcessSegmentPair — changes are committed through the Trados document model, preserving all formatting tags (bold, italic, etc.)
  • Double-space collapsing — consecutive spaces left after replacements are collapsed to a single space
  • Clipboard copy — the cleaned target text is automatically copied to the clipboard after a transform runs
  • MessageBox feedback — shows how many replacements were applied (or "No matches found")
  • Works with keyboard slots — transforms can be assigned to Ctrl+Alt+1–0 shortcuts like any other QuickLauncher prompt

Content body format

# Comments start with #
# Each rule is a find:/replace: pair. Use \uXXXX for Unicode escapes.

find: "\u2028"
replace: " "

find: "\u2029"
replace: " "

Future directions

Short term

  • Regex support (regex: instead of find:)
  • Conditional rules (if: / else:)
  • Built-in post-processing flags (normalize_spaces: true, trim: true)
  • More built-in transforms (strip zero-width spaces, normalise quotes, etc.)

Medium term

  • Variable support inside transforms ({{TARGET_SEGMENT}}, {{SOURCE_SEGMENT}})
  • Ctrl+, picker for inserting variables and Unicode escapes
  • Visual rule builder in the Prompt Editor (dropdown-based, like KnowBrainer's command builder)
  • Preview panel showing before/after when editing a transform

Long term

  • Full scripting support (C# snippets or a DSL)
  • Voice command integration — trigger transforms and QuickLauncher prompts by voice
  • Batch mode — apply a transform across all segments or filtered segments
  • Chain transforms — run multiple transforms in sequence

Architecture

Text transforms reuse the existing QuickLauncher infrastructure:

  • PromptTemplate.IsTransform — computed from type: transform in YAML frontmatter
  • PromptTemplate.ReplacementsList<TextReplacement> parsed from the content body by PromptLibrary.ParseTransformContent()
  • QuickLauncherAction and QuickLauncherSlotRunner detect transforms and call AiAssistantViewPart.RunTextTransform() instead of sending to the AI
  • RunTextTransform() uses IStudioDocument.ProcessSegmentPair() to modify IText nodes in-place, preserving inline formatting tags

Related

  • U+2028/U+2029 stripping in AI input (v4.18.26) — strips these characters before sending to AI providers
  • Batch size spinner (v4.18.26) — exposed the BatchSize setting in AI Settings

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions