Refactor auto-translations and add caching

Changelog-Added: Add auto-translation caching to ruduce api usage
Closes: #843
This commit is contained in:
2023-03-30 11:15:35 -04:00
committed by William Casarin
parent 5a238502cb
commit ae82114a33
12 changed files with 225 additions and 115 deletions

View File

@@ -95,13 +95,11 @@ struct NoteContentView: View {
}
}
if size == .selected || damus_state.settings.auto_translate {
if with_padding {
translateView
.padding(.horizontal)
} else {
translateView
}
if with_padding {
translateView
.padding(.horizontal)
} else {
translateView
}
if show_images && artifacts.images.count > 0 {

View File

@@ -15,8 +15,6 @@ struct SearchHomeView: View {
@State var search: String = ""
@FocusState private var isFocused: Bool
let preferredLanguages = Set(Locale.preferredLanguages.map { localeToLanguage($0) })
var SearchInput: some View {
HStack {
HStack{
@@ -54,12 +52,17 @@ struct SearchHomeView: View {
return true
}
// If we can't determine the note's language with 50%+ confidence, lean on the side of caution and show it anyway.
guard let noteLanguage = $0.note_language(damus_state.keypair.privkey) else {
// Always show your own posts.
if $0.pubkey == damus_state.pubkey {
return true
}
return preferredLanguages.contains(noteLanguage)
// If we can't determine the note's language with 50%+ confidence, lean on the side of caution and show it anyway.
guard let noteLanguage = damus_state.translations.detectLanguage($0, state: damus_state) else {
return true
}
return damus_state.translations.preferredLanguages.contains(noteLanguage)
}
)
.refreshable {