解决谷歌翻译在大陆停止服务导致一些翻译插件无法使用的问题

    选择打赏方式

2022年9月末,谷歌旗下网页翻译工具谷歌翻译停止了中国区服务,现在访问translate.google.cn网页会指向谷歌香港站。

但话虽如此,实际上API并没有关闭,大陆还是可以正请求的,只需要hosts一下即可。

下面放出bat代码,自行将以下文本复制到txt,改txt为bat,管理员身份运行即可;

@SETLOCAL enabledelayedexpansion
@echo off

set "source_domain=google.cn"
set "target_domain=translate.googleapis.com"

set "hosts_file=C:WindowsSystem32driversetchosts"

for /f "skip=4 tokens=2" %%a in ('"nslookup %source_domain% 2>NUL"') do set ip=%%a
set "old_rule=null"
set "new_rule=%ip% %target_domain%"

for /f "tokens=*" %%i in ('type %hosts_file%') do (
set "line=%%i"
:: Retrieve the rule If the target domain has been exists in the line.
if not "!line:%target_domain%=!"=="%%i" set "old_rule=%%i"
)

if not "%old_rule%"=="null" (
if not "%old_rule%"=="%new_rule%" (
echo Deleting the rule "%old_rule%"
echo Adding the rule "%new_rule%"
for /f "tokens=" %%i in ('type "%hosts_file%" ^| find /v /n "" ^& break ^> "%hosts_file%"') do (
set "rule=%%i"
set "rule=!rule:]=!"
if "%old_rule%"=="!rule!" set "rule=%new_rule%"
>>%hosts_file% echo(!rule!
)
) else (
echo The rule already exists, nothing to do.
)
) else (
echo Adding the rule "%new_rule%"
echo.>>%hosts_file%
echo.>>%hosts_file%
echo # Fix Google Translate CN>>%hosts_file%
echo %new_rule%>>%hosts_file%
)

echo Done.
pause
代码来源于Github大佬 @yanchenyuvip 感恩!

版权声明:若无特殊注明,本文为《傲世》原创,转载请保留文章出处。
本文链接:https://www.recho.cn/246.html
正文到此结束

热门推荐

发表吐槽

匿名评论 请叫我雷锋~

你还可以输入 250 / 250 个字

呵呵 哈哈 吐舌 开心 笑眼 可怜 乖 啊 你懂得 不高兴 生气 汗 黑线 哭 真棒 阴险 鄙视 酷 滑稽 纳尼 疑问 委屈 惊讶 勉强

评论信息框
可使用QQ号实时获取头像自动填写

私密评论

吃奶的力气提交吐槽中...


竟然没有人吐槽,快赶紧抢沙发吧!