1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Globalization ;
3
4
using System . IO ;
4
5
using System . Linq ;
5
6
using System . Reflection ;
7
+ using System . Threading ;
8
+ using System . Threading . Tasks ;
6
9
using System . Windows ;
10
+ using CommunityToolkit . Mvvm . DependencyInjection ;
7
11
using Flow . Launcher . Core . Plugin ;
8
12
using Flow . Launcher . Infrastructure ;
9
13
using Flow . Launcher . Infrastructure . UserSettings ;
10
14
using Flow . Launcher . Plugin ;
11
- using System . Globalization ;
12
- using System . Threading . Tasks ;
13
- using CommunityToolkit . Mvvm . DependencyInjection ;
14
15
15
16
namespace Flow . Launcher . Core . Resource
16
17
{
@@ -29,13 +30,12 @@ public class Internationalization
29
30
private readonly Settings _settings ;
30
31
private readonly List < string > _languageDirectories = new ( ) ;
31
32
private readonly List < ResourceDictionary > _oldResources = new ( ) ;
32
- private readonly string SystemLanguageCode ;
33
+ private static string SystemLanguageCode ;
33
34
34
35
public Internationalization ( Settings settings )
35
36
{
36
37
_settings = settings ;
37
38
AddFlowLauncherLanguageDirectory ( ) ;
38
- SystemLanguageCode = GetSystemLanguageCodeAtStartup ( ) ;
39
39
}
40
40
41
41
private void AddFlowLauncherLanguageDirectory ( )
@@ -44,7 +44,7 @@ private void AddFlowLauncherLanguageDirectory()
44
44
_languageDirectories . Add ( directory ) ;
45
45
}
46
46
47
- private static string GetSystemLanguageCodeAtStartup ( )
47
+ public static void InitSystemLanguageCode ( )
48
48
{
49
49
var availableLanguages = AvailableLanguages . GetAvailableLanguages ( ) ;
50
50
@@ -65,11 +65,11 @@ private static string GetSystemLanguageCodeAtStartup()
65
65
string . Equals ( languageCode , threeLetterCode , StringComparison . OrdinalIgnoreCase ) ||
66
66
string . Equals ( languageCode , fullName , StringComparison . OrdinalIgnoreCase ) )
67
67
{
68
- return languageCode ;
68
+ SystemLanguageCode = languageCode ;
69
69
}
70
70
}
71
71
72
- return DefaultLanguageCode ;
72
+ SystemLanguageCode = DefaultLanguageCode ;
73
73
}
74
74
75
75
private void AddPluginLanguageDirectories ( )
@@ -173,15 +173,33 @@ private async Task ChangeLanguageAsync(Language language)
173
173
LoadLanguage ( language ) ;
174
174
}
175
175
176
- // Culture of main thread
177
- // Use CreateSpecificCulture to preserve possible user-override settings in Windows, if Flow's language culture is the same as Windows's
178
- CultureInfo . CurrentCulture = CultureInfo . CreateSpecificCulture ( language . LanguageCode ) ;
179
- CultureInfo . CurrentUICulture = CultureInfo . CurrentCulture ;
176
+ // Change culture info
177
+ ChangeCultureInfo ( language . LanguageCode ) ;
180
178
181
179
// Raise event for plugins after culture is set
182
180
await Task . Run ( UpdatePluginMetadataTranslations ) ;
183
181
}
184
182
183
+ public static void ChangeCultureInfo ( string languageCode )
184
+ {
185
+ // Culture of main thread
186
+ // Use CreateSpecificCulture to preserve possible user-override settings in Windows, if Flow's language culture is the same as Windows's
187
+ CultureInfo currentCulture ;
188
+ try
189
+ {
190
+ currentCulture = CultureInfo . CreateSpecificCulture ( languageCode ) ;
191
+ }
192
+ catch ( CultureNotFoundException )
193
+ {
194
+ currentCulture = CultureInfo . CreateSpecificCulture ( SystemLanguageCode ) ;
195
+ }
196
+ CultureInfo . CurrentCulture = currentCulture ;
197
+ CultureInfo . CurrentUICulture = currentCulture ;
198
+ var thread = Thread . CurrentThread ;
199
+ thread . CurrentCulture = currentCulture ;
200
+ thread . CurrentUICulture = currentCulture ;
201
+ }
202
+
185
203
public bool PromptShouldUsePinyin ( string languageCodeToSet )
186
204
{
187
205
var languageToSet = GetLanguageByLanguageCode ( languageCodeToSet ) ;
0 commit comments