语言切换

This commit is contained in:
GukSang.Jin
2026-01-14 15:55:03 +08:00
parent 9891f7479a
commit 564258002e
4 changed files with 50 additions and 25 deletions

View File

@@ -33,9 +33,9 @@ namespace COFTester.Models
"CSI-H238M", "TestData"); "CSI-H238M", "TestData");
/// <summary> /// <summary>
/// 界面語言zh-TW繁體中文、zh-CN簡體中文、en-US英文 /// 界面語言zh-CN簡體中文、en-US英文
/// </summary> /// </summary>
public string Language { get; set; } = "zh-TW"; public string Language { get; set; } = "zh-CN";
/// <summary> /// <summary>
/// 自動保存測試結果 /// 自動保存測試結果

View File

@@ -94,7 +94,11 @@ namespace COFTester.Resources
["EndPosition"] = "结束位置", ["EndPosition"] = "结束位置",
["ApplyConfig"] = "应用配置", ["ApplyConfig"] = "应用配置",
["CancelConfig"] = "取消", ["CancelConfig"] = "取消",
["DetailedConfig"] = "详细配置" ["DetailedConfig"] = "详细配置",
["TestObject"] = "测试对象:",
["TestMethod"] = "测试方法:",
["KeyIndicators"] = "关键指标:",
["KineticWarningMessage"] = "此标准仅测量静摩擦系数,动摩擦计算区间将被忽略"
}, },
["en-US"] = new Dictionary<string, string> ["en-US"] = new Dictionary<string, string>
@@ -173,7 +177,11 @@ namespace COFTester.Resources
["EndPosition"] = "End Position", ["EndPosition"] = "End Position",
["ApplyConfig"] = "Apply", ["ApplyConfig"] = "Apply",
["CancelConfig"] = "Cancel", ["CancelConfig"] = "Cancel",
["DetailedConfig"] = "Detailed Config" ["DetailedConfig"] = "Detailed Config",
["TestObject"] = "Test Object:",
["TestMethod"] = "Test Method:",
["KeyIndicators"] = "Key Indicators:",
["KineticWarningMessage"] = "This standard only measures static friction coefficient, kinetic calculation range will be ignored"
} }
}; };
@@ -248,6 +256,10 @@ namespace COFTester.Resources
public string ApplyConfig => GetString("ApplyConfig"); public string ApplyConfig => GetString("ApplyConfig");
public string CancelConfig => GetString("CancelConfig"); public string CancelConfig => GetString("CancelConfig");
public string DetailedConfig => GetString("DetailedConfig"); public string DetailedConfig => GetString("DetailedConfig");
public string TestObject => GetString("TestObject");
public string TestMethod => GetString("TestMethod");
public string KeyIndicators => GetString("KeyIndicators");
public string KineticWarningMessage => GetString("KineticWarningMessage");
private string GetString(string key) private string GetString(string key)
{ {
@@ -325,6 +337,10 @@ namespace COFTester.Resources
OnPropertyChanged(nameof(ApplyConfig)); OnPropertyChanged(nameof(ApplyConfig));
OnPropertyChanged(nameof(CancelConfig)); OnPropertyChanged(nameof(CancelConfig));
OnPropertyChanged(nameof(DetailedConfig)); OnPropertyChanged(nameof(DetailedConfig));
OnPropertyChanged(nameof(TestObject));
OnPropertyChanged(nameof(TestMethod));
OnPropertyChanged(nameof(KeyIndicators));
OnPropertyChanged(nameof(KineticWarningMessage));
} }
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;

View File

@@ -43,6 +43,15 @@ namespace COFTester.ViewModels
ApplyCommand = new RelayCommand(Apply); ApplyCommand = new RelayCommand(Apply);
CancelCommand = new RelayCommand(Cancel); CancelCommand = new RelayCommand(Cancel);
// 監聽語言切換事件
LanguageResources.Instance.PropertyChanged += OnLanguageChanged;
}
private void OnLanguageChanged(object? sender, PropertyChangedEventArgs e)
{
// 當語言資源變化時,通知 UI 更新 Lang 屬性
OnPropertyChanged(nameof(Lang));
} }
public LanguageResources Lang => LanguageResources.Instance; public LanguageResources Lang => LanguageResources.Instance;

View File

@@ -50,8 +50,8 @@
<!-- Header --> <!-- Header -->
<Border Grid.Row="0" Style="{StaticResource CardStyle}" Margin="10,10,10,5"> <Border Grid.Row="0" Style="{StaticResource CardStyle}" Margin="10,10,10,5">
<StackPanel> <StackPanel>
<TextBlock Text="更多配置" FontSize="20" FontWeight="Bold" Foreground="{StaticResource PrimaryBrush}"/> <TextBlock Text="{Binding Lang.ConfigTitle}" FontSize="20" FontWeight="Bold" Foreground="{StaticResource PrimaryBrush}"/>
<TextBlock Text="详细测试参数配置与标准选择" FontSize="12" Foreground="{StaticResource GrayBrush}" Margin="0,5,0,0"/> <TextBlock Text="{Binding Lang.ConfigSubtitle}" FontSize="12" Foreground="{StaticResource GrayBrush}" Margin="0,5,0,0"/>
</StackPanel> </StackPanel>
</Border> </Border>
@@ -61,7 +61,7 @@
<!-- 测试标准选择 --> <!-- 测试标准选择 -->
<Border Style="{StaticResource CardStyle}"> <Border Style="{StaticResource CardStyle}">
<StackPanel> <StackPanel>
<TextBlock Text="测试标准选择" Style="{StaticResource SectionTitle}"/> <TextBlock Text="{Binding Lang.StandardSelection}" Style="{StaticResource SectionTitle}"/>
<!-- 标准下拉选择 --> <!-- 标准下拉选择 -->
<ComboBox ItemsSource="{Binding Standards}" <ComboBox ItemsSource="{Binding Standards}"
@@ -112,7 +112,7 @@
<!-- 测试对象 --> <!-- 测试对象 -->
<TextBlock Grid.Row="0" Grid.Column="0" <TextBlock Grid.Row="0" Grid.Column="0"
Text="测试对象:" Text="{Binding Lang.TestObject}"
FontSize="12" FontSize="12"
FontWeight="Bold" FontWeight="Bold"
Foreground="#2C3E50" Foreground="#2C3E50"
@@ -125,7 +125,7 @@
<!-- 测试方法 --> <!-- 测试方法 -->
<TextBlock Grid.Row="1" Grid.Column="0" <TextBlock Grid.Row="1" Grid.Column="0"
Text="测试方法:" Text="{Binding Lang.TestMethod}"
FontSize="12" FontSize="12"
FontWeight="Bold" FontWeight="Bold"
Foreground="#2C3E50" Foreground="#2C3E50"
@@ -138,7 +138,7 @@
<!-- 关键指标 --> <!-- 关键指标 -->
<TextBlock Grid.Row="2" Grid.Column="0" <TextBlock Grid.Row="2" Grid.Column="0"
Text="关键指标:" Text="{Binding Lang.KeyIndicators}"
FontSize="12" FontSize="12"
FontWeight="Bold" FontWeight="Bold"
Foreground="#2C3E50" Foreground="#2C3E50"
@@ -170,7 +170,7 @@
Visibility="{Binding ShowKineticWarning, Converter={StaticResource BoolToVisibilityConverter}}"> Visibility="{Binding ShowKineticWarning, Converter={StaticResource BoolToVisibilityConverter}}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="⚠️" FontSize="14" Margin="0,0,8,0"/> <TextBlock Text="⚠️" FontSize="14" Margin="0,0,8,0"/>
<TextBlock Text="此标准仅测量静摩擦系数,动摩擦计算区间将被忽略" <TextBlock Text="{Binding Lang.KineticWarningMessage}"
FontSize="11" FontSize="11"
Foreground="#856404" Foreground="#856404"
TextWrapping="Wrap"/> TextWrapping="Wrap"/>
@@ -182,9 +182,9 @@
<!-- 基本参数 --> <!-- 基本参数 -->
<Border Style="{StaticResource CardStyle}"> <Border Style="{StaticResource CardStyle}">
<StackPanel> <StackPanel>
<TextBlock Text="基本参数" Style="{StaticResource SectionTitle}"/> <TextBlock Text="{Binding Lang.BasicParameters}" Style="{StaticResource SectionTitle}"/>
<TextBlock Text="滑块质量 (Sled Mass)" Style="{StaticResource LabelStyle}"/> <TextBlock Text="{Binding Lang.SledMassConfig}" Style="{StaticResource LabelStyle}"/>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@@ -203,7 +203,7 @@
Margin="10,0,0,0"/> Margin="10,0,0,0"/>
</Grid> </Grid>
<TextBlock Text="测试速度 (Test Speed)" Style="{StaticResource LabelStyle}"/> <TextBlock Text="{Binding Lang.TestSpeedConfig}" Style="{StaticResource LabelStyle}"/>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@@ -222,7 +222,7 @@
Margin="10,0,0,0"/> Margin="10,0,0,0"/>
</Grid> </Grid>
<TextBlock Text="测试时长 (Test Duration)" Style="{StaticResource LabelStyle}"/> <TextBlock Text="{Binding Lang.TestDurationConfig}" Style="{StaticResource LabelStyle}"/>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@@ -241,7 +241,7 @@
Margin="10,0,0,0"/> Margin="10,0,0,0"/>
</Grid> </Grid>
<TextBlock Text="测试行程 (Test Stroke)" Style="{StaticResource LabelStyle}"/> <TextBlock Text="{Binding Lang.TestStrokeConfig}" Style="{StaticResource LabelStyle}"/>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@@ -265,9 +265,9 @@
<!-- 计算区间 --> <!-- 计算区间 -->
<Border Style="{StaticResource CardStyle}"> <Border Style="{StaticResource CardStyle}">
<StackPanel> <StackPanel>
<TextBlock Text="计算区间" Style="{StaticResource SectionTitle}"/> <TextBlock Text="{Binding Lang.CalculationRange}" Style="{StaticResource SectionTitle}"/>
<TextBlock Text="静摩擦计算区间 (Static COF Range)" Style="{StaticResource LabelStyle}"/> <TextBlock Text="{Binding Lang.StaticCalcRange}" Style="{StaticResource LabelStyle}"/>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@@ -275,17 +275,17 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Text="起始位置 (mm)" FontSize="11" Foreground="{StaticResource GrayBrush}"/> <TextBlock Text="{Binding Lang.StartPosition}" FontSize="11" Foreground="{StaticResource GrayBrush}"/>
<TextBox Text="{Binding ConfigParams.StaticCalcStart}" Height="30" FontSize="13"/> <TextBox Text="{Binding ConfigParams.StaticCalcStart}" Height="30" FontSize="13"/>
</StackPanel> </StackPanel>
<TextBlock Grid.Column="1" Text="~" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16"/> <TextBlock Grid.Column="1" Text="~" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16"/>
<StackPanel Grid.Column="2"> <StackPanel Grid.Column="2">
<TextBlock Text="结束位置 (mm)" FontSize="11" Foreground="{StaticResource GrayBrush}"/> <TextBlock Text="{Binding Lang.EndPosition}" FontSize="11" Foreground="{StaticResource GrayBrush}"/>
<TextBox Text="{Binding ConfigParams.StaticCalcEnd}" Height="30" FontSize="13"/> <TextBox Text="{Binding ConfigParams.StaticCalcEnd}" Height="30" FontSize="13"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
<TextBlock Text="动摩擦计算区间 (Kinetic COF Range)" Style="{StaticResource LabelStyle}" Margin="0,15,0,4"/> <TextBlock Text="{Binding Lang.KineticCalcRange}" Style="{StaticResource LabelStyle}" Margin="0,15,0,4"/>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@@ -293,12 +293,12 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Text="起始位置 (mm)" FontSize="11" Foreground="{StaticResource GrayBrush}"/> <TextBlock Text="{Binding Lang.StartPosition}" FontSize="11" Foreground="{StaticResource GrayBrush}"/>
<TextBox Text="{Binding ConfigParams.KineticCalcStart}" Height="30" FontSize="13"/> <TextBox Text="{Binding ConfigParams.KineticCalcStart}" Height="30" FontSize="13"/>
</StackPanel> </StackPanel>
<TextBlock Grid.Column="1" Text="~" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16"/> <TextBlock Grid.Column="1" Text="~" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16"/>
<StackPanel Grid.Column="2"> <StackPanel Grid.Column="2">
<TextBlock Text="结束位置 (mm)" FontSize="11" Foreground="{StaticResource GrayBrush}"/> <TextBlock Text="{Binding Lang.EndPosition}" FontSize="11" Foreground="{StaticResource GrayBrush}"/>
<TextBox Text="{Binding ConfigParams.KineticCalcEnd}" Height="30" FontSize="13"/> <TextBox Text="{Binding ConfigParams.KineticCalcEnd}" Height="30" FontSize="13"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
@@ -316,7 +316,7 @@
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Grid.Column="1" Content="应用配置" <Button Grid.Column="1" Content="{Binding Lang.ApplyConfig}"
Command="{Binding ApplyCommand}" Command="{Binding ApplyCommand}"
Width="120" Height="40" Margin="5" Width="120" Height="40" Margin="5"
Background="{StaticResource SuccessBrush}" Background="{StaticResource SuccessBrush}"
@@ -325,7 +325,7 @@
FontSize="14" FontWeight="Bold" FontSize="14" FontWeight="Bold"
Cursor="Hand"/> Cursor="Hand"/>
<Button Grid.Column="2" Content="取消" <Button Grid.Column="2" Content="{Binding Lang.CancelConfig}"
Command="{Binding CancelCommand}" Command="{Binding CancelCommand}"
Width="120" Height="40" Margin="5" Width="120" Height="40" Margin="5"
Background="{StaticResource GrayBrush}" Background="{StaticResource GrayBrush}"