例如,我设置了下右这个鼠标手势动作为页面翻译
可否设置为每一次这个动作都在翻译与未翻译状态间切换?
目前每一次这个动作都是翻译页面,想要回到未翻译状态需要唤出翻译弹窗手动点击原文
翻译的状态切换
Re: 翻译的状态切换
关于这个功能,我认为是可以实现的,按源码来看brave应该是调用的chronium的api
而chronium在翻译和恢复上主要是chromium/components/translate/core/browser/resources/translate.js中的translate和revert,猜测另一个浏览器可能是手动调用了revert这个过程。
也许开发者可以关注一下翻译切换状态这个功能?
而chronium在翻译和恢复上主要是chromium/components/translate/core/browser/resources/translate.js中的translate和revert,猜测另一个浏览器可能是手动调用了revert这个过程。
也许开发者可以关注一下翻译切换状态这个功能?
代码: 全选
/**
* 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();
},
上次由 Shinki 在 2023年 8月 9日 09:59,总共编辑 1 次。
Re: 翻译的状态切换
内核源码关于该功能的代码,第一次翻译之后会有一个bool 标识,当第二次再对该页进行翻译,遇到true直接返回,也就是说不支持第二次翻译,猫眼把这个逻辑取消了,可以进行多次重复翻译过来,从自己使用过程中的感受来看,多次翻译效果很一般!
Re: 翻译的状态切换
那是否可以保留逻辑判断,在翻译逻辑里添加遇到true调用revert()然后把标识标为false,这样即使遇到长文,需要多次翻译,也只是多了一次手势
上次由 Shinki 在 2023年 8月 9日 11:01,总共编辑 1 次。