33using CommunityToolkit . Mvvm . Input ;
44using PostCodeSerialMonitor . Models ;
55using PostCodeSerialMonitor . Services ;
6+ using PostCodeSerialMonitor . Utils ;
67using System . Threading . Tasks ;
78using Avalonia . Controls ;
89using System ;
10+ using System . Collections . Generic ;
11+ using System . Globalization ;
12+ using MsBox . Avalonia ;
13+ using MsBox . Avalonia . Enums ;
914
1015namespace PostCodeSerialMonitor . ViewModels ;
1116
@@ -32,11 +37,21 @@ public partial class ConfigurationDialogViewModel : ViewModelBase
3237 [ ObservableProperty ]
3338 private string fwUpdateUrl ;
3439
35- public ObservableCollection < string > Languages { get ; } = new ( ) ;
40+ [ ObservableProperty ]
41+ private ObservableCollection < string > languages ;
3642
3743 [ ObservableProperty ]
3844 private string selectedLanguage ;
3945
46+ public static ObservableCollection < string > GetAvailableLanguages ( )
47+ {
48+ var languages = new ObservableCollection < string > ( ) ;
49+ var cultures = LocalizationUtils . GetAvailableCultures ( ) ;
50+ foreach ( CultureInfo culture in cultures )
51+ languages . Add ( culture . Name ) ;
52+ return languages ;
53+ }
54+
4055 public ConfigurationDialogViewModel ( ConfigurationService configurationService )
4156 {
4257 _configurationService = configurationService ;
@@ -52,13 +67,14 @@ public ConfigurationDialogViewModel(ConfigurationService configurationService)
5267 SelectedLanguage = _originalConfiguration . Language ;
5368
5469 //Add available languages
55- Languages . Add ( "en-US" ) ;
56- Languages . Add ( "pt-BR" ) ;
70+ Languages = GetAvailableLanguages ( ) ;
5771 }
5872
5973 [ RelayCommand ]
6074 private async Task SaveAsync ( Window window )
6175 {
76+ bool languageChanged = _originalConfiguration . Language != SelectedLanguage ;
77+
6278 await _configurationService . UpdateConfigurationAsync ( config =>
6379 {
6480 config . CheckForAppUpdates = CheckForAppUpdates ;
@@ -71,6 +87,13 @@ await _configurationService.UpdateConfigurationAsync(config =>
7187 } ) ;
7288
7389 window . Close ( ) ;
90+
91+ if ( languageChanged ) {
92+ await MessageBoxManager
93+ . GetMessageBoxStandard ( Assets . Resources . RestartRequired , string . Format ( Assets . Resources . LanguageChangedPleaseRestart ) ,
94+ ButtonEnum . Ok )
95+ . ShowAsync ( ) ;
96+ }
7497 }
7598
7699 [ RelayCommand ]
0 commit comments