|
|
@ -11,35 +11,46 @@ namespace STranslate.ViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class MainVM : BaseVM
|
|
|
|
public class MainVM : BaseVM
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private static readonly string ConfigPath = @"D:\STranslate.yml";
|
|
|
|
|
|
|
|
public static ConfigModel config = new ConfigModel();
|
|
|
|
|
|
|
|
|
|
|
|
private string Text;
|
|
|
|
private string Text;
|
|
|
|
public MainVM()
|
|
|
|
public MainVM()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TranslateCmd = new RelayCommand((_) =>
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
return string.IsNullOrEmpty(InputTxt) ? false : true;
|
|
|
|
|
|
|
|
}, async (_) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Text = InputTxt;
|
|
|
|
config = ConfigUtil.ReadConfig(ConfigPath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TranslateCmd = new RelayCommand((_) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return string.IsNullOrEmpty(InputTxt) ? false : true;
|
|
|
|
|
|
|
|
}, async (_) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Text = InputTxt;
|
|
|
|
|
|
|
|
|
|
|
|
//清空输入框
|
|
|
|
//清空输入框
|
|
|
|
InputTxt = "";
|
|
|
|
InputTxt = "";
|
|
|
|
|
|
|
|
|
|
|
|
OutputTxt = "翻译中...";
|
|
|
|
OutputTxt = "翻译中...";
|
|
|
|
|
|
|
|
|
|
|
|
//获取结果
|
|
|
|
//获取结果
|
|
|
|
//var translateResp = await TranslateUtil.TranslateDeepLAsync(InputTxt, LanguageEnum.EN, LanguageEnum.auto);
|
|
|
|
//var translateResp = await TranslateUtil.TranslateDeepLAsync(InputTxt, LanguageEnum.EN, LanguageEnum.auto);
|
|
|
|
|
|
|
|
|
|
|
|
var appId = "";
|
|
|
|
var translateResp = await TranslateUtil.TranslateBaiduAsync(config.baidu.appid, config.baidu.secretKey, Text, LanguageEnum.EN, LanguageEnum.auto);
|
|
|
|
var secretKey = "";
|
|
|
|
|
|
|
|
var translateResp = await TranslateUtil.TranslateBaiduAsync(appId, secretKey, Text, LanguageEnum.EN, LanguageEnum.auto);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (translateResp == string.Empty)
|
|
|
|
if (translateResp == string.Empty)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OutputTxt = "翻译出错,请稍候再试...";
|
|
|
|
OutputTxt = "翻译出错,请稍候再试...";
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OutputTxt = translateResp;
|
|
|
|
OutputTxt = translateResp;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
OutputTxt = ex.Message;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand TranslateCmd { get; private set; }
|
|
|
|
public ICommand TranslateCmd { get; private set; }
|
|
|
|