11using System . Diagnostics ;
2+ using System . Globalization ;
23using SingleInstanceCore ;
34using System . Text . Json ;
45using Windows . ApplicationModel ;
@@ -174,4 +175,31 @@ public void OnInstanceInvoked(string[] args)
174175 {
175176 _launcher . ShowWindow ( ) ;
176177 }
178+
179+ public static void SetLocale ( string locale )
180+ {
181+ if ( locale != "zh" && locale != "zh-TW" && locale != "en" )
182+ {
183+ throw new ArgumentException ( "Invalid locale. Must be 'zh', 'zh-TW', or 'en'" ) ;
184+ }
185+
186+ StaticSettings . CurrentLocale = locale ;
187+ StaticSettings . Config . Locale = locale ;
188+
189+ // 设置 Locale 资源管理器的 Culture(这会影响所有线程)
190+ var culture = locale switch
191+ {
192+ "zh" => new CultureInfo ( "zh-CN" ) ,
193+ "zh-TW" => new CultureInfo ( "zh-TW" ) ,
194+ _ => new CultureInfo ( "en-US" ) ,
195+ } ;
196+ Locale . Culture = culture ;
197+ CultureInfo . CurrentCulture = culture ;
198+ CultureInfo . CurrentUICulture = culture ;
199+
200+ // 保存配置文件
201+ var cfgFilePath = Path . Combine ( StaticSettings . appData , "config.json" ) ;
202+ var json = JsonSerializer . Serialize ( StaticSettings . Config , new JsonSerializerOptions { WriteIndented = true } ) ;
203+ System . IO . File . WriteAllText ( cfgFilePath , json ) ;
204+ }
177205}
0 commit comments