private void btnTranslate_Click(object sender, EventArgs e) { string text = txtSrc.Text.Trim(); if (string.IsNullOrEmpty(text)) { return; } string from = cmbFrom.Text; if (string.IsNullOrEmpty(from)) { return; } LanguageType languageType = AsrLibrary.Utils.Text2LanguageType(from); string result = string.Empty; // 2)翻译 bool ret = _trans.Trans(text, languageType, out result); if (ret) { txtResult.Text = result; } else { WriteLine(result); } }
/// <summary> /// 翻译 /// </summary> /// <param name="text">待翻译的内容</param> /// <param name="from">翻译源语种</param> /// <param name="result">成功返回翻译结果,失败返回错误消息</param> /// <param name="to">翻译目的语种,默认为中文</param> /// <returns>true-成功;false-失败</returns> public bool Trans(string text, LanguageType from, out string result, LanguageType to = LanguageType.Mandarin) { if (_translate == null) { result = "客户端尚未初始化"; return(false); } return(_translate.Trans(text, from, out result, to)); }