1、概述
上个月,Google宣布停止在中国的翻译服务器,虽然对其他人来说没有啥影响,但是对于程序员来说,真的影响太大了,尤其是英语水平太差的。然后我到处找方法,也在百度上搜索了很多方法,都失效了,昨晚去B站看了一下,找到一个up主更新的教程,本人今天亲测有效,更新时间是
2022-11-05 09:17,也不知道能管多久,废话不多说,直接上干货。
2、解决办法
在windows本地新建一个名字叫 "谷歌翻译.bat" 的脚本,名字随意,然后输入下面的内容到脚本里面,双击运行即可。
@setlocal enabledelayedexpansion
@echo off
set "source_domain=google.cn"
set "target_domain=translate.googleapis.com"
set "hosts_file=C:\Windows\System32\drivers\etc\hosts"
::for /f "skip=4 tokens=2" %%a in ('"nslookup %source_domain% 2>NUL"') do set ip=%%a
set "ip=172.253.124.90"
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%
)
@ipconfig /flushdns
@echo "Ð޸Ĺȸè·ÒëºÍË¢ÐÂdnsÍê³É£¬Çë¹Ø±Õ£¡"
echo Done.
pause
文本里面的乱码不用管它,拷贝粘贴到你的脚本里面,双击运行即可。
双击运行:
查看效果: