From 46d49d8fdf373e020481b111cbd23bf8ee09538d Mon Sep 17 00:00:00 2001
From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sat, 25 May 2024 15:02:37 +0800
Subject: [PATCH] Only translate when string is double pinyin
---
Flow.Launcher.Infrastructure/DoublePinAlphabet.cs | 4 ++--
Flow.Launcher.Infrastructure/PinyinAlphabet.cs | 4 ++--
Flow.Launcher.Infrastructure/StringMatcher.cs | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Flow.Launcher.Infrastructure/DoublePinAlphabet.cs b/Flow.Launcher.Infrastructure/DoublePinAlphabet.cs
index a1eb788d7..945f47a56 100644
--- a/Flow.Launcher.Infrastructure/DoublePinAlphabet.cs
+++ b/Flow.Launcher.Infrastructure/DoublePinAlphabet.cs
@@ -22,9 +22,9 @@ namespace Flow.Launcher.Infrastructure
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
}
- public bool CanBeTranslated(string stringToTranslate)
+ public bool ShouldTranslate(string stringToTranslate)
{
- return WordsHelper.HasChinese(stringToTranslate);
+ return stringToTranslate.Length % 2 == 0 && !WordsHelper.HasChinese(stringToTranslate);
}
public (string translation, TranslationMapping map) Translate(string content)
diff --git a/Flow.Launcher.Infrastructure/PinyinAlphabet.cs b/Flow.Launcher.Infrastructure/PinyinAlphabet.cs
index 7d7235968..961af1d32 100644
--- a/Flow.Launcher.Infrastructure/PinyinAlphabet.cs
+++ b/Flow.Launcher.Infrastructure/PinyinAlphabet.cs
@@ -119,7 +119,7 @@ namespace Flow.Launcher.Infrastructure
///
/// String to translate.
///
- public bool CanBeTranslated(string stringToTranslate);
+ public bool ShouldTranslate(string stringToTranslate);
}
public class PinyinAlphabet : IAlphabet
@@ -134,7 +134,7 @@ namespace Flow.Launcher.Infrastructure
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
}
- public bool CanBeTranslated(string stringToTranslate)
+ public bool ShouldTranslate(string stringToTranslate)
{
return WordsHelper.HasChinese(stringToTranslate);
}
diff --git a/Flow.Launcher.Infrastructure/StringMatcher.cs b/Flow.Launcher.Infrastructure/StringMatcher.cs
index bd5dbdda9..4929e4cd2 100644
--- a/Flow.Launcher.Infrastructure/StringMatcher.cs
+++ b/Flow.Launcher.Infrastructure/StringMatcher.cs
@@ -61,7 +61,7 @@ namespace Flow.Launcher.Infrastructure
query = query.Trim();
TranslationMapping translationMapping = null;
- if (_alphabet is not null && !_alphabet.CanBeTranslated(query))
+ if (_alphabet is not null && _alphabet.ShouldTranslate(query))
{
// We assume that if a query can be translated (containing characters of a language, like Chinese)
// it actually means user doesn't want it to be translated to English letters.