translation: add workaround to reduce wasteful translation requests

Signed-off-by: Terry Yiu <git@tyiu.xyz>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Changelog-Fixed: Add workaround to fix note language recognition and reduce wasteful translation requests
This commit is contained in:
2024-01-07 14:07:09 -05:00
committed by William Casarin
parent eb41846bb9
commit bf78c0a3a0
2 changed files with 32 additions and 5 deletions

View File

@@ -23,6 +23,11 @@ public struct Translator {
}
public func translate(_ text: String, from sourceLanguage: String, to targetLanguage: String) async throws -> String? {
// Do not attempt to translate if the source and target languages are the same.
guard sourceLanguage != targetLanguage else {
return nil
}
switch userSettingsStore.translation_service {
case .purple:
return try await translateWithPurple(text, from: sourceLanguage, to: targetLanguage)
@@ -35,7 +40,7 @@ public struct Translator {
case .deepl:
return try await translateWithDeepL(text, from: sourceLanguage, to: targetLanguage)
case .none:
return text
return nil
}
}