diff --git a/.gitignore b/.gitignore
index d7a21fa..94fa45d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
bin/
obj/
*.user
+.idea/
packages/
\ No newline at end of file
diff --git a/STranslate/Model/ConfigModel.cs b/STranslate/Model/ConfigModel.cs
index 113701c..b36cbb0 100644
--- a/STranslate/Model/ConfigModel.cs
+++ b/STranslate/Model/ConfigModel.cs
@@ -62,6 +62,11 @@ namespace STranslate.Model
///
[JsonProperty("servers")]
public Server[] Servers { get; set; }
+ ///
+ /// 服务
+ ///
+ [JsonProperty("baiduServers")]
+ public BaiduServer BaiduServers { get; set; }
}
@@ -73,4 +78,13 @@ namespace STranslate.Model
[JsonProperty("api")]
public string Api { get; set; }
}
+
+ public class BaiduServer
+ {
+ [JsonProperty("appid")]
+ public string Appid { get; set; }
+
+ [JsonProperty("secretKey")]
+ public string SecretKey { get; set; }
+ }
}
diff --git a/STranslate/View/MainWindow.xaml b/STranslate/View/MainWindow.xaml
index c6e7957..59d5710 100644
--- a/STranslate/View/MainWindow.xaml
+++ b/STranslate/View/MainWindow.xaml
@@ -3,10 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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:vm="clr-namespace:STranslate.ViewModel"
- xmlns:local="clr-namespace:STranslate.View"
mc:Ignorable="d"
x:Name="Mwin"
Background="Transparent"
@@ -52,6 +49,7 @@
+
@@ -186,6 +184,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs
index d5d5c87..fceca6c 100644
--- a/STranslate/ViewModel/MainVM.cs
+++ b/STranslate/ViewModel/MainVM.cs
@@ -85,16 +85,16 @@ namespace STranslate.ViewModel
{
Speech.SpeakAsync(InputTxt);
});
- //target speak
- TargetSpeakCmd = new RelayCommand((_) => true, (_) =>
- {
- Speech.SpeakAsync(OutputTxt);
- });
//复制输入
CopyInputCmd = new RelayCommand((_) => true, (_) =>
{
Clipboard.SetText(InputTxt);
});
+ //target speak
+ TargetSpeakCmd = new RelayCommand((_) => true, (_) =>
+ {
+ Speech.SpeakAsync(OutputTxt);
+ });
//复制翻译结果
CopyResultCmd = new RelayCommand((_) => true, (_) =>
{
@@ -115,6 +115,31 @@ namespace STranslate.ViewModel
{
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) =>
@@ -143,9 +168,13 @@ namespace STranslate.ViewModel
{
InputTxt = string.Empty;
OutputTxt = string.Empty;
+ OutputTxt2 = string.Empty;
SnakeRet = string.Empty;
SmallHumpRet = string.Empty;
LargeHumpRet = string.Empty;
+ SnakeRet2 = string.Empty;
+ SmallHumpRet2 = string.Empty;
+ LargeHumpRet2 = string.Empty;
IdentifyLanguage = string.Empty;
}
@@ -268,6 +297,7 @@ namespace STranslate.ViewModel
TargetLanguage = OutputComboSelected,
SelectServer = TranslationInterface.FindIndex(x => x == SelectedTranslationInterface),
Servers = _GlobalConfig.Servers,
+ BaiduServers = _GlobalConfig.BaiduServers,
});
}
catch (Exception ex)
@@ -321,10 +351,12 @@ namespace STranslate.ViewModel
var isEng = string.Empty;
IdentifyLanguage = string.Empty;
OutputTxt = "翻译中...";
+ OutputTxt2 = "翻译中...";
//清空多种复制
SnakeRet = string.Empty;
SmallHumpRet = string.Empty;
LargeHumpRet = string.Empty;
+ var translateResp2 = string.Empty;
//自动选择目标语言
if (OutputComboSelected == LanguageEnum.AUTO.GetDescription())
@@ -333,20 +365,29 @@ namespace STranslate.ViewModel
IdentifyLanguage = autoRet.Item1;
isEng = autoRet.Item2;
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
{
translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
- }
- //百度 Api
- //var translateResp = await TranslateUtil.TranslateBaiduAsync(config.baidu.appid, config.baidu.secretKey, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
+ //百度 Api
+ translateResp2 = await Util.Util.TranslateBaiduAsync(_GlobalConfig.BaiduServers.Appid, _GlobalConfig.BaiduServers.SecretKey, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
+
+ }
if (translateResp == string.Empty)
{
OutputTxt = "翻译出错,请稍候再试...";
return;
}
+ if (translateResp2 == string.Empty)
+ {
+ OutputTxt2 = "翻译出错,请稍候再试...";
+ return;
+ }
OutputTxt = translateResp;
+ OutputTxt2 = translateResp2;
//如果目标语言不是英文则不进行转换
//1. 自动判断语种:Tuple item2 不为 EN
@@ -367,11 +408,20 @@ namespace STranslate.ViewModel
SmallHumpRet = Util.Util.GenHumpString(splitList, true); //小驼峰
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);
}
catch (Exception ex)
{
OutputTxt = ex.Message;
+ OutputTxt2 = ex.Message;
}
}
#endregion handle
@@ -382,12 +432,17 @@ namespace STranslate.ViewModel
public ICommand DeactivatedCmd { get; private set; }
public ICommand SourceSpeakCmd { get; private set; }
public ICommand TargetSpeakCmd { get; private set; }
+ public ICommand TargetSpeakCmd2 { get; private set; }
public ICommand TranslateCmd { get; private set; }
public ICommand CopyInputCmd { get; private set; }
public ICommand CopyResultCmd { get; private set; }
public ICommand CopySnakeResultCmd { get; private set; }
public ICommand CopySmallHumpResultCmd { 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 TopmostCmd { get; private set; }
public ICommand EscCmd { get; private set; }
@@ -422,6 +477,11 @@ namespace STranslate.ViewModel
private string _SnakeRet;
public string SnakeRet { get => _SnakeRet; set => UpdateProperty(ref _SnakeRet, value); }
///
+ /// 构造蛇形结果
+ ///
+ private string _SnakeRet2;
+ public string SnakeRet2 { get => _SnakeRet2; set => UpdateProperty(ref _SnakeRet2, value); }
+ ///
/// 构造驼峰结果
///
private string _SmallHumpRet;
@@ -429,8 +489,18 @@ namespace STranslate.ViewModel
///
/// 构造驼峰结果
///
+ private string _SmallHumpRet2;
+ public string SmallHumpRet2 { get => _SmallHumpRet2; set => UpdateProperty(ref _SmallHumpRet2, value); }
+ ///
+ /// 构造驼峰结果
+ ///
private string _LargeHumpRet;
public string LargeHumpRet { get => _LargeHumpRet; set => UpdateProperty(ref _LargeHumpRet, value); }
+ ///
+ /// 构造驼峰结果2
+ ///
+ private string _LargeHumpRet2;
+ public string LargeHumpRet2 { get => _LargeHumpRet2; set => UpdateProperty(ref _LargeHumpRet2, value); }
private string _InputTxt;
public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); }
@@ -438,6 +508,9 @@ namespace STranslate.ViewModel
private string _OutputTxt;
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 _InputCombo;
public List InputCombo { get => _InputCombo; set => UpdateProperty(ref _InputCombo, value); }
diff --git a/STranslate/ViewModel/ScreenShotVM.cs b/STranslate/ViewModel/ScreenShotVM.cs
index 62caf12..e40ffde 100644
--- a/STranslate/ViewModel/ScreenShotVM.cs
+++ b/STranslate/ViewModel/ScreenShotVM.cs
@@ -30,28 +30,28 @@ namespace STranslate.ViewModel
{
if (MouseDown)
{
- System.Windows.Point CurrentPoint = Mouse.GetPosition(_ScreenShotWin);
- Rectangle = new Rect(StartPoint, CurrentPoint);
+ var currentPoint = Mouse.GetPosition(_ScreenShotWin);
+ _rectangle = new Rect(StartPoint, currentPoint);
Canvas.SetLeft(_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;
- 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);
- (_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;
- 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);
- (_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).Width = _rectangle.Width;
+ (_ScreenShotWin.FindName("UpMask") as System.Windows.Shapes.Rectangle).Height = _rectangle.Y;
- 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);
- (_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;
+ 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);
+ (_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;
}
});
@@ -67,10 +67,10 @@ namespace STranslate.ViewModel
{
MouseDown = false;
- int x = (int)(Rectangle.X * dpiScale);
- int y = (int)(Rectangle.Y * dpiScale);
- int width = (int)(Rectangle.Width * dpiScale);
- int height = (int)(Rectangle.Height * dpiScale);
+ var x = (int)(_rectangle.X * dpiScale);
+ var y = (int)(_rectangle.Y * dpiScale);
+ var width = (int)(_rectangle.Width * dpiScale);
+ var height = (int)(_rectangle.Height * dpiScale);
if (width <= 0 || height <= 0)
{
return;
@@ -150,14 +150,14 @@ namespace STranslate.ViewModel
_ScreenShotWin.Background = Util.Util.BitmapToImageBrush(bitmap);
}
- public ICommand EscCmd { get; private set; }
- public ICommand MouseMoveCmd { get; private set; }
- public ICommand MouseLeftDownCmd { get; private set; }
- public ICommand MouseLeftUpCmd { get; private set; }
- public ICommand ClosedCmd { get; private set; }
+ private ICommand EscCmd { get; set; }
+ private ICommand MouseMoveCmd { get; set; }
+ private ICommand MouseLeftDownCmd { get; set; }
+ private ICommand MouseLeftUpCmd { get; set; }
+ private ICommand ClosedCmd { get; set; }
private Window _ScreenShotWin; //Window
- private Rect Rectangle = new Rect(); //保存的矩形
+ private Rect _rectangle = new Rect(); //保存的矩形
private System.Windows.Point StartPoint; //鼠标按下的点
private bool MouseDown; //鼠标是否被按下
private Bitmap bitmap; // 截屏图片