|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Input;
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace STranslate.ViewModel
|
|
|
|
namespace STranslate.ViewModel
|
|
|
@ -13,12 +14,19 @@ namespace STranslate.ViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private static readonly string ConfigPath = @"D:\STranslate.yml";
|
|
|
|
private static readonly string ConfigPath = @"D:\STranslate.yml";
|
|
|
|
public static ConfigModel config = new ConfigModel();
|
|
|
|
public static ConfigModel config = new ConfigModel();
|
|
|
|
|
|
|
|
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); }
|
|
|
|
|
|
|
|
|
|
|
|
private string Text;
|
|
|
|
private string Text;
|
|
|
|
public MainVM()
|
|
|
|
public MainVM()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
//初始化界面参数
|
|
|
|
|
|
|
|
InputCombo = LanguageEnumDict.Keys.ToList();
|
|
|
|
|
|
|
|
InputComboSelected = LanguageEnum.AUTO.GetDescription();
|
|
|
|
|
|
|
|
OutputCombo = LanguageEnumDict.Keys.ToList();
|
|
|
|
|
|
|
|
OutputComboSelected = LanguageEnum.EN.GetDescription();
|
|
|
|
|
|
|
|
|
|
|
|
config = ConfigUtil.ReadConfig(ConfigPath);
|
|
|
|
config = ConfigUtil.ReadConfig(ConfigPath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -37,7 +45,7 @@ namespace STranslate.ViewModel
|
|
|
|
//获取结果
|
|
|
|
//获取结果
|
|
|
|
//var translateResp = await TranslateUtil.TranslateDeepLAsync(InputTxt, LanguageEnum.EN, LanguageEnum.auto);
|
|
|
|
//var translateResp = await TranslateUtil.TranslateDeepLAsync(InputTxt, LanguageEnum.EN, LanguageEnum.auto);
|
|
|
|
|
|
|
|
|
|
|
|
var translateResp = await TranslateUtil.TranslateBaiduAsync(config.baidu.appid, config.baidu.secretKey, Text, LanguageEnum.EN, LanguageEnum.auto);
|
|
|
|
var translateResp = await TranslateUtil.TranslateBaiduAsync(config.baidu.appid, config.baidu.secretKey, Text, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
|
|
|
|
|
|
|
|
|
|
|
|
if (translateResp == string.Empty)
|
|
|
|
if (translateResp == string.Empty)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -45,7 +53,9 @@ namespace STranslate.ViewModel
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OutputTxt = translateResp;
|
|
|
|
OutputTxt = translateResp;
|
|
|
|
|
|
|
|
Clipboard.SetText(OutputTxt);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -57,8 +67,21 @@ namespace STranslate.ViewModel
|
|
|
|
|
|
|
|
|
|
|
|
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); }
|
|
|
|
|
|
|
|
|
|
|
|
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 List<string> _InputCombo;
|
|
|
|
|
|
|
|
public List<string> InputCombo { get => _InputCombo; set => UpdateProperty(ref _InputCombo, value); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string _InputComboSelected;
|
|
|
|
|
|
|
|
public string InputComboSelected { get => _InputComboSelected; set => UpdateProperty(ref _InputComboSelected, value); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<string> _OutputCombo;
|
|
|
|
|
|
|
|
public List<string> OutputCombo { get => _OutputCombo; set => UpdateProperty(ref _OutputCombo, value); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string _OutputComboSelected;
|
|
|
|
|
|
|
|
public string OutputComboSelected { get => _OutputComboSelected; set => UpdateProperty(ref _OutputComboSelected, value); }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|