Skip to content

Commit fba42ff

Browse files
Fix transaltion logic
1 parent 16fd256 commit fba42ff

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

Flow.Launcher.Infrastructure/PinyinAlphabet.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public bool ShouldTranslate(string stringToTranslate)
3232
{
3333
if (_settings.ShouldUsePinyin)
3434
{
35-
if (!_pinyinCache.TryGetValue(content, out var value))
35+
if (true)
3636
{
3737
return BuildCacheFromContent(content);
3838
}
39-
else
40-
{
41-
return value;
42-
}
39+
//else
40+
//{
41+
// return value;
42+
//}
4343
}
4444
return (content, null);
4545
}
@@ -164,11 +164,10 @@ private static string ToDoublePin(string fullPinyin)
164164
// Check for initials that are two characters long (zh, ch, sh)
165165
if (fullPinyin.Length >= 2)
166166
{
167-
var firstTwo = fullPinyinSpan[..2];
168-
var firstTwoString = firstTwo.ToString();
169-
if (first.ContainsKey(firstTwoString))
167+
var firstTwoString = fullPinyinSpan[..2].ToString();
168+
if (first.TryGetValue(firstTwoString, out var firstTwoDoublePin))
170169
{
171-
doublePin.Append(firstTwoString);
170+
doublePin.Append(firstTwoDoublePin);
172171

173172
var lastTwo = fullPinyinSpan[2..];
174173
var lastTwoString = lastTwo.ToString();
@@ -178,27 +177,26 @@ private static string ToDoublePin(string fullPinyin)
178177
}
179178
else
180179
{
181-
doublePin.Append(lastTwo);
180+
doublePin.Append(lastTwo); // Todo: original pinyin, remove this line if not needed
182181
}
183182
}
184-
}
185-
// Handle single-character initials
186-
else
187-
{
188-
doublePin.Append(fullPinyinSpan[0]);
189-
190-
var lastOne = fullPinyinSpan[1..];
191-
var lastOneString = lastOne.ToString();
192-
if (second.TryGetValue(lastOneString, out var tmp))
193-
{
194-
doublePin.Append(tmp);
195-
}
196183
else
197184
{
198-
doublePin.Append(lastOne);
185+
// Handle single-character initials
186+
doublePin.Append(fullPinyinSpan[0]);
187+
188+
var lastOne = fullPinyinSpan[1..];
189+
var lastOneString = lastOne.ToString();
190+
if (second.TryGetValue(lastOneString, out var tmp))
191+
{
192+
doublePin.Append(tmp);
193+
}
194+
else
195+
{
196+
doublePin.Append(lastOne);
197+
}
199198
}
200199
}
201-
202200
return doublePin.ToString();
203201
}
204202

0 commit comments

Comments
 (0)