feat: enhance translation functionality in MessageMenubar
- Updated translateText function to accept an optional callback for handling translated text directly within the function. - Refactored MessageMenubar to utilize the new callback mechanism, improving the flow of translated content handling. - Enhanced error handling during translation to ensure better user feedback in case of failures.
This commit is contained in:
parent
8aec8a60b3
commit
900b11bdf7
@ -126,8 +126,9 @@ const MessageMenubar: FC<Props> = (props) => {
|
||||
setIsTranslating(true)
|
||||
|
||||
try {
|
||||
const translatedText = await translateText(message.content, language)
|
||||
onEditMessage?.({ ...message, translatedContent: translatedText })
|
||||
await translateText(message.content, language, (text) =>
|
||||
onEditMessage?.({ ...message, translatedContent: text })
|
||||
)
|
||||
} catch (error) {
|
||||
console.error('Translation failed:', error)
|
||||
window.message.error({
|
||||
|
||||
@ -6,7 +6,7 @@ import { getDefaultTopic } from './AssistantService'
|
||||
import { getDefaultTranslateAssistant } from './AssistantService'
|
||||
import { getUserMessage } from './MessagesService'
|
||||
|
||||
export const translateText = async (text: string, targetLanguage: string) => {
|
||||
export const translateText = async (text: string, targetLanguage: string, onResponse?: (text: string) => void) => {
|
||||
const translateModel = store.getState().llm.translateModel
|
||||
|
||||
if (!translateModel) {
|
||||
@ -25,7 +25,7 @@ export const translateText = async (text: string, targetLanguage: string) => {
|
||||
content: text
|
||||
})
|
||||
|
||||
const translatedText = await fetchTranslate({ message, assistant })
|
||||
const translatedText = await fetchTranslate({ message, assistant, onResponse })
|
||||
|
||||
const trimmedText = translatedText.trim()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user