using ComPDFKit_Conversion.Options;
using DryIoc;
using ImTools;
using Microsoft.Office.Interop.Word;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PDF_Master.Properties;
using PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using static Dropbox.Api.Files.SearchMatchType;
using static Dropbox.Api.TeamLog.EventCategory;
using static Google.Apis.Requests.BatchRequest;
namespace PDF_Master.Helper
{
public static class ChatGTPAIHelper
{
#if DEBUG
//测试环境
//纠错重写
private static string host = "https://ai.compdf.com";
//百度翻译
private static string translate = "http://101.132.103.13:8030";
#else
//纠错重写
private static string host = "https://ai.compdf.com";
//百度翻译
private static string translate ="https://api-server.compdf.com";
#endif
///
/// 翻译文档Key接口
///
private static string Uri_fileKeytranslate = translate + "/v1/translate/fileUpload";
///
/// 翻译文档接口
///
private static string Uri_filetranslate = translate + "/v1/translate/fileTranslateHandle";
///
/// 翻译文本接口
///
private static string Uri_texttranslate = translate + "/v1/translate/textTrans";
///
/// 错别字纠正
///
private static string Uri_Correction = host + "/api/correct-typos";
///
/// 错别字纠正
///
private static string Uri_Rewrite = host + "/api/rewrite";
///
/// chatGPT错误码
///
public static string ChatGPTCode = "";
#region AI服务器对接接口
///
/// 获取
///
///
///
///
public static async Task fileKeyTranslate(string content, string filename)
{
string Code = "Code" + "300";
ServicePointManager.DefaultConnectionLimit = 200;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_fileKeytranslate);
//关闭请求
//弹窗内进度条关闭
DocumentaryTranslationDialogViewModel.CancelProgress = () =>
{
if (request != null)
{
Code = "Code" + "-1";
request.Abort();
}
};
//进度条关闭
App.mainWindowViewModel.ProcessCloseAction = () =>
{
if (request != null)
{
Code = "Code" + "-1";
request.Abort();
}
};
request.Method = "Post";
//request.Accept = "application/vnd.api+json;version=1";
request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
request.Timeout = 20000;
request.ServicePoint.Expect100Continue = false;
request.KeepAlive = false;
var formData = new MultipartFormDataContent();
byte[] data = File.ReadAllBytes(@content);
MemoryStream stream = new MemoryStream(data);
formData.Add(new ByteArrayContent(data), "file", filename);
formData.Add(new StringContent("2"), "projectId");
formData.Add(new StringContent("1.0.1"), "version");
if (!string.IsNullOrEmpty(Settings.Default.UserDate.id))
{
formData.Add(new StringContent(Settings.Default.UserDate.id), "userId");
}
else
{
formData.Add(new StringContent("1"), "userId");
}
// 设置请求体格式
request.ContentType = formData.Headers.ContentType.ToString();
request.ContentLength = formData.Headers.ContentLength.Value;
// 将FormData写入请求体
try
{
using (var requestStream = request.GetRequestStream())
{
await formData.CopyToAsync(requestStream);
}
// 获取HTTP响应
HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response2.GetResponseStream()))
{
string responseData = reader.ReadToEnd();
Console.WriteLine(responseData);
reader.Close();
JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
if (response2 != null)
{
response2.Close();
}
if (request != null)
{
request.Abort();
}
string translation = "";
if (jobject["code"].ToObject().ToLower() == "200")
{
translation = jobject["data"]["fileKey"].ToObject().ToLower();
return translation;
}
return "Code" + jobject["code"].ToObject().ToLower();
}
}
catch (WebException ex)
{
int statusCode = 0;
if (ex.Response is HttpWebResponse)
{
//从网络异常信息里解析错误,后面的逻辑根据错误码判断会更准确
statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
}
Trace.WriteLine("HTTP异常:" + ex.Message);
if (statusCode == 401)
{
return "Code" + "401";
}
else
{
//-1为自己取消,300为一般错误
return Code;
}
}
catch
{
return "300";
}
}
public static string HttpDownloadFile(string url, string path)
{
// 设置参数
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
//创建本地文件写入流
Stream stream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
return path;
}
///
/// 翻译指定内容,可以指定语言
///
/// 文件
/// 文本语言
/// 需要翻译的语言
/// 是否需要阅读也进度条
/// code与文件路径
public static async Task fileTranslate(string content, string fromlanguage, string tolanguage, bool isprocess = true)
{
string Code = "300";
intProcess(isprocess, "Translating...", System.Windows.Visibility.Visible);
//判断word文档大小
if (!GetDocumentPagesWord(content))
{
clossProcess();
return "05011";
}
FileInfo file = new FileInfo(content);
string fileKey = await fileKeyTranslate(content, file.Name);
App.mainWindowViewModel.Value = 1;
if (fileKey.Contains("Code"))
{
clossProcess();
return fileKey.Replace("Code", "");
}
HttpWebResponse response = null;
ServicePointManager.DefaultConnectionLimit = 200;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_filetranslate);
//关闭请求
DocumentaryTranslationDialogViewModel.CancelProgress = () =>
{
if (request != null)
{
Code = "-1";
request.Abort();
}
};
App.mainWindowViewModel.ProcessCloseAction = () =>
{
if (request != null)
{
Code = "-1";
request.Abort();
}
};
request.Method = "Post";
request.ContentType = "application/json";
//request.Accept = "application/vnd.api+json;version=1";
request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
//设置无限请求时间:由于文本翻译时间不确定且时间长
request.Timeout = Timeout.Infinite;
request.ServicePoint.Expect100Continue = false;
request.KeepAlive = false;
StringWriter sw = new StringWriter();
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.WriteStartObject();
writer.WritePropertyName("fileKey");
writer.WriteValue(fileKey);
writer.WritePropertyName("from");
writer.WriteValue(fromlanguage);
writer.WritePropertyName("to");
writer.WriteValue(tolanguage);
writer.WritePropertyName("projectId");
writer.WriteValue("2");
writer.WritePropertyName("version");
writer.WriteValue("1.0.1");
writer.WritePropertyName("userId");
writer.WriteValue(Settings.Default.UserDate.id);
writer.WriteEndObject();
}
try
{
App.mainWindowViewModel.Value = 2;
string postBody = sw.ToString();
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(postBody);
writer.Close();
}
App.mainWindowViewModel.Value = 3;
response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
App.mainWindowViewModel.Value = 4;
string responseData = reader.ReadToEnd();
Console.WriteLine(responseData);
reader.Close();
JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
App.mainWindowViewModel.Value = 6;
if (response != null)
{
response.Close();
}
if (request != null)
{
request.Abort();
}
if (jobject["code"].ToObject().ToLower() == "200")
{
translate = jobject["data"]["ossDownUrl"].ToObject().ToLower();
//return jobject["code"].ToObject().ToLower();
using (var client = new WebClient())
{
App.mainWindowViewModel.Value = 8;
string folderPath = file.FullName.Remove(file.FullName.LastIndexOf("."), file.FullName.Length - file.FullName.LastIndexOf(".")) + "_aiTranslation.pdf";
folderPath = CommonHelper.CreateFilePath(folderPath);
client.DownloadProgressChanged += (sender, e) =>
{
};
client.DownloadFile(translate, folderPath);
clossProcess();
return folderPath;
}
}
clossProcess();
return jobject["code"].ToObject().ToLower();
}
}
catch (WebException ex)
{
clossProcess();
int statusCode = 0;
if (ex.Response is HttpWebResponse)
{
//从网络异常信息里解析错误,后面的逻辑根据错误码判断会更准确
statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
}
Trace.WriteLine("HTTP异常:" + ex.Message);
if (statusCode == 401)
{
return "401";
}
else
{
//-1为自己取消,300为一般错误
return Code;
}
}
catch
{
return "300";
}
}
///
/// 翻译指定内容,可以指定语言
///
/// 翻译内容
/// 文本语言
/// 需要翻译的语言
///
public static String textTranslate(string content, string fromlanguage, string tolanguage, ref string translate)
{
HttpWebResponse response = null;
ServicePointManager.DefaultConnectionLimit = 200;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_texttranslate);
request.Method = "Post";
request.ContentType = "application/json";
//request.Accept = "application/vnd.api+json;version=1";
request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
request.Timeout = 60000;
request.ServicePoint.Expect100Continue = false;
StringWriter sw = new StringWriter();
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.WriteStartObject();
writer.WritePropertyName("q");
writer.WriteValue(content);
writer.WritePropertyName("from");
writer.WriteValue(fromlanguage);
writer.WritePropertyName("to");
writer.WriteValue(tolanguage);
writer.WritePropertyName("projectId");
writer.WriteValue("2");
writer.WritePropertyName("version");
writer.WriteValue("1.0.1");
writer.WritePropertyName("userId");
writer.WriteValue(Settings.Default.UserDate.id);
writer.WriteEndObject();
}
try
{
string postBody = sw.ToString();
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(postBody);
writer.Close();
}
response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string responseData = reader.ReadToEnd();
Console.WriteLine(responseData);
reader.Close();
JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
if (response != null)
{
response.Close();
}
if (request != null)
{
request.Abort();
}
if (jobject["code"].ToObject().ToLower() == "200")
{
translate = jobject["data"]["dst"].ToObject().ToLower();
}
//return jobject["code"].ToObject().ToLower();
return jobject["code"].ToObject().ToLower();
}
}
catch (WebException ex)
{
int statusCode = 0;
if (ex.Response is HttpWebResponse)
{
//从网络异常信息里解析错误,后面的逻辑根据错误码判断会更准确
statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
}
if (statusCode == 401)
{
return "401";
}
else return "300";
}
catch
{
return "300";
}
}
///
/// 纠错
///
///
///
public static async Task Correction(string content)
{
intProcess(true, "Correcting...");
App.mainWindowViewModel.Value = 1;
ServicePointManager.DefaultConnectionLimit = 200;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_Correction);
request.Method = "Post";
//request.Accept = "application/vnd.api+json;version=1";
request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
request.Timeout = 60000;
request.ServicePoint.Expect100Continue = false;
var formData = new MultipartFormDataContent();
formData.Add(new StringContent("2"), "project_id");
formData.Add(new StringContent("1.0.1"), "version");
if (!string.IsNullOrEmpty(Settings.Default.UserDate.id))
{
formData.Add(new StringContent(Settings.Default.UserDate.id), "user_id");
}
else
{
formData.Add(new StringContent("1"), "user_id");
}
formData.Add(new StringContent(content), "content");
// 设置请求体格式
request.ContentType = formData.Headers.ContentType.ToString();
request.ContentLength = formData.Headers.ContentLength.Value;
App.mainWindowViewModel.Value = 3;
return await PostStringHttpWeb(formData, request, "content");
}
///
/// 重写
///
///
///
public static async Task Rewrite(string content)
{
intProcess(true, "Rewriting...");
App.mainWindowViewModel.Value = 1;
ServicePointManager.DefaultConnectionLimit = 200;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_Rewrite);
request.Method = "Post";
//request.Accept = "application/vnd.api+json;version=1";
request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
request.Timeout = 60000;
request.ServicePoint.Expect100Continue = false;
var formData = new MultipartFormDataContent();
formData.Add(new StringContent("2"), "project_id");
formData.Add(new StringContent("1.0.1"), "version");
if (!string.IsNullOrEmpty(Settings.Default.UserDate.id))
{
formData.Add(new StringContent(Settings.Default.UserDate.id), "user_id");
}
else
{
formData.Add(new StringContent("1"), "user_id");
}
formData.Add(new StringContent(content), "content");
// 设置请求体格式
request.ContentType = formData.Headers.ContentType.ToString();
request.ContentLength = formData.Headers.ContentLength.Value;
App.mainWindowViewModel.Value = 3;
return await PostStringHttpWeb(formData, request, "content");
}
///
/// 从链接中返回存在的链接(仅返回第一个找到的链接)
///
///
///
public static List GetLinkFromString(string content)
{
if (string.IsNullOrEmpty(content))
{
return null;
}
// 创建正则表达式模式
string pattern = @"(https?://[^\s]+)";
// 获取所有匹配项
MatchCollection matches = Regex.Matches(content, pattern);
List list = new List();
// 遍历并打印所有匹配项
foreach (Match match in matches)
{
list.Add(match.Value);
}
return list;
}
///
/// 从接口获取信息,获取message对应value值
///
/// 传入参数
/// 请求体
/// /// 值
///
private static async Task PostStringHttpWeb(MultipartFormDataContent formData, HttpWebRequest request, string key = "message")
{
App.mainWindowViewModel.Value = 6;
string repsonseData = "";
try
{
using (var requestStream = request.GetRequestStream())
{
await formData.CopyToAsync(requestStream);
}
// 获取HTTP响应
HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response2.GetResponseStream()))
{
string responseData = reader.ReadToEnd();
Console.WriteLine(responseData);
reader.Close();
App.mainWindowViewModel.Value = 7;
JObject jobject = (JObject)JsonConvert.DeserializeObject(responseData);
App.mainWindowViewModel.Value = 8;
if (response2 != null)
{
response2.Close();
}
if (request != null)
{
request.Abort();
}
string unicode = "";
// 遍历字典对象输出键值对
ChatGPTCode = jobject["code"].ToObject().ToLower();
if (ChatGPTCode == "200")
{
unicode = jobject["data"][key].ToObject().ToLower();
}
//将Unicode格式转换成String
//repsonseData = Regex.Unescape(unicode);
repsonseData = unicode;
clossProcess();
}
}
catch (WebException ex)
{
App.mainWindowViewModel.Value = 8;
int statusCode = 0;
if (ex.Response is HttpWebResponse)
{
//从网络异常信息里解析错误,后面的逻辑根据错误码判断会更准确
statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
}
if (statusCode == 401)
{
ChatGPTCode = "401";
}
else ChatGPTCode = "300";
clossProcess();
return null;
}
catch
{
ChatGPTCode = "300";
clossProcess();
}
clossProcess();
return repsonseData;
}
///
/// 从接口获取信息,获取message对应value值,WebClient没有设置请求时间参数换一种方案
///
///
///
///
private static async Task PostStringWebClient(string url, System.Collections.Specialized.NameValueCollection namevalue, string key = "message")
{
App.mainWindowViewModel.Value = 5;
string repsonseData = "";
try
{
using (var client = new WebClient())
{
byte[] bytes = await client.UploadValuesTaskAsync(url, namevalue);
//转换成字符串类型
var json = Encoding.Default.GetString(bytes);
//将Json格式字符串转换成键值对
//var values = JsonConvert.DeserializeObject>(json);
JObject jobject = (JObject)JsonConvert.DeserializeObject(json);
App.mainWindowViewModel.Value = 8;
string unicode = "";
// 遍历字典对象输出键值对
ChatGPTCode = jobject["code"].ToObject().ToLower();
if (ChatGPTCode == "200")
{
unicode = jobject["data"][key].ToObject().ToLower();
}
//将Unicode格式转换成String
//repsonseData = Regex.Unescape(unicode);
repsonseData = unicode;
}
clossProcess();
}
catch (WebException ex)
{
int statusCode = 0;
if (ex.Response is HttpWebResponse)
{
//从网络异常信息里解析错误,后面的逻辑根据错误码判断会更准确
statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
}
if (statusCode == 401)
{
ChatGPTCode = "401";
}
else ChatGPTCode = "300";
clossProcess();
return null;
}
return repsonseData;
}
///
/// 初始进度条
///
/// 是否需要进度条
/// 文案
public static void intProcess(bool isprocess = true, string progressTitle = "Translating...", System.Windows.Visibility ProcessCloseBtnVisible = System.Windows.Visibility.Collapsed)
{
if (isprocess)
{
App.mainWindowViewModel.ProgressTitle = progressTitle;
App.mainWindowViewModel.MaxValue = 10;
App.mainWindowViewModel.Value = 0;
App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
App.mainWindowViewModel.ProcessCloseBtnVisible = ProcessCloseBtnVisible;
}
}
///
/// 初始进度条
///
/// 是否需要进度条
/// 文案
/// 进度条最大值
/// 进度条关闭按钮是否可见
public static void SetIntProcess(bool isprocess = true, string progressTitle = "Splitting...", int maxValue = 10, System.Windows.Visibility ProcessCloseBtnVisible = System.Windows.Visibility.Collapsed)
{
if (isprocess)
{
App.mainWindowViewModel.ProgressTitle = progressTitle;
App.mainWindowViewModel.MaxValue = maxValue;
App.mainWindowViewModel.Value = 0;
App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
App.mainWindowViewModel.ProcessCloseBtnVisible = ProcessCloseBtnVisible;
}
}
///
/// 关闭进度条
///
public static void clossProcess()
{
App.mainWindowViewModel.Value = 9;
App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
}
///
/// 关闭进度条
///
/// 进度条当前值
public static void clossProcess(int value = 9)
{
App.mainWindowViewModel.Value = value;
App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
}
///
/// 判断word文档页面大小,如果接口有问题则交给服务器判断
///
///
/// 返回值为是否拿到页码没拿到则为true,页面过小为true
public static bool GetDocumentPagesWord(string filepath)
{
try
{
FileInfo fileInfo = new FileInfo(filepath);
if (fileInfo.Extension.ToLower() != ".pdf")
{
Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.Application();
object Nothing = System.Reflection.Missing.Value;
object oMissing = System.Reflection.Missing.Value;
//这里是Word文件的路径
object filePath = filepath;
//打开文件
Document myWordDoc = myWordApp.Documents.Open(
ref filePath, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//下面是取得打开文件的页数
int pages = myWordDoc.ComputeStatistics(WdStatistic.wdStatisticPages, ref Nothing);
//关闭文件
myWordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
//退出Word程序
myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
if (pages > 30)
{
return false;
}
}
return true;
}
catch
{
return true;
}
}
#endregion AI服务器对接接口
#region 支持翻译的语言
///
/// 当前语言列表
///
public static List FromlanguageFamily { set; get; } = new List();
public static List SetFromlanguageOrigin()
{
FromlanguageFamily.Clear();
FromlanguageFamily.Add("Automatic Identification");
FromlanguageFamily.Add("English");
FromlanguageFamily.Add("Simplified Chinese");
FromlanguageFamily.Add("Traditional Chinese");
FromlanguageFamily.Add("Japanese");
FromlanguageFamily.Add("Korean");
FromlanguageFamily.Add("French");
FromlanguageFamily.Add("Spanish");
FromlanguageFamily.Add("Italian");
FromlanguageFamily.Add("German");
FromlanguageFamily.Add("Portuguese");
FromlanguageFamily.Add("Russian");
FromlanguageFamily.Add("Vietnamese");
FromlanguageFamily.Add("Thai");
FromlanguageFamily.Add("Arabic");
FromlanguageFamily.Add("Greek");
FromlanguageFamily.Add("Bulgarian");
FromlanguageFamily.Add("Finnish");
FromlanguageFamily.Add("Slovene");
FromlanguageFamily.Add("Dutch");
FromlanguageFamily.Add("Czech");
FromlanguageFamily.Add("Swedish");
FromlanguageFamily.Add("Polish");
FromlanguageFamily.Add("Danish");
FromlanguageFamily.Add("Romanian");
FromlanguageFamily.Add("Hungarian");
return FromlanguageFamily;
}
///
/// 需要翻译成对应语言列表
///
public static List TolanguageFamily { set; get; } = new List();
public static List SetTolanguageOrigin()
{
TolanguageFamily.Clear();
TolanguageFamily.Add("English");
TolanguageFamily.Add("Simplified Chinese");
TolanguageFamily.Add("Traditional Chinese");
TolanguageFamily.Add("Japanese");
TolanguageFamily.Add("Korean");
TolanguageFamily.Add("French");
TolanguageFamily.Add("Spanish");
TolanguageFamily.Add("Italian");
TolanguageFamily.Add("German");
TolanguageFamily.Add("Portuguese");
TolanguageFamily.Add("Russian");
TolanguageFamily.Add("Vietnamese");
TolanguageFamily.Add("Thai");
TolanguageFamily.Add("Arabic");
TolanguageFamily.Add("Greek");
TolanguageFamily.Add("Bulgarian");
TolanguageFamily.Add("Finnish");
TolanguageFamily.Add("Slovene");
TolanguageFamily.Add("Dutch");
TolanguageFamily.Add("Czech");
TolanguageFamily.Add("Swedish");
TolanguageFamily.Add("Polish");
TolanguageFamily.Add("Danish");
TolanguageFamily.Add("Romanian");
TolanguageFamily.Add("Hungarian");
return TolanguageFamily;
}
///
/// 接口传值对应字符
///
/// 控制form与to的区别,form为0开始,to为1开始,因为to没有auto
///
public static string UpdateLanguagebType(int index)
{
switch (index)
{
case 0:
return "auto";
case 1:
return "en";
case 2:
return "zh";
case 3:
return "cht";
case 4:
return "jp";
case 5:
return "kor";
case 6:
return "fra";
case 7:
return "spa";
case 8:
return "it";
case 9:
return "de";
case 10:
return "pt";
case 11:
return "ru";
case 12:
return "vie";
case 13:
return "th";
case 14:
return "ara";
case 15:
return "el";
case 16:
return "bul";
case 17:
return "fin";
case 18:
return "slo";
case 19:
return "nl";
case 20:
return "cs";
case 21:
return "swe";
case 22:
return "pl";
case 23:
return "dan";
case 24:
return "rom";
case 25:
return "hu";
default:
return "";
}
}
#endregion 支持翻译的语言
#region 错误码
public static string GetBaiduTranslationCode(string code)
{
if (code == "300" || code == "401") { return App.HomePageLoader.GetString("ChatGTPNetworkError"); }
if (!String.IsNullOrEmpty(App.HomePageLoader.GetString("BaiduTranslation" + code)))
{
return App.HomePageLoader.GetString("BaiduTranslation" + code);
}
return code;
}
public static string GetChatGPTCode(string code)
{
if (code == "300" || code == "401") { return App.HomePageLoader.GetString("ChatGTPNetworkError"); }
if (!String.IsNullOrEmpty(App.HomePageLoader.GetString("ChatGTP" + code)))
{
return App.HomePageLoader.GetString("ChatGTP" + code);
}
return code;
}
#endregion 错误码
}
}