SharePoint 2013 全球语言功能 (C# 部分 JS 我没有验证)

SharePoint 2013 翻译功能

SharePoint 2013 中的一个新的服务应用程序, 它提供了文件和网站的自动机器翻译。还提供 云服务还提供 Microsoft Office、Lync、Yammer 和 Bing 翻译功能。 翻译计时器作业的默认间隔为 15 分钟;您可以在管理中心中或使用Windows PowerShell 管理该设置。您还可以使用以下命令将计时器设置为立即执行:
$tj = get-sptimerjob "Sharepoint Translation Services"
$tj.Runnow()



使用服务器对象模型的异步翻译

TranslationJob 类定义了一组要翻译的项目。它可以是单个文件或文件夹/文档库中的每个文件。以此方式提交的翻译作业将存储在翻译数据库中。每次运行翻译计时器作业时,它会从翻译数据库中提取一些作业并将其添加到要翻译的异步队列中。翻译计时器作业的默认间隔为 15 分钟。

以下代码演示如何异步翻译单个文件。

SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site));
TranslationJob job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture)); 
job.AddFile(input, output);
job.Start(); 


以下代码演示如何异步翻译文档库中的每个文件。

SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site));
TranslationJob job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture));
using (SPSite siteIn = new SPSite(inputList))
{
    using (SPWeb webIn = siteIn.OpenWeb())
    {
        using (SPSite siteOut = new SPSite(outputList))
        {
            using (SPWeb webOut = siteOut.OpenWeb())
            {
                SPDocumentLibrary listIn = (SPDocumentLibrary)webIn.GetList(inputList);
                SPDocumentLibrary listOut = (SPDocumentLibrary)webOut.GetList(outputList);
                job.AddLibrary(listIn, listOut);
                job.Start();
            }
        }
    }
}


以下代码演示如何同步翻译单个文件。

SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site));
SyncTranslator job = new SyncTranslator(sc, CultureInfo.GetCultureInfo(jobCulture));
TranslationItemInfo itemInfo = job.Translate(input, output);

异步翻译单个文件:

ClientContext clientContext = new ClientContext("http://serverName/sites/siteCollectionPath");
string culture  = "cultureID";
string name = "translationJobName";
string  inputFile =  "http://serverName/path/inputFileName";
string outputFile = "http://serverName/path/outputFileName";
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.
string jobID = job.JobId;

异步翻译文件夹:

ClientContext clientContext = new ClientContext("http://serverName/sites/siteCollectionPath");
string culture = "cultureID";
string name = "translationJobName";
string inputFolder = clientContext.Web.GetFolderByServerRelativeUrl("inFolderPath");
string outputFolder = clientContext.Web.GetFolderByServerRelativeUrl("outFolderPath");  
TranslationJob job = new TranslationJob(clientContext , culture);
job.AddFolder(inputFolder, outputFolder, true);
job.Name = name;
job.Start();            
clientContext.Load(job);
clientContext.ExecuteQuery();
//To retrieve the translation job ID.
string jobID = job.JobId;

异步翻译库:

ClientContext clientContext = new ClientContext("http://serverName/sites/siteCollectionPath");
string culture = "cultureID";
string name = "translationJobName";
string inputLibrary = clientContext.Web.Lists.GetByTitle("inputLibraryName");
string outputLibrary = clientContext.Web.Lists.GetByTitle("outputLibraryName");
TranslationJob job = new TranslationJob(clientContext , culture);
job.AddFolder(inputLibrary , outputLibrary , true);
job.Name = name;
job.Start();            
clientContext.Load(job);
clientContext.ExecuteQuery();
//To retrieve the translation job ID.
string jobID = job.JobId;

同步翻译单个文件:

ClientContext clientContext = new ClientContext("http://serverName/sites/siteCollectionPath");
string culture = "cultureID"
string inputFile = "http://serverName/path/inputFileName";
string outputFile = "http://serverName/path/outputFileName";
SyncTranslator job = new SyncTranslator(clientContext , culture);
job.OutputSaveBehavior = SaveBehavior.AlwaysOverwrite;
ClientResult<TranslationItemInfo> cr = job.Translate(inputFile, outputFile );
clientContext.ExecuteQuery(); 
//To retrieve additional information about the translation job.
string errorCode = clientContext.Value.ErrorCode;
string errorMessage = clientContext.Value.ErrorMessage;
string translateID = clientContext.Value.TranslationId;
string succeedResult  = clientContext.Value.Succeeded;
string failResult  = clientContext.Value.Failed;
string cancelStatus = clientContext.Value.Canceled;
string inProgressStatus = clientContext.Value.InProgress;
string notStartedStatus = clientContext.Value.NotStarted;

检索机器翻译服务支持的所有语言:

ClientContext clientContext = new ClientContext("http://serverName/sites/siteCollectionPath");
IEnumerable<string> supportedLanguages = TranslationJob.EnumerateSupportedLanguages(clientContext);
clientContext.ExecuteQuery();
foreach (string item in supportedLanguages)
{
    Console.Write(item + ", ");
}

先列出来 API 接口。

异步翻译 REST API

以下是用于执行异步翻译的 REST API:
http://serverName/_api/TranslationJob('language')

异步翻译单个文件:
http://serverName/_api/TranslationJob('language')/TranslateFile(inputFile='/path/intput file', outputFile='/path/output file')

异步翻译文件夹:
http://serverName/_api/TranslationJob('language')/TranslateFolder(inputFolder='/path/in', outputFolder='/path/out')

异步翻译库:
http://serverName/_api/TranslationJob('language')/TranslateLibrary(inputLibrary='/LibraryName', outputLibrary='/LibraryName'')

同步翻译 REST API

机器翻译服务 REST 服务仅支持文件的同步翻译。以下是用于执行此操作的 API:
http://serverName/_api/SyncTranslator('language')/Translate(outputFile='/path/output file', inputFile='/path/input file')

附加的 机器翻译服务 REST API

机器翻译服务 REST 服务包括可用于检索有关机器翻译服务应用程序功能和翻译作业状态的信息的附加 API。

检索机器翻译服务支持的所有语言:
http://serverName/_api/TranslationJob.EnumerateSupportedLanguages

检查是否支持某种特定语言:
http://serverName/_api/TranslationJob.IsLanguageSupported('language')

检索机器翻译服务支持的所有文件扩展名:
http://serverName/_api/TranslationJob.EnumerateSupportedFileEXtensions

检查是否支持某个特定文件扩展名:
http://serverName/_api/TranslationJob.IsFileExtensionSupported('extension')

检查特定文件扩展名的文件大小限制:
http://serverName/_api/TranslationJob.GetMaximumFileSize('extension')

检索所有异步翻译作业的列表:
http://serverName/_api/TranslationJobStatus.GetAllJobs

检索所有活动异步翻译作业的列表:
http://serverName/_api/TranslationJobStatus.GetAllActiveJobs

检索特定异步翻译作业的文档信息:
http://serverName/_api/TranslationJobStatus('jobid')/GetAllItems

取消异步翻译作业:
http://serverName/_api/TranslationJob.CancelJob('jobid')


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值