翻译的状态切换
发表于 : 2023年 8月 8日 08:36
例如,我设置了下右这个鼠标手势动作为页面翻译
可否设置为每一次这个动作都在翻译与未翻译状态间切换?
目前每一次这个动作都是翻译页面,想要回到未翻译状态需要唤出翻译弹窗手动点击原文
可否设置为每一次这个动作都在翻译与未翻译状态间切换?
目前每一次这个动作都是翻译页面,想要回到未翻译状态需要唤出翻译弹窗手动点击原文
是的,在这一点上我同意开发者
代码: 全选
/**
* Translate the page contents. Note that the translation is asynchronous.
* You need to regularly check the state of |finished| and |errorCode| to
* know if the translation finished or if there was an error.
* @param {string} sourceLang The language the page is in.
* @param {string} targetLang The language the page should be translated to.
* @return {boolean} False if the translate library was not ready, in which
* case the translation is not started. True otherwise.
*/
translate(sourceLang, targetLang) {
finished = false;
errorCode = ERROR['NONE'];
if (!libReady) {
return false;
}
startTime = performance.now();
try {
lib.translatePage(sourceLang, targetLang, onTranslateProgress);
} catch (err) {
console.error('Translate: ' + err);
errorCode = ERROR['UNEXPECTED_SCRIPT_ERROR'];
invokeResultCallback();
return false;
}
return true;
},
/**
* Reverts the page contents to its original value, effectively reverting
* any performed translation. Does nothing if the page was not translated.
*/
revert() {
lib.restore();
},