window.onload = function() {
if (typeof translate !== 'undefined') {
try {
translate.language.setLocal('chinese_simplified'); // 设置本地语种(当前网页的语种)。如果不设置,默认自动识别当前网页显示文字的语种。 可填写如 'english'、'chinese_simplified' 等,具体参见文档下方关于此的说明。
translate.service.use('client.edge'); // 设置机器翻译服务通道,直接客户端本身,不依赖服务端 。相关说明参考 http://translate.zvo.cn/43086.html
translate.execute(); // 进行翻译
// 监听翻译完成事件
translate.on('translated', function() {
location.reload(); // 翻译完成后自动刷新页面
});
} catch (error) {
console.error("Error during translation:", error);
}
} else {
console.error("Translate library is not loaded.");
}