diff --git a/README.md b/README.md index 902c30fb..00547a18 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Zotero PDF Translate -This is an add-on for [Zotero 6](https://www.zotero.org/). It provides PDF translation for Zotero inner PDF reader. +This is an add-on for [Zotero 6](https://www.zotero.org/). It provides PDF translation for Zotero built-in PDF reader. ![](imgs/en2jp.png) @@ -27,12 +27,13 @@ Not the lauguage you want? The default tartget lauguage is `zh-CN`(Chinese Simpl The default engine is Google Translate. Currently we support: | Translate Engine | Require Secret | Supported Languages | | ---- | ---- | ---- | -| Google Translate | No | [200+]() -| Youdao Translate | No | [100+?](https://ai.youdao.com/DOCSIRMA/html/%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E7%BF%BB%E8%AF%91/API%E6%96%87%E6%A1%A3/%E6%96%87%E6%9C%AC%E7%BF%BB%E8%AF%91%E6%9C%8D%E5%8A%A1/%E6%96%87%E6%9C%AC%E7%BF%BB%E8%AF%91%E6%9C%8D%E5%8A%A1-API%E6%96%87%E6%A1%A3.html) +| Google Translate | No | [100+](https://translate.google.com/about/languages/) | | Microsoft Translate | Yes(free 2M) | [200+](https://docs.microsoft.com/en-us/azure/cognitive-services/translator/language-support) | -| LingoCloud(Caiyun) Translate | No(temporarily) | [zh, en, ja, es, fr, ru](https://open.caiyunapp.com/LingoCloud_API_in_5_minutes) +| Youdao Translate | No | [100+?](https://ai.youdao.com/DOCSIRMA/html/%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E7%BF%BB%E8%AF%91/API%E6%96%87%E6%A1%A3/%E6%96%87%E6%9C%AC%E7%BF%BB%E8%AF%91%E6%9C%8D%E5%8A%A1/%E6%96%87%E6%9C%AC%E7%BF%BB%E8%AF%91%E6%9C%8D%E5%8A%A1-API%E6%96%87%E6%A1%A3.html) | +| LingoCloud(Caiyun) Translate | No(temporarily) | [zh, en, ja, es, fr, ru](https://open.caiyunapp.com/LingoCloud_API_in_5_minutes) | +| Niu Translate | No | [100+](https://niutrans.com/documents/contents/trans_text#accessMode) | -如果你无法访问谷歌,请选择有道或彩云作为翻译引擎。 +如果你无法访问谷歌,请选择其他翻译引擎。 ### Lauguage Settings You can change the source and target language here. For some Translte Engines, the `secret` is required. They are listed below: > **Microsoft Translate** diff --git a/chrome/content/preferences.xul b/chrome/content/preferences.xul index 11904f7a..47d777a4 100644 --- a/chrome/content/preferences.xul +++ b/chrome/content/preferences.xul @@ -39,9 +39,10 @@ - + + diff --git a/chrome/content/scripts/zoteropdftranslate.js b/chrome/content/scripts/zoteropdftranslate.js index 0f5e675d..649b601d 100644 --- a/chrome/content/scripts/zoteropdftranslate.js +++ b/chrome/content/scripts/zoteropdftranslate.js @@ -1,5 +1,40 @@ Zotero.ZoteroPDFTranslate = { translate: { + niutrans: async function () { + let sl = Zotero.Prefs.get("ZoteroPDFTranslate.sourceLanguage"); + if (typeof sl === "undefined") { + secret = Zotero.ZoteroPDFTranslate.defaultSourceLanguage; + } + let tl = Zotero.Prefs.get("ZoteroPDFTranslate.targetLanguage"); + if (typeof tl === "undefined") { + secret = Zotero.ZoteroPDFTranslate.defaultTargetLanguage; + } + let param = `from=${sl.split("-")[0]}&to=${tl.split("-")[0]}`; + let xhr = await Zotero.HTTP.request( + "GET", + `https://test.niutrans.com/NiuTransServer/testaligntrans?${param}&src_text=${ + Zotero.ZoteroPDFTranslate._sourceText + }&source=text&dictNo=&memoryNo=&isUseDict=0&isUseMemory=0&time=${new Date().valueOf()}`, + { + responseType: "json", + } + ); + + if (xhr.status === 200) { + try { + let tgt = xhr.response.tgt_text; + Zotero.debug(tgt); + Zotero.ZoteroPDFTranslate._translatedText = tgt; + return 0; + } catch (e) { + Zotero.debug(e); + Zotero.debug(xhr); + return -1; + } + } + Zotero.ZoteroPDFTranslate._translatedText = xhr.status; + return xhr.status; + }, caiyun: async function () { let secret = Zotero.Prefs.get("ZoteroPDFTranslate.secret"); if (typeof secret === "undefined") { @@ -225,7 +260,7 @@ Zotero.ZoteroPDFTranslate = { Zotero.ZoteroPDFTranslate._translatedText = xhr.status; return xhr.status; }, - sources: ["google", "youdao", "microsoft", "caiyun"], + sources: ["google", "youdao", "microsoft", "caiyun", "niutrans"], defaultSourceLanguage: "en-US", defaultTargetLanguage: "zh-CN", defaultSecret: { @@ -233,6 +268,7 @@ Zotero.ZoteroPDFTranslate = { youdao: "", microsoft: "0fbf924f4a334759a3340cf7c09e2128", caiyun: "3975l6lr5pcbvidl6jl2", + niutrans: "", }, }, _openPagePopup: undefined, diff --git a/chrome/locale/en-US/overlay.dtd b/chrome/locale/en-US/overlay.dtd index 58c00898..84deda69 100644 --- a/chrome/locale/en-US/overlay.dtd +++ b/chrome/locale/en-US/overlay.dtd @@ -7,6 +7,7 @@ + @@ -14,5 +15,5 @@ - - + + diff --git a/chrome/locale/zh-CN/overlay.dtd b/chrome/locale/zh-CN/overlay.dtd index 356041a2..69eeaa94 100644 --- a/chrome/locale/zh-CN/overlay.dtd +++ b/chrome/locale/zh-CN/overlay.dtd @@ -7,6 +7,7 @@ + @@ -14,5 +15,5 @@ - - + + diff --git a/install.rdf b/install.rdf index 9e09936a..857b832e 100644 --- a/install.rdf +++ b/install.rdf @@ -7,7 +7,7 @@ RDF:about="urn:mozilla:install-manifest" em:id="zoteropdftranslate@euclpts.com" em:name="Zotero PDF Translate" - em:version="0.0.6" + em:version="0.0.7" em:type="2" em:creator="windingwind" em:description="PDF translation plugin for Zotero 6" diff --git a/update.rdf b/update.rdf index 04207431..dbb011aa 100644 --- a/update.rdf +++ b/update.rdf @@ -5,7 +5,7 @@ - 0.0.6 + 0.0.7 zotero@chnm.gmu.edu