使用 Microsoft API 将页面内容翻译成其他语言
Translate the content of a page to other language using Microsoft APIs
我们需要将一页或整页的内容翻译成其他语言,例如从英语翻译成西班牙语,
我尝试使用可用的 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();
}
}
}
谢谢
帕鲁
SharePoint 免费提供机器翻译服务,该服务由 Microsoft Translator Text API 提供支持。在 https://www.microsoft.com/en-us/translator/sharepoint.aspx
的 Microsoft Translator SharePoint 网页中了解更多信息
如果您有兴趣使用文本翻译 API,请按照位于 https://www.microsoft.com/en-us/translator/getstarted.aspx 的入门网页中的步骤操作。您可以通过订阅免费的每月订阅层来测试 API。
不是 SharePoint 专家,但您可能需要添加代码来翻译实际文档。这是一个 link 到使用 Microsoft Translator API:
的完整文档翻译工具
我们需要将一页或整页的内容翻译成其他语言,例如从英语翻译成西班牙语,
我尝试使用可用的 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();
}
}
}
谢谢
帕鲁
SharePoint 免费提供机器翻译服务,该服务由 Microsoft Translator Text API 提供支持。在 https://www.microsoft.com/en-us/translator/sharepoint.aspx
的 Microsoft Translator SharePoint 网页中了解更多信息如果您有兴趣使用文本翻译 API,请按照位于 https://www.microsoft.com/en-us/translator/getstarted.aspx 的入门网页中的步骤操作。您可以通过订阅免费的每月订阅层来测试 API。
不是 SharePoint 专家,但您可能需要添加代码来翻译实际文档。这是一个 link 到使用 Microsoft Translator API:
的完整文档翻译工具