diff --git a/Flow.Launcher.Infrastructure/PinyinAlphabet.cs b/Flow.Launcher.Infrastructure/PinyinAlphabet.cs index 38f1ab879c1..80fd1282035 100644 --- a/Flow.Launcher.Infrastructure/PinyinAlphabet.cs +++ b/Flow.Launcher.Infrastructure/PinyinAlphabet.cs @@ -1,14 +1,10 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Linq; using System.Text; using JetBrains.Annotations; -using Flow.Launcher.Infrastructure.Logger; -using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Infrastructure.UserSettings; using ToolGood.Words.Pinyin; -using System.Threading.Tasks; namespace Flow.Launcher.Infrastructure { @@ -27,7 +23,6 @@ public void Initialize([NotNull] Settings settings) _settings = settings ?? throw new ArgumentNullException(nameof(settings)); } - public string Translate(string content) { if (_settings.ShouldUsePinyin) @@ -36,10 +31,40 @@ public string Translate(string content) { if (WordsHelper.HasChinese(content)) { - var result = WordsHelper.GetPinyin(content, ";"); - result = GetFirstPinyinChar(result) + result.Replace(";", ""); - _pinyinCache[content] = result; - return result; + var resultList = WordsHelper.GetPinyinList(content); + + StringBuilder resultBuilder = new StringBuilder(); + + for (int i = 0; i < resultList.Length; i++) + { + if (content[i] >= 0x3400 && content[i] <= 0x9FD5) + resultBuilder.Append(resultList[i].First()); + } + + resultBuilder.Append(' '); + + bool pre = false; + + for (int i = 0; i < resultList.Length; i++) + { + if (content[i] >= 0x3400 && content[i] <= 0x9FD5) + { + resultBuilder.Append(' '); + resultBuilder.Append(resultList[i]); + pre = true; + } + else + { + if (pre) + { + pre = false; + resultBuilder.Append(' '); + } + resultBuilder.Append(resultList[i]); + } + } + + return _pinyinCache[content] = resultBuilder.ToString(); } else { @@ -56,10 +81,5 @@ public string Translate(string content) return content; } } - - private string GetFirstPinyinChar(string content) - { - return string.Concat(content.Split(';').Select(x => x.First())); - } } } \ No newline at end of file