TranslationSettingsWindow.xaml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <Window x:Class="LocalizationTool.Views.TranslationSettingsWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:hc="https://handyorg.github.io/handycontrol"
  5. Title="翻译设置" Height="580" Width="700"
  6. WindowStartupLocation="CenterScreen"
  7. Background="#F5F6FA">
  8. <Grid>
  9. <Grid.RowDefinitions>
  10. <RowDefinition Height="*"/>
  11. <RowDefinition Height="Auto"/>
  12. </Grid.RowDefinitions>
  13. <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" Padding="24">
  14. <StackPanel>
  15. <TextBlock Text="🌐 自动翻译设置" FontSize="20" FontWeight="Bold" Foreground="#333" Margin="0,0,0,16"/>
  16. <!-- 翻译引擎选择 -->
  17. <GroupBox Header="翻译引擎" Style="{StaticResource GroupBoxOriginal}">
  18. <StackPanel Margin="12" Orientation="Horizontal">
  19. <RadioButton Content="OpenAI (ChatGPT)" GroupName="Provider" Margin="5"
  20. IsChecked="{Binding IsOpenAi}" Command="{Binding SwitchToOpenAiCommand}"/>
  21. <RadioButton Content="百度翻译" GroupName="Provider" Margin="5"
  22. IsChecked="{Binding IsBaidu}" Command="{Binding SwitchToBaiduCommand}"/>
  23. </StackPanel>
  24. </GroupBox>
  25. <!-- OpenAI 设置 -->
  26. <GroupBox Header="OpenAI 配置" Style="{StaticResource GroupBoxOriginal}"
  27. Visibility="{Binding IsOpenAi, Converter={StaticResource BoolToVis}}">
  28. <hc:UniformSpacingPanel Spacing="12" Orientation="Vertical" Margin="12">
  29. <DockPanel>
  30. <TextBlock Text="Base URL:" Width="100" VerticalAlignment="Center"/>
  31. <TextBox hc:InfoElement.Placeholder="留空 = 内置默认" Style="{StaticResource TextBoxExtend}"
  32. Text="{Binding BaseUrl, UpdateSourceTrigger=PropertyChanged}"/>
  33. </DockPanel>
  34. <DockPanel>
  35. <TextBlock Text="Model:" Width="100" VerticalAlignment="Center"/>
  36. <Button DockPanel.Dock="Right" Content="获取模型" Width="80"
  37. Margin="8,0,0,0" Style="{StaticResource ButtonDefault}"
  38. Command="{Binding FetchModelsCommand}"
  39. ToolTip="从 {BaseUrl}/models 接口获取可用模型列表"/>
  40. <ComboBox IsEditable="True" hc:InfoElement.Placeholder="手输或点“获取模型”后筛选选择"
  41. Text="{Binding Model, UpdateSourceTrigger=PropertyChanged}"
  42. ItemsSource="{Binding FilteredModels, Mode=OneWay}"/>
  43. </DockPanel>
  44. <DockPanel>
  45. <TextBlock Text="最大上下文:" Width="100" VerticalAlignment="Center"/>
  46. <TextBox hc:InfoElement.Placeholder="留空 = 内置默认 512K"
  47. Style="{StaticResource TextBoxExtend}"
  48. Text="{Binding MaxContextTokensText, UpdateSourceTrigger=PropertyChanged}"
  49. ToolTip="模型上下文窗口上限(token),用于 AI 助手上下文用量指示器。留空 = 内置默认(agnes-2.5-flash 512K)"/>
  50. </DockPanel>
  51. <DockPanel>
  52. <TextBlock Text="API Key:" Width="100" VerticalAlignment="Center"/>
  53. <PasswordBox x:Name="TxtOpenAIKey" hc:InfoElement.Placeholder="sk-..." Style="{StaticResource PasswordBoxExtend}"
  54. PasswordChanged="OpenAiKey_PasswordChanged"/>
  55. </DockPanel>
  56. <DockPanel Margin="0,2,0,0">
  57. <Button DockPanel.Dock="Right" Content="↺ 恢复默认" Width="90"
  58. Margin="8,0,0,0" Style="{StaticResource ButtonDefault}"
  59. Command="{Binding ResetOpenAICommand}"
  60. ToolTip="清空自定义 Base URL / Model / API Key,回到程序内置默认 AI"/>
  61. <TextBlock FontSize="11" VerticalAlignment="Center"
  62. Foreground="{DynamicResource SecondaryTextBrush}"
  63. Text="{Binding OpenAiStatus}"/>
  64. </DockPanel>
  65. </hc:UniformSpacingPanel>
  66. </GroupBox>
  67. <!-- 百度翻译设置 -->
  68. <GroupBox Header="百度翻译配置" Style="{StaticResource GroupBoxOriginal}"
  69. Visibility="{Binding IsBaidu, Converter={StaticResource BoolToVis}}">
  70. <hc:UniformSpacingPanel Spacing="12" Orientation="Vertical" Margin="12">
  71. <DockPanel>
  72. <TextBlock Text="APP ID:" Width="100" VerticalAlignment="Center"/>
  73. <TextBox hc:InfoElement.Placeholder="留空 = 内置默认" Style="{StaticResource TextBoxExtend}"
  74. Text="{Binding BaiduAppIdInput, UpdateSourceTrigger=PropertyChanged}"/>
  75. </DockPanel>
  76. <DockPanel>
  77. <TextBlock Text="密钥:" Width="100" VerticalAlignment="Center"/>
  78. <PasswordBox x:Name="TxtBaiduSecret" hc:InfoElement.Placeholder="留空 = 内置默认" Style="{StaticResource PasswordBoxExtend}"
  79. PasswordChanged="BaiduSecret_PasswordChanged"/>
  80. </DockPanel>
  81. <DockPanel>
  82. <TextBlock Text="翻译模式:" Width="100" VerticalAlignment="Center"/>
  83. <StackPanel Orientation="Horizontal">
  84. <RadioButton Content="NMT 机器翻译(默认·快)" GroupName="BaiduModelType"
  85. Margin="0,0,16,0" IsChecked="{Binding IsNmt}"/>
  86. <RadioButton Content="LLM 大模型翻译(质量好·需开通)" GroupName="BaiduModelType"
  87. IsChecked="{Binding IsLlm}"/>
  88. </StackPanel>
  89. </DockPanel>
  90. <StackPanel>
  91. <TextBlock Text="翻译指令 reference(llm 模式生效 · 如保留数字/符号只翻文本):" FontSize="11"
  92. Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,0,0,4"/>
  93. <TextBox TextWrapping="Wrap" AcceptsReturn="False" FontSize="12" Height="46"
  94. VerticalScrollBarVisibility="Auto" VerticalContentAlignment="Top"
  95. Text="{Binding Reference, UpdateSourceTrigger=PropertyChanged}"/>
  96. </StackPanel>
  97. <DockPanel Margin="0,2,0,0">
  98. <Button DockPanel.Dock="Right" Content="↺ 恢复默认" Width="90"
  99. Margin="8,0,0,0" Style="{StaticResource ButtonDefault}"
  100. Command="{Binding ResetBaiduCommand}"
  101. ToolTip="清空自定义 APP ID / 密钥,回到程序内置默认百度凭证"/>
  102. <TextBlock FontSize="11" VerticalAlignment="Center"
  103. Foreground="{DynamicResource SecondaryTextBrush}"
  104. Text="{Binding BaiduStatus}"/>
  105. </DockPanel>
  106. </hc:UniformSpacingPanel>
  107. </GroupBox>
  108. <!-- 测试翻译 -->
  109. <GroupBox Header="测试翻译" Style="{StaticResource GroupBoxOriginal}">
  110. <hc:UniformSpacingPanel Spacing="12" Orientation="Vertical" Margin="12">
  111. <DockPanel>
  112. <TextBlock Text="目标语言:" Width="100" VerticalAlignment="Center"/>
  113. <ComboBox Width="280" HorizontalAlignment="Left" DisplayMemberPath="Display"
  114. ItemsSource="{Binding TestLanguages}"
  115. SelectedItem="{Binding TestLang}"
  116. ToolTip="来自语言目录(LanguageCatalog),百度自动映射语言代码;OpenAI 直接使用语言代码"/>
  117. </DockPanel>
  118. <DockPanel>
  119. <TextBlock Text="测试文本:" Width="100" VerticalAlignment="Top" Margin="0,8,0,0"/>
  120. <TextBox Height="60" TextWrapping="Wrap" AcceptsReturn="True"
  121. hc:InfoElement.Placeholder="输入中文测试..." Style="{StaticResource TextBoxExtend}"
  122. Text="{Binding TestText, UpdateSourceTrigger=PropertyChanged}"/>
  123. </DockPanel>
  124. <Button Content="🧪 测试翻译" Width="120" HorizontalAlignment="Left"
  125. Style="{StaticResource ButtonPrimary}" Command="{Binding TestCommand}"
  126. IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBool}}"/>
  127. <Border Background="#FFFFFF" CornerRadius="4" Padding="12" MinHeight="80" BorderBrush="#E4E7EC" BorderThickness="1">
  128. <TextBlock Text="{Binding TestResult}" TextWrapping="Wrap" Foreground="#333"/>
  129. </Border>
  130. </hc:UniformSpacingPanel>
  131. </GroupBox>
  132. </StackPanel>
  133. </ScrollViewer>
  134. <!-- 底部按钮 -->
  135. <Border Grid.Row="1" Background="White" BorderBrush="#E4E7EC" BorderThickness="0,1,0,0" Padding="16">
  136. <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
  137. <Button Content="保存" Width="88" Style="{StaticResource ButtonPrimary}"
  138. Command="{Binding SaveCommand}" Margin="0,0,10,0"/>
  139. <Button Content="取消" Width="88" Style="{StaticResource ButtonDefault}"
  140. Command="{Binding CancelCommand}"/>
  141. </StackPanel>
  142. </Border>
  143. </Grid>
  144. </Window>