make translation service endpoint configurable
This commit is contained in:
Родитель
96111eb0ad
Коммит
b229e89013
|
@ -1752,19 +1752,21 @@ module TDev {
|
|||
|
||||
private translateToScriptAsync(to: string, tutorialId: string): Promise { // translated topic
|
||||
// unpublished tutorial
|
||||
if (!tutorialId)
|
||||
if (!tutorialId ||
|
||||
// cloud config not set
|
||||
!Cloud.config.translateCdnUrl || !Cloud.config.translateApiUrl)
|
||||
return Promise.as(this.translatedTopic = <HelpTopicInfoJson>{ body: undefined });
|
||||
|
||||
return ProgressOverlay.lockAndShowAsync(lf("translating topic...") + (dbg ? tutorialId : ""))
|
||||
.then(() => {
|
||||
var blobUrl = HTML.proxyResource("https://tdtutorialtranslator.blob.core.windows.net/docs/" + to + "/" + tutorialId);
|
||||
var blobUrl = HTML.proxyResource(Cloud.config.translateCdnUrl + "/docs/" + to + "/" + tutorialId);
|
||||
return Util.httpGetJsonAsync(blobUrl).then((blob) => {
|
||||
this.translatedTopic = blob;
|
||||
return this.translatedTopic;
|
||||
}, e => {
|
||||
// requestion translation
|
||||
Util.log('requesting topic translation');
|
||||
var url = 'https://tdtutorialtranslator.azurewebsites.net/api/translate_doc?scriptId=' + tutorialId + '&to=' + to;
|
||||
var url = Cloud.config.translateApiUrl + '/translate_doc?scriptId=' + tutorialId + '&to=' + to;
|
||||
return Util.httpGetJsonAsync(url).then((js) => {
|
||||
this.translatedTopic = js.info;
|
||||
return this.translatedTopic;
|
||||
|
|
|
@ -3903,12 +3903,13 @@
|
|||
}
|
||||
|
||||
static translateCommentAsync(cid: string): Promise { // text
|
||||
if (!Cloud.config.translateCdnUrl || !Cloud.config.translateApiUrl) return Promise.as(undefined);
|
||||
var to = Util.getTranslationLanguage();
|
||||
var blobUrl = "https://tdtutorialtranslator.blob.core.windows.net/comments/" + to + "/" + cid;
|
||||
var blobUrl = Cloud.config.translateCdnUrl + "/comments/" + to + "/" + cid;
|
||||
return Util.httpGetTextAsync(blobUrl)
|
||||
.then((blob) => blob, e => {
|
||||
// requestion translation
|
||||
var url = 'https://tdtutorialtranslator.azurewebsites.net/api/translate_comment?commentId=' + cid + '&to=' + to;
|
||||
var url = Cloud.config.translateApiUrl + '/translate_comment?commentId=' + cid + '&to=' + to;
|
||||
return Util.httpGetJsonAsync(url).then((js) => js.translated, e => undefined);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1118,21 +1118,21 @@ module TDev
|
|||
|
||||
private translateAsync(to : string) : Promise { // of TranslatedTutorialInfo
|
||||
if (this.translatedTutorial) return Promise.as(this.translatedTutorial);
|
||||
if (!to || /^en/i.test(to) || Cloud.isOffline()) return Promise.as(undefined);
|
||||
if (!to || /^en(-us)?$/i.test(to) || Cloud.isOffline() || !Cloud.config.translateCdnUrl || !Cloud.config.translateApiUrl) return Promise.as(undefined);
|
||||
|
||||
tick(Ticks.tutorialTranslateScript, to);
|
||||
var tutorialId = this.topic.json.id;
|
||||
return ProgressOverlay.lockAndShowAsync(lf("translating tutorial..."))
|
||||
.then(() => {
|
||||
Util.log('loading tutorial translation from blob');
|
||||
var blobUrl = HTML.proxyResource("https://tdtutorialtranslator.blob.core.windows.net/translations/" + to + "/" + tutorialId);
|
||||
var blobUrl = HTML.proxyResource(Cloud.config.translateCdnUrl + "/translations/" + to + "/" + tutorialId);
|
||||
return Util.httpGetJsonAsync(blobUrl).then((blob) => {
|
||||
this.translatedTutorial = blob;
|
||||
return this.translatedTutorial;
|
||||
}, e => {
|
||||
// requestion translation
|
||||
Util.log('requesting tutorial translation');
|
||||
var url = 'https://tdtutorialtranslator.azurewebsites.net/api/translate_tutorial?scriptId=' + tutorialId + '&to=' + to;
|
||||
var url = HTML.proxyResource(Cloud.config.translateApiUrl + '/translate_tutorial?scriptId=' + tutorialId + '&to=' + to);
|
||||
return Util.httpGetJsonAsync(url).then((js) => {
|
||||
this.translatedTutorial = js.info;
|
||||
return this.translatedTutorial;
|
||||
|
|
|
@ -162,6 +162,8 @@ module TDev.Cloud {
|
|||
liteVersion: string;
|
||||
shareUrl: string;
|
||||
cdnUrl: string;
|
||||
translateCdnUrl: string;
|
||||
translateApiUrl: string;
|
||||
hashtag: string;
|
||||
|
||||
tdVersion?: string;
|
||||
|
@ -176,6 +178,8 @@ module TDev.Cloud {
|
|||
searchApiKey: "E43690E2B2A39FEB68117546BF778DB8", // touchdevelop web app query key in portal
|
||||
searchUrl: "https://tdsearch.search.windows.net",
|
||||
cdnUrl: "https://az31353.vo.msecnd.net",
|
||||
translateCdnUrl: "https://tdtutorialtranslator.blob.core.windows.net",
|
||||
translateApiUrl: "https://tdtutorialtranslator.azurewebsites.net/api",
|
||||
workspaceUrl: null,
|
||||
rootUrl: "https://www.touchdevelop.com",
|
||||
shareUrl: "http://tdev.ly",
|
||||
|
|
Загрузка…
Ссылка в новой задаче