diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 384202b1..dc125cc8 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -489,17 +489,22 @@ public class Global "localhost" ]; + public static readonly List LanguageOptions = + [ + new("zh-Hans", "简体中文"), + new("zh-Hant", "繁體中文"), + new("en", "English"), + new("fa", "فارسی"), + new("fr", "Français"), + new("ru", "Русский"), + new("hu", "Magyar"), + new("id", "Bahasa Indonesia"), + new("az", "Azərbaycan dili") + ]; + public static readonly List Languages = [ - "zh-Hans", - "zh-Hant", - "en", - "fa", - "fr", - "ru", - "hu", - "id", - "az" + .. LanguageOptions.Select(t => t.Value) ]; public static readonly List Alpns = diff --git a/v2rayN/ServiceLib/Models/Dto/LanguageOption.cs b/v2rayN/ServiceLib/Models/Dto/LanguageOption.cs new file mode 100644 index 00000000..26ac6f31 --- /dev/null +++ b/v2rayN/ServiceLib/Models/Dto/LanguageOption.cs @@ -0,0 +1,3 @@ +namespace ServiceLib.Models.Dto; + +public sealed record LanguageOption(string Value, string Display); diff --git a/v2rayN/v2rayN.Desktop/Views/ThemeSettingView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ThemeSettingView.axaml.cs index d3103b11..498c6d56 100644 --- a/v2rayN/v2rayN.Desktop/Views/ThemeSettingView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ThemeSettingView.axaml.cs @@ -1,3 +1,4 @@ +using Avalonia.Data; using v2rayN.Desktop.ViewModels; namespace v2rayN.Desktop.Views; @@ -14,7 +15,9 @@ public partial class ThemeSettingView : ReactiveUserControl(); cmbCurrentFontSize.ItemsSource = Enumerable.Range(Global.MinFontSize, Global.MinFontSizeCount).ToList(); - cmbCurrentLanguage.ItemsSource = Global.Languages; + cmbCurrentLanguage.ItemsSource = Global.LanguageOptions; + cmbCurrentLanguage.DisplayMemberBinding = new Binding(nameof(LanguageOption.Display)); + cmbCurrentLanguage.SelectedValueBinding = new Binding(nameof(LanguageOption.Value)); this.WhenActivated(disposables => { diff --git a/v2rayN/v2rayN/Views/ThemeSettingView.xaml b/v2rayN/v2rayN/Views/ThemeSettingView.xaml index 570f06f8..2b0ab56f 100644 --- a/v2rayN/v2rayN/Views/ThemeSettingView.xaml +++ b/v2rayN/v2rayN/Views/ThemeSettingView.xaml @@ -81,6 +81,8 @@ Grid.Column="1" Width="120" Margin="{StaticResource Margin8}" + DisplayMemberPath="Display" + SelectedValuePath="Value" Style="{StaticResource DefComboBox}" /> diff --git a/v2rayN/v2rayN/Views/ThemeSettingView.xaml.cs b/v2rayN/v2rayN/Views/ThemeSettingView.xaml.cs index 000d3fa4..a7ed0b09 100644 --- a/v2rayN/v2rayN/Views/ThemeSettingView.xaml.cs +++ b/v2rayN/v2rayN/Views/ThemeSettingView.xaml.cs @@ -14,7 +14,7 @@ public partial class ThemeSettingView cmbCurrentTheme.ItemsSource = Utils.GetEnumNames().Take(3).ToList(); cmbCurrentFontSize.ItemsSource = Enumerable.Range(Global.MinFontSize, Global.MinFontSizeCount).ToList(); - cmbCurrentLanguage.ItemsSource = Global.Languages; + cmbCurrentLanguage.ItemsSource = Global.LanguageOptions; this.WhenActivated(disposables => { @@ -22,7 +22,7 @@ public partial class ThemeSettingView this.OneWayBind(ViewModel, vm => vm.Swatches, v => v.cmbSwatches.ItemsSource).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSwatch, v => v.cmbSwatches.SelectedItem).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.CurrentFontSize, v => v.cmbCurrentFontSize.Text).DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.CurrentLanguage, v => v.cmbCurrentLanguage.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.CurrentLanguage, v => v.cmbCurrentLanguage.SelectedValue).DisposeWith(disposables); }); } }