mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 14:26:20 +00:00
change language in runtime without restart application
This commit is contained in:
parent
92baf9025a
commit
44df650e5f
5 changed files with 41 additions and 11 deletions
|
@ -5,8 +5,7 @@
|
|||
xmlns:conv="clr-namespace:v2rayN.Converters"
|
||||
xmlns:local="clr-namespace:v2rayN"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
ShutdownMode="OnExplicitShutdown"
|
||||
StartupUri="Views/MainWindow.xaml">
|
||||
ShutdownMode="OnExplicitShutdown">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using ProtosLib.Statistics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using v2rayN.Handler;
|
||||
using v2rayN.Mode;
|
||||
using v2rayN.Tool;
|
||||
using v2rayN.Views;
|
||||
|
||||
namespace v2rayN
|
||||
{
|
||||
|
@ -13,8 +15,8 @@ namespace v2rayN
|
|||
public partial class App : Application
|
||||
{
|
||||
public static EventWaitHandle ProgramStarted;
|
||||
private static Config _config;
|
||||
|
||||
private static v2rayN.Mode.Config _config;
|
||||
public static bool ignoreClosing { get; set; } = true;
|
||||
public App()
|
||||
{
|
||||
// Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());
|
||||
|
@ -53,6 +55,8 @@ namespace v2rayN
|
|||
Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage);
|
||||
|
||||
base.OnStartup(e);
|
||||
Current.MainWindow = new MainWindow();
|
||||
Current.MainWindow.Show();
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,5 +92,22 @@ namespace v2rayN
|
|||
{
|
||||
Utils.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception);
|
||||
}
|
||||
|
||||
public static void ChangeCulture(CultureInfo newCulture)
|
||||
{
|
||||
if (newCulture != null)
|
||||
{
|
||||
Thread.CurrentThread.CurrentCulture = newCulture;
|
||||
Thread.CurrentThread.CurrentUICulture = newCulture;
|
||||
_config.uiItem.currentLanguage = newCulture.Name;
|
||||
var oldWindow = Current.MainWindow;
|
||||
ignoreClosing = false;
|
||||
Current.MainWindow = new MainWindow();
|
||||
oldWindow.Close();
|
||||
ignoreClosing = true;
|
||||
Current.MainWindow.Show();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@
|
|||
};
|
||||
public static readonly List<string> allowInsecures = new() { "true", "false", "" };
|
||||
public static readonly List<string> domainStrategy4Freedoms = new() { "AsIs", "UseIP", "UseIPv4", "UseIPv6", "" };
|
||||
public static readonly List<string> Languages = new() { "zh-Hans", "en", "fa-Ir", "ru" };
|
||||
public static readonly List<string> Languages = new() { "zh-Hans", "en", "fa-IR", "ru" };
|
||||
public static readonly List<string> alpns = new() { "h2", "http/1.1", "h2,http/1.1", "" };
|
||||
public static readonly List<string> LogLevel = new() { "debug", "info", "warning", "error", "none" };
|
||||
public static readonly List<string> InboundTags = new() { "socks", "http", "socks2", "http2" };
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
Width="100"
|
||||
Margin="8"
|
||||
materialDesign:HintAssist.Hint="Language"
|
||||
SelectionChanged="cmbCurrentLanguage_SelectionChanged"
|
||||
Style="{StaticResource DefComboBox}" />
|
||||
|
||||
</Grid>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using ReactiveUI;
|
||||
using Splat;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
@ -224,10 +225,13 @@ namespace v2rayN.Views
|
|||
}
|
||||
|
||||
private void MainWindow_Closing(object? sender, CancelEventArgs e)
|
||||
{
|
||||
if (App.ignoreClosing)
|
||||
{
|
||||
e.Cancel = true;
|
||||
ViewModel?.ShowHideWindow(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void menuExit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
@ -605,8 +609,13 @@ namespace v2rayN.Views
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
private void cmbCurrentLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count != 0 && e.RemovedItems.Count != 0)
|
||||
App.ChangeCulture(new CultureInfo(e.AddedItems[0].ToString()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue