Skip to content

Commit 83f0675

Browse files
authored
Translate with a neutral tone by default in the AI editor (#146)
The Translate tab started with the first configured style (Formal) as the tone and always sent it, while the header hid it as the default and the Tone menu had no neutral option. Every AI translation came back rewritten in the Formal style. Start with a neutral tone and send no style for it, like iOS, and list Neutral first in the Tone menu using the existing ChatHeader.Tone.Neutral string.
1 parent e188309 commit 83f0675

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎packages/TranslateUI/Sources/TranslateUI/TranslateModalController.swift‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ private func entries(_ state: State, arguments: Arguments) -> [InputDataEntry] {
860860
toneMenu: nil
861861
)
862862
} else if isTranslateMode {
863-
let isDefaultTone = state.toneId == (tones.first?.id ?? "neutral")
863+
let isDefaultTone = state.toneId == "neutral"
864864
let languageWithTone: String
865865
if !isDefaultTone {
866866
languageWithTone = "\(toName) (\(toneName))"
@@ -875,7 +875,10 @@ private func entries(_ state: State, arguments: Arguments) -> [InputDataEntry] {
875875

876876
let toneItem = ContextMenuItem(strings().translateTone, handler: {}, itemImage: MenuAnimation.menu_tune_fork.value)
877877
let toneSubmenu = ContextMenu()
878-
for tone in tones {
878+
toneSubmenu.addItem(ContextMenuItem(strings().chatHeaderToneNeutral, handler: {
879+
arguments.updateTone("neutral")
880+
}, state: isDefaultTone ? .on : nil))
881+
for tone in tones where tone.id != "neutral" {
879882
toneSubmenu.addItem(ContextMenuItem(tone.title, handler: {
880883
arguments.updateTone(tone.id)
881884
}, state: state.toneId == tone.id ? .on : nil))
@@ -1039,10 +1042,8 @@ public func TranslateModalController(context: any AccountContextProtocol, from:
10391042
let isInputMode = onUse != nil || onUseRich != nil
10401043

10411044
let configTones = translationStyles(from: context)
1042-
let defaultToneId = configTones.first?.id ?? "neutral"
10431045
var initialState = State(text: text, textEntities: entities, from: from, to: Translate.normalizeLanguageCode(toLang), fromIsRevealed: !canBreak, toIsRevealed: true)
10441046
initialState.tones = configTones
1045-
initialState.toneId = defaultToneId
10461047
initialState.mode = isInputMode ? .style : .translate
10471048
initialState.styleId = ""
10481049
if isInputMode {
@@ -1210,7 +1211,7 @@ public func TranslateModalController(context: any AccountContextProtocol, from:
12101211
changeStyle = .standard(state.styleId)
12111212
}
12121213
}
1213-
} else if state.mode == .translate {
1214+
} else if state.mode == .translate && state.toneId != "neutral" {
12141215
changeStyle = .standard(state.toneId)
12151216
}
12161217
let emojify = state.mode == .fix ? false : state.emojify
@@ -1257,7 +1258,7 @@ public func TranslateModalController(context: any AccountContextProtocol, from:
12571258
} else {
12581259
changeStyle = .standard(state.styleId)
12591260
}
1260-
} else if state.mode == .translate {
1261+
} else if state.mode == .translate && state.toneId != "neutral" {
12611262
changeStyle = .standard(state.toneId)
12621263
} else {
12631264
changeStyle = nil

0 commit comments

Comments
 (0)