我们要求将网页内容或整页翻译成其他语言,例如从英语翻译成西班牙语,
我尝试使用可用的变体OOTB进行翻译,但它不起作用,只翻译OOTB选项而不翻译页面上的内容。
无论如何使用Microsoft API完成同样的工作吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;
using Microsoft.Office.Client.TranslationServices;
using System.Security;
namespace testTranslate
{
class Program
{
static void Main(string[] args)
{
ClientContext clientContext = new ClientContext("https://xyz.sharepoint.com/sites/abc/");
string username = "abc@xyz.onmicrosoft.com", pssword = "";
var securePassword = new SecureString();
foreach (char c in pssword)
{
securePassword.AppendChar(c);
}
var onlineCredentials = new SharePointOnlineCredentials(username, securePassword);
clientContext.Credentials = onlineCredentials;
string jobID;
string culture = "en";
string name = "translationJob1";
string inputFile = "https://xyz.sharepoint.com/sites/abc/SitePages/testTranslate.aspx";
string outputFile = "https://xyz.sharepoint.com/sites/abc/SitePages/testTranslateEnglish.aspx";
TranslationJob job = new TranslationJob(clientContext, culture);
job.AddFile(inputFile, outputFile);
job.Name = name;
job.Start();
clientContext.Load(job);
clientContext.ExecuteQuery();
//To retrieve the translation job ID.
jobID = job.JobId.ToString();
//IEnumerable<string> supportedLanguages = TranslationJob.EnumerateSupportedLanguages(clientContext);
//clientContext.ExecuteQuery();
//foreach (string item in supportedLanguages)
//{
// Console.Write(item + ", ");
//}
Console.WriteLine("Script completed,press any key to exit");
Console.ReadKey();
}
}
}
由于
帕鲁
答案 0 :(得分:0)
SharePoint免费提供机器翻译服务,该服务由Microsoft Translator Text API提供支持。有关详细信息,请参阅Microsoft翻译器SharePoint网页https://www.microsoft.com/en-us/translator/sharepoint.aspx
如果您对使用翻译文本API感兴趣,请按照https://www.microsoft.com/en-us/translator/getstarted.aspx上的入门网页中的步骤操作。您可以通过订阅免费的每月订阅层来测试API。
答案 1 :(得分:0)
不是SharePoint专家,但您可能需要添加代码来翻译实际文档。以下是使用Microsoft Translator API的完整文档翻译工具的链接: