Skip to content

Commit 0c01c95

Browse files
Only translate when string is double pinyin
1 parent 22f6ad7 commit 0c01c95

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Flow.Launcher.Infrastructure/DoublePinAlphabet.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public void Initialize([NotNull] Settings settings)
2222
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
2323
}
2424

25-
public bool CanBeTranslated(string stringToTranslate)
25+
public bool ShouldTranslate(string stringToTranslate)
2626
{
27-
return WordsHelper.HasChinese(stringToTranslate);
27+
return stringToTranslate.Length % 2 == 0 && !WordsHelper.HasChinese(stringToTranslate);
2828
}
2929

3030
public (string translation, TranslationMapping map) Translate(string content)

Flow.Launcher.Infrastructure/PinyinAlphabet.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public interface IAlphabet
119119
/// </summary>
120120
/// <param name="stringToTranslate">String to translate.</param>
121121
/// <returns></returns>
122-
public bool CanBeTranslated(string stringToTranslate);
122+
public bool ShouldTranslate(string stringToTranslate);
123123
}
124124

125125
public class PinyinAlphabet : IAlphabet
@@ -134,7 +134,7 @@ public void Initialize([NotNull] Settings settings)
134134
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
135135
}
136136

137-
public bool CanBeTranslated(string stringToTranslate)
137+
public bool ShouldTranslate(string stringToTranslate)
138138
{
139139
return WordsHelper.HasChinese(stringToTranslate);
140140
}

Flow.Launcher.Infrastructure/StringMatcher.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
6161

6262
query = query.Trim();
6363
TranslationMapping translationMapping = null;
64-
if (_alphabet is not null && !_alphabet.CanBeTranslated(query))
64+
if (_alphabet is not null && _alphabet.ShouldTranslate(query))
6565
{
6666
// We assume that if a query can be translated (containing characters of a language, like Chinese)
6767
// it actually means user doesn't want it to be translated to English letters.

0 commit comments

Comments
 (0)