11using  System ; 
22using  System . Collections . Generic ; 
3+ using  System . Globalization ; 
34using  System . IO ; 
45using  System . Linq ; 
56using  System . Reflection ; 
7+ using  System . Threading ; 
8+ using  System . Threading . Tasks ; 
69using  System . Windows ; 
10+ using  CommunityToolkit . Mvvm . DependencyInjection ; 
711using  Flow . Launcher . Core . Plugin ; 
812using  Flow . Launcher . Infrastructure ; 
913using  Flow . Launcher . Infrastructure . UserSettings ; 
1014using  Flow . Launcher . Plugin ; 
11- using  System . Globalization ; 
12- using  System . Threading . Tasks ; 
13- using  CommunityToolkit . Mvvm . DependencyInjection ; 
1415
1516namespace  Flow . Launcher . Core . Resource 
1617{ 
@@ -29,13 +30,12 @@ public class Internationalization
2930        private  readonly  Settings  _settings ; 
3031        private  readonly  List < string >  _languageDirectories  =  new ( ) ; 
3132        private  readonly  List < ResourceDictionary >  _oldResources  =  new ( ) ; 
32-         private  readonly  string  SystemLanguageCode ; 
33+         private  static   string  SystemLanguageCode ; 
3334
3435        public  Internationalization ( Settings  settings ) 
3536        { 
3637            _settings  =  settings ; 
3738            AddFlowLauncherLanguageDirectory ( ) ; 
38-             SystemLanguageCode  =  GetSystemLanguageCodeAtStartup ( ) ; 
3939        } 
4040
4141        private  void  AddFlowLauncherLanguageDirectory ( ) 
@@ -44,7 +44,7 @@ private void AddFlowLauncherLanguageDirectory()
4444            _languageDirectories . Add ( directory ) ; 
4545        } 
4646
47-         private  static   string   GetSystemLanguageCodeAtStartup ( ) 
47+         public  static   void   InitSystemLanguageCode ( ) 
4848        { 
4949            var  availableLanguages  =  AvailableLanguages . GetAvailableLanguages ( ) ; 
5050
@@ -65,11 +65,11 @@ private static string GetSystemLanguageCodeAtStartup()
6565                    string . Equals ( languageCode ,  threeLetterCode ,  StringComparison . OrdinalIgnoreCase )  || 
6666                    string . Equals ( languageCode ,  fullName ,  StringComparison . OrdinalIgnoreCase ) ) 
6767                { 
68-                     return  languageCode ; 
68+                     SystemLanguageCode   =  languageCode ; 
6969                } 
7070            } 
7171
72-             return  DefaultLanguageCode ; 
72+             SystemLanguageCode   =  DefaultLanguageCode ; 
7373        } 
7474
7575        private  void  AddPluginLanguageDirectories ( ) 
@@ -173,15 +173,33 @@ private async Task ChangeLanguageAsync(Language language)
173173                LoadLanguage ( language ) ; 
174174            } 
175175
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 ) ; 
180178
181179            // Raise event for plugins after culture is set 
182180            await  Task . Run ( UpdatePluginMetadataTranslations ) ; 
183181        } 
184182
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+ 
185203        public  bool  PromptShouldUsePinyin ( string  languageCodeToSet ) 
186204        { 
187205            var  languageToSet  =  GetLanguageByLanguageCode ( languageCodeToSet ) ; 
0 commit comments