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
+10 -8
View File
@@ -50,7 +50,7 @@
ToolTip="Click to update"
Command="{Binding UpdateCommand}"
Visibility="{Binding IsUpdateAvailable, Converter={StaticResource ToVisibilityConverter}}"
Content="A new version is available"/>
Content="{DynamicResource mw_update_available}"/>
</StackPanel>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
@@ -59,6 +59,7 @@
Width="25" Height="25" Padding="5.5"
Style="{StaticResource IconButton}"
Tag="{StaticResource CogIcon}"
Command="{Binding OpenSettingsCommand}"
/>
<Button
Margin="9 0 15 0"
@@ -95,9 +96,9 @@
<Grid Margin="10" Cursor="Hand" Background="Transparent">
<TextBox Style="{StaticResource TitledTextBox}"
Uid="Folder path" IsReadOnly="True"
IsReadOnly="True"
Text="{Binding WeModInfo.RootDirectory, Mode=OneWay}"
VerticalAlignment="Center" Tag="Folder not found">
VerticalAlignment="Center">
</TextBox>
<Grid.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding SetFolderPathCommand}" />
@@ -169,14 +170,15 @@
<Button Style="{StaticResource ColoredButton}"
IsEnabled="{Binding IsPatchEnabled}"
FontWeight="Bold" FontSize="16" Width="200"
Command="{Binding ApplyPatchCommand}">Patch</Button>
Command="{Binding ApplyPatchCommand}"
Content="{DynamicResource mw_patch}"/>
</Grid>
<Button HorizontalAlignment="Right"
Command="{Binding RestoreBackupCommand }"
FontWeight="Bold" FontSize="16" Width="200"
Style="{StaticResource ColoredButton}"
Visibility="{Binding AlreadyPatched, Converter={StaticResource ToVisibilityConverter}}"
Content="Restore"/>
Content="{DynamicResource mw_restore}"/>
</Grid>
</StackPanel>
@@ -194,13 +196,13 @@
</Viewbox>
<Grid>
<TextBlock Margin="8 0 0 0" FontSize="10" Foreground="{DynamicResource AccentForeground}">
<Hyperlink Foreground="{DynamicResource AccentForeground}">Source code </Hyperlink>
<Hyperlink Foreground="{DynamicResource AccentForeground}"><Run Text="{DynamicResource mw_source_code}"/></Hyperlink>
<LineBreak/>
<Run>Made with ❤️ by k1tbyte</Run>
<Run Text="{DynamicResource mw_made_by}"/>
<LineBreak/>
<Run Foreground="{DynamicResource MutedForeground}">Put a star if you found this helpful ;)</Run>
<Run Foreground="{DynamicResource MutedForeground}" Text="{DynamicResource mw_star_hint}"/>
</TextBlock>
</Grid>
</StackPanel>
+9 -2
View File
@@ -72,6 +72,7 @@ namespace WeModPatcher.View.MainWindow
public RelayCommand ApplyPatchCommand { get; }
public RelayCommand RestoreBackupCommand { get; }
public RelayCommand UpdateCommand { get; }
public RelayCommand OpenSettingsCommand { get; }
private void OnFolderPathSelection(object obj)
{
@@ -162,7 +163,7 @@ namespace WeModPatcher.View.MainWindow
IsPatchEnabled = true;
}
});
}), "What are we gonna patch?");
}), Application.Current.FindResource("pv_popup_title") as string);
}
private void Log(string message, ELogType logType)
@@ -199,7 +200,12 @@ namespace WeModPatcher.View.MainWindow
Log("WeModPatcher updated successfully. Restarting...", ELogType.Success);
});
}), "Update available!");
}), Application.Current.FindResource("up_popup_title") as string);
}
private void OnOpenSettings(object param)
{
MainWindow.Instance.OpenPopup(new SettingsPopup(), Application.Current.FindResource("settings_title") as string);
}
public MainWindowVm(MainWindow view)
@@ -210,6 +216,7 @@ namespace WeModPatcher.View.MainWindow
ApplyPatchCommand = new RelayCommand(OnPatching);
RestoreBackupCommand = new RelayCommand(OnBackupRestoring);
UpdateCommand = new RelayCommand(OnUpdate);
OpenSettingsCommand = new RelayCommand(OnOpenSettings);
WeModInfo = Extensions.FindWeMod();
if (WeModInfo == null)
@@ -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>