More robust dictionary search feature, styling tweaks for widgets

This commit is contained in:
Madeline
2022-10-26 15:46:50 -04:00
parent 5999cc3533
commit e893a04e13
5 changed files with 43 additions and 15 deletions

View File

@@ -40,6 +40,32 @@ class TokiDictionaryViewModel: ObservableObject {
}
}
func filterDictionaryEnglishMode(_ input: String) {
dictionary = []
for value in fullDictionary {
var entryMatch = false
// Check if word matches toki pona form, even partially
if value.word.hasPrefix(input) {
entryMatch = true
}
// Check if any part of the word definitions match in English, even partially
for definition in value.definitions {
if definition.definition.contains(input) {
entryMatch = true
}
}
// Add to dictionary
if entryMatch == true {
dictionary.append(value)
}
}
}
func translatePhrase(_ input: String) {
dictionary = []
translatedDictionary = []