Compare commits

...

1 Commits

Author SHA1 Message Date
DESKTOP-3BO4HSG\ksat 5749612755 tmp
2 years ago

1
.gitignore vendored

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

@ -62,6 +62,11 @@ namespace STranslate.Model
/// </summary>
[JsonProperty("servers")]
public Server[] Servers { get; set; }
/// <summary>
/// 服务
/// </summary>
[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; }
}
}

@ -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 @@
<RowDefinition Height="5*"/>
<RowDefinition Height="*" />
<RowDefinition Height="7*"/>
<RowDefinition Height="7*"/>
</Grid.RowDefinitions>
<!--header-->
@ -186,6 +184,44 @@
</Grid>
</Border>
</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>
</Border>
</Window>

@ -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); }
/// <summary>
/// 构造蛇形结果
/// </summary>
private string _SnakeRet2;
public string SnakeRet2 { get => _SnakeRet2; set => UpdateProperty(ref _SnakeRet2, value); }
/// <summary>
/// 构造驼峰结果
/// </summary>
private string _SmallHumpRet;
@ -429,8 +489,18 @@ namespace STranslate.ViewModel
/// <summary>
/// 构造驼峰结果
/// </summary>
private string _SmallHumpRet2;
public string SmallHumpRet2 { get => _SmallHumpRet2; set => UpdateProperty(ref _SmallHumpRet2, value); }
/// <summary>
/// 构造驼峰结果
/// </summary>
private string _LargeHumpRet;
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;
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<string> _InputCombo;
public List<string> InputCombo { get => _InputCombo; set => UpdateProperty(ref _InputCombo, value); }

@ -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; // 截屏图片

Loading…
Cancel
Save