Slight cleanup to main window language handling

This commit is contained in:
Matt Nadareski
2025-10-16 20:33:43 -04:00
parent f63517bb52
commit 2325844bd4
2 changed files with 7 additions and 15 deletions

View File

@@ -118,7 +118,7 @@
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
Foreground="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"
Template="{DynamicResource CustomMenuItemTemplate}">
<MenuItem x:Name="EnglishMenuItem" Header="English" HorizontalAlignment="Left" Width="120" IsCheckable="True"
<MenuItem x:Name="EnglishMenuItem" Header="ENG" HorizontalAlignment="Left" Width="120" IsCheckable="True"
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
Foreground="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"
Template="{DynamicResource CustomMenuItemTemplate}" />

View File

@@ -575,8 +575,8 @@ namespace MPF.UI.Windows
/// </summary>
private void LanguageMenuItemClick(object sender, RoutedEventArgs e)
{
var clickedItem = (MenuItem)sender;
// Don't do anything if language is already checked and being unchecked
var clickedItem = (MenuItem)sender;
if (!clickedItem.IsChecked)
{
clickedItem.IsChecked = true;
@@ -594,20 +594,12 @@ namespace MPF.UI.Windows
// Change UI language to selected item
string lang = clickedItem.Header.ToString() ?? "";
var dictionary = new ResourceDictionary();
switch (lang)
dictionary.Source = lang switch
{
case "ENG":
// Change UI language to English
dictionary.Source = new Uri("../Resources/Strings.xaml", UriKind.Relative);
break;
case "한국어":
// Change UI language to Korean
dictionary.Source = new Uri("../Resources/Strings.ko.xaml", UriKind.Relative);
break;
default:
dictionary.Source = new Uri("../Resources/Strings.xaml", UriKind.Relative);
break;
}
"ENG" => new Uri("../Resources/Strings.xaml", UriKind.Relative),
"한국어" => new Uri("../Resources/Strings.ko.xaml", UriKind.Relative),
_ => new Uri("../Resources/Strings.xaml", UriKind.Relative),
};
Application.Current.Resources.MergedDictionaries.Add(dictionary);
// Update the labels that don't get updated automatically