Only translate when string is double pinyin

This commit is contained in:
VictoriousRaptor 2024-05-25 15:02:37 +08:00
parent 99ff3b2ec5
commit 46d49d8fdf
3 changed files with 5 additions and 5 deletions

View file

@ -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)

View file

@ -119,7 +119,7 @@ namespace Flow.Launcher.Infrastructure
/// </summary>
/// <param name="stringToTranslate">String to translate.</param>
/// <returns></returns>
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);
}

View file

@ -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.