dev_self
DESKTOP-3BO4HSG\ksat 2 years ago
parent 579d967003
commit 5749612755

1
.gitignore vendored

@ -2,6 +2,7 @@
bin/ bin/
obj/ obj/
*.user *.user
.idea/
packages/ packages/

@ -62,6 +62,11 @@ namespace STranslate.Model
/// </summary> /// </summary>
[JsonProperty("servers")] [JsonProperty("servers")]
public Server[] Servers { get; set; } public Server[] Servers { get; set; }
/// <summary>
/// 服务
/// </summary>
[JsonProperty("baiduServers")]
public BaiduServer BaiduServers { get; set; }
} }
@ -73,4 +78,13 @@ namespace STranslate.Model
[JsonProperty("api")] [JsonProperty("api")]
public string Api { get; set; } public string Api { get; set; }
} }
public class BaiduServer
{
[JsonProperty("appid")]
public string Appid { get; set; }
[JsonProperty("secretKey")]
public string SecretKey { get; set; }
}
} }

@ -3,10 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:vm="clr-namespace:STranslate.ViewModel"
xmlns:local="clr-namespace:STranslate.View"
mc:Ignorable="d" mc:Ignorable="d"
x:Name="Mwin" x:Name="Mwin"
Background="Transparent" Background="Transparent"
@ -52,6 +49,7 @@
<RowDefinition Height="5*"/> <RowDefinition Height="5*"/>
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="7*"/> <RowDefinition Height="7*"/>
<RowDefinition Height="7*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!--header--> <!--header-->
@ -186,6 +184,44 @@
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
<!--output baidu-->
<Grid Margin="10,0,10,10"
Grid.Row="4">
<!--输出框-->
<Border Style="{DynamicResource BorderInOutputStyle}"
Height="{Binding Height, ElementName=Output}">
<Grid>
<TextBox Style="{DynamicResource TextBoxOutputStyle}"
Text="{Binding OutputTxt2}"/>
<StackPanel Orientation="Horizontal"
Margin="10,5"
VerticalAlignment="Bottom">
<Button Template="{DynamicResource ButtonTemplateSpeak}"
Visibility="{Binding OutputTxt2, Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding TargetSpeakCmd2}"/>
<!--普通复制-->
<Button Template="{DynamicResource ButtonTemplate}"
Visibility="{Binding OutputTxt2, Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyResultCmd2}"/>
<!--蛇形复制-->
<Button Margin="5,0"
Template="{DynamicResource ButtonTemplateSnakeCopy}"
Visibility="{Binding SnakeRet2, Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySnakeResultCmd2}"/>
<!--小驼峰复制-->
<Button Template="{DynamicResource ButtonTemplateSmallHumpCopy}"
Visibility="{Binding SmallHumpRet2, Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopySmallHumpResultCmd2}"/>
<!--大驼峰复制-->
<Button Margin="5,0"
Template="{DynamicResource ButtonTemplateLargeHumpCopy}"
Visibility="{Binding LargeHumpRet2, Converter={StaticResource String2VisibilityConverter}}"
Command="{Binding CopyLargeHumpResultCmd2}"/>
</StackPanel>
</Grid>
</Border>
</Grid>
</Grid> </Grid>
</Border> </Border>
</Window> </Window>

@ -85,16 +85,16 @@ namespace STranslate.ViewModel
{ {
Speech.SpeakAsync(InputTxt); Speech.SpeakAsync(InputTxt);
}); });
//target speak
TargetSpeakCmd = new RelayCommand((_) => true, (_) =>
{
Speech.SpeakAsync(OutputTxt);
});
//复制输入 //复制输入
CopyInputCmd = new RelayCommand((_) => true, (_) => CopyInputCmd = new RelayCommand((_) => true, (_) =>
{ {
Clipboard.SetText(InputTxt); Clipboard.SetText(InputTxt);
}); });
//target speak
TargetSpeakCmd = new RelayCommand((_) => true, (_) =>
{
Speech.SpeakAsync(OutputTxt);
});
//复制翻译结果 //复制翻译结果
CopyResultCmd = new RelayCommand((_) => true, (_) => CopyResultCmd = new RelayCommand((_) => true, (_) =>
{ {
@ -115,6 +115,31 @@ namespace STranslate.ViewModel
{ {
Clipboard.SetText(LargeHumpRet); Clipboard.SetText(LargeHumpRet);
}); });
//target speak
TargetSpeakCmd2 = new RelayCommand((_) => true, (_) =>
{
Speech.SpeakAsync(OutputTxt2);
});
//复制翻译结果
CopyResultCmd2 = new RelayCommand((_) => true, (_) =>
{
Clipboard.SetText(OutputTxt2);
});
//复制蛇形结果
CopySnakeResultCmd2 = new RelayCommand((_) => true, (_) =>
{
Clipboard.SetText(SnakeRet2);
});
//复制小驼峰结果
CopySmallHumpResultCmd2 = new RelayCommand((_) => true, (_) =>
{
Clipboard.SetText(SmallHumpRet2);
});
//复制大驼峰结果
CopyLargeHumpResultCmd2 = new RelayCommand((_) => true, (_) =>
{
Clipboard.SetText(LargeHumpRet2);
});
//主题切换 //主题切换
ThemeConvertCmd = new RelayCommand((_) => true, (o) => ThemeConvertCmd = new RelayCommand((_) => true, (o) =>
@ -143,9 +168,13 @@ namespace STranslate.ViewModel
{ {
InputTxt = string.Empty; InputTxt = string.Empty;
OutputTxt = string.Empty; OutputTxt = string.Empty;
OutputTxt2 = string.Empty;
SnakeRet = string.Empty; SnakeRet = string.Empty;
SmallHumpRet = string.Empty; SmallHumpRet = string.Empty;
LargeHumpRet = string.Empty; LargeHumpRet = string.Empty;
SnakeRet2 = string.Empty;
SmallHumpRet2 = string.Empty;
LargeHumpRet2 = string.Empty;
IdentifyLanguage = string.Empty; IdentifyLanguage = string.Empty;
} }
@ -268,6 +297,7 @@ namespace STranslate.ViewModel
TargetLanguage = OutputComboSelected, TargetLanguage = OutputComboSelected,
SelectServer = TranslationInterface.FindIndex(x => x == SelectedTranslationInterface), SelectServer = TranslationInterface.FindIndex(x => x == SelectedTranslationInterface),
Servers = _GlobalConfig.Servers, Servers = _GlobalConfig.Servers,
BaiduServers = _GlobalConfig.BaiduServers,
}); });
} }
catch (Exception ex) catch (Exception ex)
@ -321,10 +351,12 @@ namespace STranslate.ViewModel
var isEng = string.Empty; var isEng = string.Empty;
IdentifyLanguage = string.Empty; IdentifyLanguage = string.Empty;
OutputTxt = "翻译中..."; OutputTxt = "翻译中...";
OutputTxt2 = "翻译中...";
//清空多种复制 //清空多种复制
SnakeRet = string.Empty; SnakeRet = string.Empty;
SmallHumpRet = string.Empty; SmallHumpRet = string.Empty;
LargeHumpRet = string.Empty; LargeHumpRet = string.Empty;
var translateResp2 = string.Empty;
//自动选择目标语言 //自动选择目标语言
if (OutputComboSelected == LanguageEnum.AUTO.GetDescription()) if (OutputComboSelected == LanguageEnum.AUTO.GetDescription())
@ -333,20 +365,29 @@ namespace STranslate.ViewModel
IdentifyLanguage = autoRet.Item1; IdentifyLanguage = autoRet.Item1;
isEng = autoRet.Item2; isEng = autoRet.Item2;
translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]); translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]);
translateResp2 = await Util.Util.TranslateBaiduAsync(_GlobalConfig.BaiduServers.Appid, _GlobalConfig.BaiduServers.SecretKey, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]);
} }
else else
{ {
translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]); translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
}
//百度 Api //百度 Api
//var translateResp = await TranslateUtil.TranslateBaiduAsync(config.baidu.appid, config.baidu.secretKey, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]); translateResp2 = await Util.Util.TranslateBaiduAsync(_GlobalConfig.BaiduServers.Appid, _GlobalConfig.BaiduServers.SecretKey, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
}
if (translateResp == string.Empty) if (translateResp == string.Empty)
{ {
OutputTxt = "翻译出错,请稍候再试..."; OutputTxt = "翻译出错,请稍候再试...";
return; return;
} }
if (translateResp2 == string.Empty)
{
OutputTxt2 = "翻译出错,请稍候再试...";
return;
}
OutputTxt = translateResp; OutputTxt = translateResp;
OutputTxt2 = translateResp2;
//如果目标语言不是英文则不进行转换 //如果目标语言不是英文则不进行转换
//1. 自动判断语种Tuple item2 不为 EN //1. 自动判断语种Tuple item2 不为 EN
@ -367,11 +408,20 @@ namespace STranslate.ViewModel
SmallHumpRet = Util.Util.GenHumpString(splitList, true); //小驼峰 SmallHumpRet = Util.Util.GenHumpString(splitList, true); //小驼峰
LargeHumpRet = Util.Util.GenHumpString(splitList, false); //大驼峰 LargeHumpRet = Util.Util.GenHumpString(splitList, false); //大驼峰
} }
var splitList2 = OutputTxt2.Split(' ').ToList();
if (splitList2.Count > 1)
{
SnakeRet2 = Util.Util.GenSnakeString(splitList);
SmallHumpRet2 = Util.Util.GenHumpString(splitList, true); //小驼峰
LargeHumpRet2 = Util.Util.GenHumpString(splitList, false); //大驼峰
}
//System.Diagnostics.Debug.Print(SnakeRet + "\n" + SmallHumpRet + "\n" + LargeHumpRet); //System.Diagnostics.Debug.Print(SnakeRet + "\n" + SmallHumpRet + "\n" + LargeHumpRet);
} }
catch (Exception ex) catch (Exception ex)
{ {
OutputTxt = ex.Message; OutputTxt = ex.Message;
OutputTxt2 = ex.Message;
} }
} }
#endregion handle #endregion handle
@ -382,12 +432,17 @@ namespace STranslate.ViewModel
public ICommand DeactivatedCmd { get; private set; } public ICommand DeactivatedCmd { get; private set; }
public ICommand SourceSpeakCmd { get; private set; } public ICommand SourceSpeakCmd { get; private set; }
public ICommand TargetSpeakCmd { get; private set; } public ICommand TargetSpeakCmd { get; private set; }
public ICommand TargetSpeakCmd2 { get; private set; }
public ICommand TranslateCmd { get; private set; } public ICommand TranslateCmd { get; private set; }
public ICommand CopyInputCmd { get; private set; } public ICommand CopyInputCmd { get; private set; }
public ICommand CopyResultCmd { get; private set; } public ICommand CopyResultCmd { get; private set; }
public ICommand CopySnakeResultCmd { get; private set; } public ICommand CopySnakeResultCmd { get; private set; }
public ICommand CopySmallHumpResultCmd { get; private set; } public ICommand CopySmallHumpResultCmd { get; private set; }
public ICommand CopyLargeHumpResultCmd { get; private set; } public ICommand CopyLargeHumpResultCmd { get; private set; }
public ICommand CopyResultCmd2 { get; private set; }
public ICommand CopySnakeResultCmd2 { get; private set; }
public ICommand CopySmallHumpResultCmd2 { get; private set; }
public ICommand CopyLargeHumpResultCmd2 { get; private set; }
public ICommand ThemeConvertCmd { get; private set; } public ICommand ThemeConvertCmd { get; private set; }
public ICommand TopmostCmd { get; private set; } public ICommand TopmostCmd { get; private set; }
public ICommand EscCmd { get; private set; } public ICommand EscCmd { get; private set; }
@ -422,6 +477,11 @@ namespace STranslate.ViewModel
private string _SnakeRet; private string _SnakeRet;
public string SnakeRet { get => _SnakeRet; set => UpdateProperty(ref _SnakeRet, value); } public string SnakeRet { get => _SnakeRet; set => UpdateProperty(ref _SnakeRet, value); }
/// <summary> /// <summary>
/// 构造蛇形结果
/// </summary>
private string _SnakeRet2;
public string SnakeRet2 { get => _SnakeRet2; set => UpdateProperty(ref _SnakeRet2, value); }
/// <summary>
/// 构造驼峰结果 /// 构造驼峰结果
/// </summary> /// </summary>
private string _SmallHumpRet; private string _SmallHumpRet;
@ -429,8 +489,18 @@ namespace STranslate.ViewModel
/// <summary> /// <summary>
/// 构造驼峰结果 /// 构造驼峰结果
/// </summary> /// </summary>
private string _SmallHumpRet2;
public string SmallHumpRet2 { get => _SmallHumpRet2; set => UpdateProperty(ref _SmallHumpRet2, value); }
/// <summary>
/// 构造驼峰结果
/// </summary>
private string _LargeHumpRet; private string _LargeHumpRet;
public string LargeHumpRet { get => _LargeHumpRet; set => UpdateProperty(ref _LargeHumpRet, value); } public string LargeHumpRet { get => _LargeHumpRet; set => UpdateProperty(ref _LargeHumpRet, value); }
/// <summary>
/// 构造驼峰结果2
/// </summary>
private string _LargeHumpRet2;
public string LargeHumpRet2 { get => _LargeHumpRet2; set => UpdateProperty(ref _LargeHumpRet2, value); }
private string _InputTxt; private string _InputTxt;
public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); } public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); }
@ -438,6 +508,9 @@ namespace STranslate.ViewModel
private string _OutputTxt; private string _OutputTxt;
public string OutputTxt { get => _OutputTxt; set => UpdateProperty(ref _OutputTxt, value); } public string OutputTxt { get => _OutputTxt; set => UpdateProperty(ref _OutputTxt, value); }
private string _OutputTxt2;
public string OutputTxt2 { get => _OutputTxt2; set => UpdateProperty(ref _OutputTxt2, value); }
private List<string> _InputCombo; private List<string> _InputCombo;
public List<string> InputCombo { get => _InputCombo; set => UpdateProperty(ref _InputCombo, value); } public List<string> InputCombo { get => _InputCombo; set => UpdateProperty(ref _InputCombo, value); }

@ -30,28 +30,28 @@ namespace STranslate.ViewModel
{ {
if (MouseDown) if (MouseDown)
{ {
System.Windows.Point CurrentPoint = Mouse.GetPosition(_ScreenShotWin); var currentPoint = Mouse.GetPosition(_ScreenShotWin);
Rectangle = new Rect(StartPoint, CurrentPoint); _rectangle = new Rect(StartPoint, currentPoint);
Canvas.SetLeft(_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle, 0); Canvas.SetLeft(_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle, 0);
Canvas.SetTop(_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle, 0); Canvas.SetTop(_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle, 0);
(_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle).Width = Rectangle.X; (_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle).Width = _rectangle.X;
(_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle).Height = bitmap.Height; (_ScreenShotWin.FindName("LeftMask") as System.Windows.Shapes.Rectangle).Height = bitmap.Height;
Canvas.SetLeft(_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle, Rectangle.Left + Rectangle.Width); Canvas.SetLeft(_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle, _rectangle.Left + _rectangle.Width);
Canvas.SetTop(_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle, 0); Canvas.SetTop(_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle, 0);
(_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle).Width = bitmap.Width - Rectangle.Left - Rectangle.Width; (_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle).Width = bitmap.Width - _rectangle.Left - _rectangle.Width;
(_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle).Height = bitmap.Height; (_ScreenShotWin.FindName("RightMask") as System.Windows.Shapes.Rectangle).Height = bitmap.Height;
Canvas.SetLeft(_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle, Rectangle.Left); Canvas.SetLeft(_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle, _rectangle.Left);
Canvas.SetTop(_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle, 0); Canvas.SetTop(_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle, 0);
(_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle).Width = Rectangle.Width; (_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle).Width = _rectangle.Width;
(_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle).Height = Rectangle.Y; (_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle).Height = _rectangle.Y;
Canvas.SetLeft(_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle, Rectangle.Left); Canvas.SetLeft(_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle, _rectangle.Left);
Canvas.SetTop(_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle, Rectangle.Y + Rectangle.Height); Canvas.SetTop(_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle, _rectangle.Y + _rectangle.Height);
(_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle).Width = Rectangle.Width; (_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle).Width = _rectangle.Width;
(_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle).Height = bitmap.Height - Rectangle.Height - Rectangle.Y; (_ScreenShotWin.FindName("DownMask") as System.Windows.Shapes.Rectangle).Height = bitmap.Height - _rectangle.Height - _rectangle.Y;
} }
}); });
@ -67,10 +67,10 @@ namespace STranslate.ViewModel
{ {
MouseDown = false; MouseDown = false;
int x = (int)(Rectangle.X * dpiScale); var x = (int)(_rectangle.X * dpiScale);
int y = (int)(Rectangle.Y * dpiScale); var y = (int)(_rectangle.Y * dpiScale);
int width = (int)(Rectangle.Width * dpiScale); var width = (int)(_rectangle.Width * dpiScale);
int height = (int)(Rectangle.Height * dpiScale); var height = (int)(_rectangle.Height * dpiScale);
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0)
{ {
return; return;
@ -150,14 +150,14 @@ namespace STranslate.ViewModel
_ScreenShotWin.Background = Util.Util.BitmapToImageBrush(bitmap); _ScreenShotWin.Background = Util.Util.BitmapToImageBrush(bitmap);
} }
public ICommand EscCmd { get; private set; } private ICommand EscCmd { get; set; }
public ICommand MouseMoveCmd { get; private set; } private ICommand MouseMoveCmd { get; set; }
public ICommand MouseLeftDownCmd { get; private set; } private ICommand MouseLeftDownCmd { get; set; }
public ICommand MouseLeftUpCmd { get; private set; } private ICommand MouseLeftUpCmd { get; set; }
public ICommand ClosedCmd { get; private set; } private ICommand ClosedCmd { get; set; }
private Window _ScreenShotWin; //Window private Window _ScreenShotWin; //Window
private Rect Rectangle = new Rect(); //保存的矩形 private Rect _rectangle = new Rect(); //保存的矩形
private System.Windows.Point StartPoint; //鼠标按下的点 private System.Windows.Point StartPoint; //鼠标按下的点
private bool MouseDown; //鼠标是否被按下 private bool MouseDown; //鼠标是否被按下
private Bitmap bitmap; // 截屏图片 private Bitmap bitmap; // 截屏图片

Loading…
Cancel
Save