Back to Cherry Studio

Translate-on-Main

v2-refactor-temp/docs/ai/translate-on-main.md

2.0.101.9 KB
Original Source

Translate-on-Main

The current source of truth is Text Translation. This file records the v2 design outcome and is not an API reference.

Final boundary

The v2 migration moved model selection, prompt construction, and provider streaming into Main without making translation a chat turn:

text
renderer translateText
  -> IpcApi translate.open
  -> translateService.open
  -> AiStreamManager.streamPrompt
  -> WebContentsListener
  -> renderer ai.stream.* subscribers

Translation has no assistant, message history, tools, or chat RequestFeature stack. Qwen-MT receives raw text; other models receive the configured translation prompt.

translateService remains a direct-import singleton. It owns no long-lived resource or persistent side effect; the lifecycle-owned IpcApi layer owns route registration.

Persistence outcome

translate.open is a chunks-only route with { streamId, text, targetLangCode }. It has no message target and does not write message or translation-history data.

Home chat persists the current data-translation part through homeMessageListAdapter.translateMessage and ChatWrite.editMessage. Other callers keep the accumulated result locally.

The earlier optional messageId / sourceLangCode request fields, renderer-side translation overlay, and Main-side TranslationBackend lost their production consumer when Home moved to the page adapter. They were removed rather than optimized as an external store or Cache entry.

Open questions

  • Qwen-MT target language. Current code sends raw text without a providerOptions.dashscope.translation_options.target_lang override.
  • Source-language detection. useDetectLang remains renderer-owned.
  • Translation history. Text translation does not currently write translate_history rows.
  • Per-call temperature. No product surface currently requests it.