You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

65 lines
1.9 KiB

2 years ago
using STranslate.Model;
using STranslate.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace STranslate.ViewModel
{
public class MainVM : BaseVM
{
2 years ago
private static readonly string ConfigPath = @"D:\STranslate.yml";
public static ConfigModel config = new ConfigModel();
private string Text;
2 years ago
public MainVM()
{
2 years ago
try
2 years ago
{
2 years ago
config = ConfigUtil.ReadConfig(ConfigPath);
TranslateCmd = new RelayCommand((_) =>
{
return string.IsNullOrEmpty(InputTxt) ? false : true;
}, async (_) =>
{
Text = InputTxt;
2 years ago
//清空输入框
InputTxt = "";
2 years ago
2 years ago
OutputTxt = "翻译中...";
2 years ago
//获取结果
//var translateResp = await TranslateUtil.TranslateDeepLAsync(InputTxt, LanguageEnum.EN, LanguageEnum.auto);
2 years ago
var translateResp = await TranslateUtil.TranslateBaiduAsync(config.baidu.appid, config.baidu.secretKey, Text, LanguageEnum.EN, LanguageEnum.auto);
2 years ago
if (translateResp == string.Empty)
{
OutputTxt = "翻译出错,请稍候再试...";
return;
}
OutputTxt = translateResp;
});
}
catch (Exception ex)
{
OutputTxt = ex.Message;
}
2 years ago
}
public ICommand TranslateCmd { get; private set; }
private string _InputTxt;
public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); }
private string _OutputTxt;
public string OutputTxt { get => _OutputTxt; set => UpdateProperty(ref _OutputTxt, value); }
}
}