-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,5 @@ public enum SettingNames | |
IsMigrating, | ||
LastSelectedGroup, | ||
ChatGroupPanelType, | ||
AppLanguage, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Desktop/RodelAgent.UI/Controls/Settings/LanguageSettingSection.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<local:SettingSectionBase | ||
x:Class="RodelAgent.UI.Controls.Settings.LanguageSettingSection" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:community="using:CommunityToolkit.WinUI.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:ext="using:RodelAgent.UI.Extensions" | ||
xmlns:ic="using:FluentIcons.WinUI" | ||
xmlns:local="using:RodelAgent.UI.Controls.Settings" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<community:SettingsCard Description="{ext:Locale Name=LanguageSettingDescription}" Header="{ext:Locale Name=LanguageSetting}"> | ||
<community:SettingsCard.HeaderIcon> | ||
<ic:SymbolIcon Symbol="LocalLanguage" /> | ||
</community:SettingsCard.HeaderIcon> | ||
|
||
<ComboBox | ||
x:Name="LanguageComboBox" | ||
MinWidth="120" | ||
AutomationProperties.Name="{ext:Locale Name=LanguageSetting}" | ||
SelectionChanged="OnLanguageChangedAsync" | ||
SelectionChangedTrigger="Committed"> | ||
<ComboBoxItem Content="{ext:Locale Name=SystemDefault}" Tag="default" /> | ||
<ComboBoxItem Content="简体中文" Tag="zh-Hans-CN" /> | ||
<ComboBoxItem Content="English" Tag="en-US" /> | ||
</ComboBox> | ||
</community:SettingsCard> | ||
</local:SettingSectionBase> |
83 changes: 83 additions & 0 deletions
83
src/Desktop/RodelAgent.UI/Controls/Settings/LanguageSettingSection.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) Rodel. All rights reserved. | ||
|
||
using System.ComponentModel; | ||
using Microsoft.Windows.AppLifecycle; | ||
using RodelAgent.UI.Models.Constants; | ||
using RodelAgent.UI.Toolkits; | ||
|
||
namespace RodelAgent.UI.Controls.Settings; | ||
|
||
/// <summary> | ||
/// 应用语言设置. | ||
/// </summary> | ||
public sealed partial class LanguageSettingSection : SettingSectionBase | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LanguageSettingSection"/> class. | ||
/// </summary> | ||
public LanguageSettingSection() | ||
{ | ||
InitializeComponent(); | ||
Loaded += OnLoaded; | ||
Unloaded += OnUnloaded; | ||
} | ||
|
||
private void OnUnloaded(object sender, RoutedEventArgs e) | ||
=> ViewModel.PropertyChanged -= OnViewModelPropertyChanged; | ||
|
||
private void OnLoaded(object sender, RoutedEventArgs e) | ||
{ | ||
ViewModel.PropertyChanged += OnViewModelPropertyChanged; | ||
CheckLanguage(); | ||
} | ||
|
||
private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName == nameof(ViewModel.AppLanguage)) | ||
{ | ||
CheckLanguage(); | ||
} | ||
} | ||
|
||
private void CheckLanguage() | ||
{ | ||
if (string.IsNullOrEmpty(ViewModel.AppLanguage)) | ||
{ | ||
return; | ||
} | ||
|
||
var selectIndex = ViewModel.AppLanguage switch | ||
{ | ||
"zh-Hans-CN" => 1, | ||
"en-US" => 2, | ||
_ => 0, | ||
}; | ||
|
||
if (selectIndex == LanguageComboBox.SelectedIndex) | ||
{ | ||
return; | ||
} | ||
|
||
LanguageComboBox.SelectedIndex = selectIndex; | ||
} | ||
|
||
private async void OnLanguageChangedAsync(object sender, SelectionChangedEventArgs e) | ||
{ | ||
var item = e.AddedItems.First() as ComboBoxItem; | ||
var lanCode = item?.Tag as string; | ||
if (string.IsNullOrEmpty(lanCode) | ||
|| (!string.IsNullOrEmpty(ViewModel.AppLanguage) && ViewModel.AppLanguage == lanCode)) | ||
{ | ||
return; | ||
} | ||
|
||
ViewModel.AppLanguage = lanCode; | ||
var dialog = new TipDialog(ResourceToolkit.GetLocalizedString(StringNames.ChangeLanguageTip)); | ||
var result = await dialog.ShowAsync(); | ||
if (result == ContentDialogResult.Primary) | ||
{ | ||
AppInstance.GetCurrent().UnregisterKey(); | ||
_ = AppInstance.Restart(default); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters