feat: implement localization support and add language settings

This commit is contained in:
kitbyte
2025-12-14 18:57:30 +02:00
parent a943b91f5f
commit d02b84a414
26 changed files with 964 additions and 19 deletions
@@ -20,14 +20,14 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" VerticalAlignment="Center" Text="Activate WeMod Pro" />
<TextBlock Grid.Row="0" VerticalAlignment="Center" Text="{DynamicResource pv_activate_pro}" />
<CheckBox Grid.Row="0" x:Name="ActivateProBox" HorizontalAlignment="Right" VerticalAlignment="Center"
IsChecked="True" />
<TextBlock Grid.Row="1" VerticalAlignment="Center" Text="DevTools on F12" />
<TextBlock Grid.Row="1" VerticalAlignment="Center" Text="{DynamicResource pv_devtools}" />
<CheckBox Grid.Row="1" x:Name="DevToolsHotkeyBox" HorizontalAlignment="Right" VerticalAlignment="Center" />
<TextBlock Grid.Row="2" VerticalAlignment="Center" Text="Disable updates" />
<TextBlock Grid.Row="2" VerticalAlignment="Center" Text="{DynamicResource pv_disable_updates}" />
<CheckBox Grid.Row="2" x:Name="DisableUpdateBox" HorizontalAlignment="Right" VerticalAlignment="Center" />
<!--<TextBlock
@@ -39,7 +39,7 @@
<CheckBox Grid.Row="3" x:Name="AutoUpdates" HorizontalAlignment="Right" VerticalAlignment="Center"
IsChecked="True" />-->
<Button Grid.Row="3" Padding="0 5 0 5" Margin="0 15 0 0" Content="Start"
<Button Grid.Row="3" Padding="0 5 0 5" Margin="0 15 0 0" Content="{DynamicResource pv_start}"
Click="OnPatchButtonClick" />
</Grid>
</Grid>
@@ -0,0 +1,41 @@
<UserControl x:Class="WeModPatcher.View.Popups.SettingsPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="Auto" d:DesignWidth="Auto"
Background="{DynamicResource Background}"
Foreground="{DynamicResource MutedForeground}"
FontWeight="Medium"
FontSize="13">
<Grid MinWidth="250">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="0 0 0 15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" VerticalAlignment="Center"
Text="{DynamicResource settings_language}" />
<ComboBox Grid.Column="1" x:Name="LanguageComboBox"
Width="130"
SelectionChanged="OnLanguageSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<Button Grid.Row="1" Padding="0 5 0 5" Margin="0 5 0 0"
Content="{DynamicResource settings_save}"
Click="OnSaveClick" />
</Grid>
</UserControl>
@@ -0,0 +1,68 @@
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using WeModPatcher.Core;
using WeModPatcher.Core.Services;
using WeModPatcher.View.MainWindow;
namespace WeModPatcher.View.Popups
{
public partial class SettingsPopup : UserControl
{
private CultureInfo _selectedLanguage;
public SettingsPopup()
{
InitializeComponent();
LoadLanguages();
}
private void LoadLanguages()
{
var items = LocalizationManager.SupportedLanguages
.Select(c => new LanguageItem
{
Culture = c,
DisplayName = LocalizationManager.GetLanguageDisplayName(c)
})
.ToList();
LanguageComboBox.ItemsSource = items;
var currentItem = items.FirstOrDefault(i => i.Culture.Name == LocalizationManager.CurrentLanguage?.Name);
if (currentItem != null)
{
LanguageComboBox.SelectedItem = currentItem;
}
_selectedLanguage = LocalizationManager.CurrentLanguage;
}
private void OnLanguageSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LanguageComboBox.SelectedItem is LanguageItem item)
{
_selectedLanguage = item.Culture;
}
}
private void OnSaveClick(object sender, RoutedEventArgs e)
{
if (_selectedLanguage != null &&
(LocalizationManager.CurrentLanguage == null ||
_selectedLanguage.Name != LocalizationManager.CurrentLanguage.Name))
{
LocalizationManager.CurrentLanguage = _selectedLanguage;
}
MainWindow.MainWindow.Instance.ClosePopup();
}
private class LanguageItem
{
public CultureInfo Culture { get; set; }
public string DisplayName { get; set; }
}
}
}
+2 -2
View File
@@ -12,9 +12,9 @@
FontSize="13">
<StackPanel>
<TextBlock Foreground="Red" MaxWidth="320" TextAlignment="Center" Text="Before updating, it is strongly recommended to roll back patches if they have been applied" TextWrapping="Wrap" />
<TextBlock Foreground="Red" MaxWidth="320" TextAlignment="Center" Text="{DynamicResource up_warning}" TextWrapping="Wrap" />
<Button Padding="0 5 0 5" Margin="0 15 0 0" Content="Update now"
<Button Padding="0 5 0 5" Margin="0 15 0 0" Content="{DynamicResource up_update_now}"
Click="OnUpdateClick" />
</StackPanel>
</UserControl>