1
1
using System ;
2
2
using System . Collections . Concurrent ;
3
- using System . Collections . Generic ;
4
3
using System . Linq ;
5
4
using System . Text ;
6
5
using JetBrains . Annotations ;
7
- using Flow . Launcher . Infrastructure . Logger ;
8
- using Flow . Launcher . Infrastructure . Storage ;
9
6
using Flow . Launcher . Infrastructure . UserSettings ;
10
7
using ToolGood . Words . Pinyin ;
11
- using System . Threading . Tasks ;
12
8
13
9
namespace Flow . Launcher . Infrastructure
14
10
{
@@ -27,7 +23,6 @@ public void Initialize([NotNull] Settings settings)
27
23
_settings = settings ?? throw new ArgumentNullException ( nameof ( settings ) ) ;
28
24
}
29
25
30
-
31
26
public string Translate ( string content )
32
27
{
33
28
if ( _settings . ShouldUsePinyin )
@@ -36,10 +31,40 @@ public string Translate(string content)
36
31
{
37
32
if ( WordsHelper . HasChinese ( content ) )
38
33
{
39
- var result = WordsHelper . GetPinyin ( content , ";" ) ;
40
- result = GetFirstPinyinChar ( result ) + result . Replace ( ";" , "" ) ;
41
- _pinyinCache [ content ] = result ;
42
- return result ;
34
+ var resultList = WordsHelper . GetPinyinList ( content ) ;
35
+
36
+ StringBuilder resultBuilder = new StringBuilder ( ) ;
37
+
38
+ for ( int i = 0 ; i < resultList . Length ; i ++ )
39
+ {
40
+ if ( content [ i ] >= 0x3400 && content [ i ] <= 0x9FD5 )
41
+ resultBuilder . Append ( resultList [ i ] . First ( ) ) ;
42
+ }
43
+
44
+ resultBuilder . Append ( ' ' ) ;
45
+
46
+ bool pre = false ;
47
+
48
+ for ( int i = 0 ; i < resultList . Length ; i ++ )
49
+ {
50
+ if ( content [ i ] >= 0x3400 && content [ i ] <= 0x9FD5 )
51
+ {
52
+ resultBuilder . Append ( ' ' ) ;
53
+ resultBuilder . Append ( resultList [ i ] ) ;
54
+ pre = true ;
55
+ }
56
+ else
57
+ {
58
+ if ( pre )
59
+ {
60
+ pre = false ;
61
+ resultBuilder . Append ( ' ' ) ;
62
+ }
63
+ resultBuilder . Append ( resultList [ i ] ) ;
64
+ }
65
+ }
66
+
67
+ return _pinyinCache [ content ] = resultBuilder . ToString ( ) ;
43
68
}
44
69
else
45
70
{
@@ -56,10 +81,5 @@ public string Translate(string content)
56
81
return content ;
57
82
}
58
83
}
59
-
60
- private string GetFirstPinyinChar ( string content )
61
- {
62
- return string . Concat ( content . Split ( ';' ) . Select ( x => x . First ( ) ) ) ;
63
- }
64
84
}
65
85
}
0 commit comments