Skip to content

Commit 4b2ffe5

Browse files
authored
fix: i18n for Simulate module - all labels use LocalizationService (#51)
- XAML: all hardcoded English replaced with {x:Static} bindings - ViewModel: PickFolder/PickFile strings use _loc - Status messages: Sim.Starting, Sim.Completed, Sim.Failed, Sim.Report - Added 4 new i18n keys to both zh-CN and en-US - Code-behind: ComboBox SelectionChanged updates Config.Platform/AppType
1 parent 04f0959 commit 4b2ffe5

4 files changed

Lines changed: 77 additions & 29 deletions

File tree

src/Services/LocalizationService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public string this[string key]
136136
["Sim.SelectOutput"] = "选择模拟输出目录",
137137
["Sim.ValidateDirs"] = "请填写所有必填项",
138138
["Sim.DotnetCheck"] = "需要 .NET 10.0 SDK,请先安装",
139+
["Sim.Starting"] = "正在启动模拟...",
140+
["Sim.Completed"] = "模拟完成 ({0:F1}s)",
141+
["Sim.Failed"] = "模拟失败: {0}",
142+
["Sim.Report"] = "报告: {0}",
139143
},
140144
["en-US"] = new()
141145
{
@@ -229,6 +233,10 @@ public string this[string key]
229233
["Sim.SelectOutput"] = "Select simulation output directory",
230234
["Sim.ValidateDirs"] = "Please fill in all required fields",
231235
["Sim.DotnetCheck"] = ".NET 10.0 SDK is required. Please install it first.",
236+
["Sim.Starting"] = "Starting simulation...",
237+
["Sim.Completed"] = "Simulation completed ({0:F1}s)",
238+
["Sim.Failed"] = "Simulation failed: {0}",
239+
["Sim.Report"] = "Report: {0}",
232240
}
233241
};
234242

src/ViewModels/SimulateViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public int AppTypeIndex
7979
return r.Count > 0 ? r[0].Path.LocalPath : null;
8080
}
8181

82-
[RelayCommand] async Task SelectAppDir() { var p = await PickFolder("选择旧版本应用目录"); if (p != null) Config.AppDirectory = p; }
83-
[RelayCommand] async Task SelectPatch() { var p = await PickFile("选择补丁包"); if (p != null) Config.PatchFilePath = p; }
84-
[RelayCommand] async Task SelectOutputDir() { var p = await PickFolder("选择模拟输出目录"); if (p != null) Config.OutputDirectory = p; }
82+
[RelayCommand] async Task SelectAppDir() { var p = await PickFolder(_loc["Sim.SelectAppDir"]); if (p != null) Config.AppDirectory = p; }
83+
[RelayCommand] async Task SelectPatch() { var p = await PickFile(_loc["Sim.SelectPatch"]); if (p != null) Config.PatchFilePath = p; }
84+
[RelayCommand] async Task SelectOutputDir() { var p = await PickFolder(_loc["Sim.SelectOutput"]); if (p != null) Config.OutputDirectory = p; }
8585

8686
[RelayCommand]
8787
async Task StartSimulation()
@@ -92,7 +92,7 @@ async Task StartSimulation()
9292

9393
IsRunning = true;
9494
Log.Clear();
95-
Status = "Starting simulation...";
95+
Status = _loc["Sim.Starting"];
9696

9797
try
9898
{
@@ -101,17 +101,17 @@ async Task StartSimulation()
101101

102102
if (result.Success)
103103
{
104-
Status = $"Simulation completed ({result.Elapsed.TotalSeconds:F1}s)";
104+
Status = _loc.T("Sim.Completed", result.Elapsed.TotalSeconds);
105105
L($"Result: {(result.Success ? "PASS" : "FAIL")}");
106106
foreach (var note in result.Notes)
107107
L($" Note: {note}");
108108

109109
var reportPath = await _report.GenerateAsync(Config, result, Config.OutputDirectory);
110-
L($"Report: {reportPath}");
110+
L(_loc.T("Sim.Report", reportPath));
111111
}
112112
else
113113
{
114-
Status = $"Simulation failed: {result.ErrorMessage}";
114+
Status = _loc.T("Sim.Failed", result.ErrorMessage);
115115
}
116116
}
117117
catch (Exception ex)

src/Views/SimulateView.axaml

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,64 @@
33
xmlns:vm="using:GeneralUpdate.Tools.ViewModels"
44
xmlns:svc="using:GeneralUpdate.Tools.Services"
55
x:Class="GeneralUpdate.Tools.Views.SimulateView"
6+
x:Name="SimRoot"
67
x:DataType="vm:SimulateViewModel">
78
<ScrollViewer>
89
<StackPanel Margin="28,24" Spacing="14">
9-
<TextBlock Text="🧪 Simulate Update" FontSize="20" FontWeight="Bold"/>
10+
<TextBlock Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Title]}"
11+
FontSize="20" FontWeight="Bold"/>
1012

1113
<!-- Test target -->
1214
<Border Padding="16" CornerRadius="8" Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}">
1315
<StackPanel Spacing="10">
14-
<TextBlock Text="Test Target" FontSize="14" FontWeight="SemiBold"/>
16+
<TextBlock Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.TestTarget]}"
17+
FontSize="14" FontWeight="SemiBold"/>
1518
<Grid ColumnDefinitions="Auto,*,Auto">
16-
<TextBlock Grid.Column="0" Text="Old App Dir" VerticalAlignment="Center" Width="110"/>
19+
<TextBlock Grid.Column="0" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.OldAppDir]}"
20+
VerticalAlignment="Center" Width="100"/>
1721
<TextBox Grid.Column="1" Text="{Binding Config.AppDirectory}" IsReadOnly="True" Margin="8,0"/>
18-
<Button Grid.Column="2" Content="📁 Select" Command="{Binding SelectAppDirCommand}" MinWidth="80"/>
22+
<Button Grid.Column="2" Content="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Select]}"
23+
Command="{Binding SelectAppDirCommand}" MinWidth="80"/>
1924
</Grid>
2025
<Grid ColumnDefinitions="Auto,*,Auto">
21-
<TextBlock Grid.Column="0" Text="Patch Package" VerticalAlignment="Center" Width="110"/>
26+
<TextBlock Grid.Column="0" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.PatchFile]}"
27+
VerticalAlignment="Center" Width="100"/>
2228
<TextBox Grid.Column="1" Text="{Binding Config.PatchFilePath}" IsReadOnly="True" Margin="8,0"/>
23-
<Button Grid.Column="2" Content="📁 Select" Command="{Binding SelectPatchCommand}" MinWidth="80"/>
29+
<Button Grid.Column="2" Content="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Select]}"
30+
Command="{Binding SelectPatchCommand}" MinWidth="80"/>
2431
</Grid>
2532
</StackPanel>
2633
</Border>
2734

2835
<!-- Config -->
2936
<Border Padding="16" CornerRadius="8" Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}">
3037
<StackPanel Spacing="10">
31-
<TextBlock Text="Update Config" FontSize="14" FontWeight="SemiBold"/>
38+
<TextBlock Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.UpdateConfig]}"
39+
FontSize="14" FontWeight="SemiBold"/>
3240
<Grid ColumnDefinitions="Auto,*,Auto,*">
33-
<TextBlock Grid.Column="0" Text="Current Ver" VerticalAlignment="Center"/>
41+
<TextBlock Grid.Column="0" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.CurrentVer]}"
42+
VerticalAlignment="Center"/>
3443
<TextBox Grid.Column="1" Text="{Binding Config.CurrentVersion}" Margin="8,0,16,0"/>
35-
<TextBlock Grid.Column="2" Text="Target Ver" VerticalAlignment="Center"/>
44+
<TextBlock Grid.Column="2" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.TargetVer]}"
45+
VerticalAlignment="Center"/>
3646
<TextBox Grid.Column="3" Text="{Binding Config.TargetVersion}" Margin="8,0"/>
3747
</Grid>
3848
<Grid ColumnDefinitions="Auto,*,Auto,*">
39-
<TextBlock Grid.Column="0" Text="Platform" VerticalAlignment="Center"/>
40-
<ComboBox Grid.Column="1" ItemsSource="{Binding Platforms}"
41-
SelectedIndex="{Binding PlatformIndex}" Margin="8,0,16,0"/>
42-
<TextBlock Grid.Column="2" Text="AppType" VerticalAlignment="Center"/>
43-
<ComboBox Grid.Column="3" ItemsSource="{Binding AppTypes}"
44-
SelectedIndex="{Binding AppTypeIndex}" Margin="8,0"/>
49+
<TextBlock Grid.Column="0" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Platform]}"
50+
VerticalAlignment="Center"/>
51+
<ComboBox x:Name="PlatformCombo" Grid.Column="1" ItemsSource="{Binding Platforms}"
52+
SelectedIndex="0" Margin="8,0,16,0"/>
53+
<TextBlock Grid.Column="2" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.AppType]}"
54+
VerticalAlignment="Center"/>
55+
<ComboBox x:Name="AppTypeCombo" Grid.Column="3" ItemsSource="{Binding AppTypes}"
56+
SelectedIndex="0" Margin="8,0"/>
4557
</Grid>
4658
<Grid ColumnDefinitions="Auto,*,Auto,*">
47-
<TextBlock Grid.Column="0" Text="AppSecret" VerticalAlignment="Center"/>
59+
<TextBlock Grid.Column="0" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.AppSecret]}"
60+
VerticalAlignment="Center"/>
4861
<TextBox Grid.Column="1" Text="{Binding Config.AppSecretKey}" Margin="8,0,16,0"/>
49-
<TextBlock Grid.Column="2" Text="Product ID" VerticalAlignment="Center"/>
62+
<TextBlock Grid.Column="2" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.ProductId]}"
63+
VerticalAlignment="Center"/>
5064
<TextBox Grid.Column="3" Text="{Binding Config.ProductId}" Margin="8,0"/>
5165
</Grid>
5266
</StackPanel>
@@ -55,17 +69,21 @@
5569
<!-- Output -->
5670
<Border Padding="16" CornerRadius="8" Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}">
5771
<StackPanel Spacing="10">
58-
<TextBlock Text="Output" FontSize="14" FontWeight="SemiBold"/>
72+
<TextBlock Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Output]}"
73+
FontSize="14" FontWeight="SemiBold"/>
5974
<Grid ColumnDefinitions="Auto,*,Auto">
60-
<TextBlock Grid.Column="0" Text="Simulate Dir" VerticalAlignment="Center" Width="110"/>
75+
<TextBlock Grid.Column="0" Text="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.OutputDir]}"
76+
VerticalAlignment="Center" Width="100"/>
6177
<TextBox Grid.Column="1" Text="{Binding Config.OutputDirectory}" IsReadOnly="True" Margin="8,0"/>
62-
<Button Grid.Column="2" Content="📁 Select" Command="{Binding SelectOutputDirCommand}" MinWidth="80"/>
78+
<Button Grid.Column="2" Content="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Select]}"
79+
Command="{Binding SelectOutputDirCommand}" MinWidth="80"/>
6380
</Grid>
6481
</StackPanel>
6582
</Border>
6683

6784
<!-- Run -->
68-
<Button Content="🚀 Start Simulation" Command="{Binding StartSimulationCommand}"
85+
<Button Content="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Start]}"
86+
Command="{Binding StartSimulationCommand}"
6987
IsEnabled="{Binding !IsRunning}" Height="40" FontSize="14" HorizontalAlignment="Stretch"/>
7088
<TextBlock Text="{Binding Status}" FontSize="13"/>
7189

src/Views/SimulateView.axaml.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
using Avalonia.Controls;
2+
using Avalonia.Interactivity;
23

34
namespace GeneralUpdate.Tools.Views;
45

56
public partial class SimulateView : UserControl
67
{
7-
public SimulateView() => InitializeComponent();
8+
public SimulateView()
9+
{
10+
InitializeComponent();
11+
}
12+
13+
protected override void OnLoaded(RoutedEventArgs e)
14+
{
15+
base.OnLoaded(e);
16+
if (DataContext is ViewModels.SimulateViewModel vm)
17+
{
18+
PlatformCombo.SelectionChanged += (_, _) =>
19+
{
20+
if (PlatformCombo.SelectedIndex >= 0)
21+
vm.Config.Platform = PlatformCombo.SelectedIndex == 1 ? 2 : 1;
22+
};
23+
AppTypeCombo.SelectionChanged += (_, _) =>
24+
{
25+
if (AppTypeCombo.SelectedIndex >= 0)
26+
vm.Config.AppType = AppTypeCombo.SelectedIndex == 1 ? 2 : 1;
27+
};
28+
}
29+
}
830
}

0 commit comments

Comments
 (0)