谷歌已调用用户退出使用“使用率太低”的谷歌翻译显示服务正式中国。现在访问谷歌翻译主页,是香港谷歌翻译的页面,点击页面上的链接会进入香港谷歌翻译页面。
当然,如果不使用网络代理是无法使用的。这给日常需要使用谷歌翻译的小伙伴带来了不便。
下面是IP地址以及修改windows系统主机文件的自动化脚本代码,只需一键即可完成所有步骤。
脚本在GitHub Gist上,你也可以通过下面的链接直接下载到本地使用。
把代码保存为bat'文件,最后以管理员身份运行脚本自动完成!
:: Copyright (c)2022
:: This is a batch script for fixing Google Translate and making it available
:: in the Chinese mainland. If you experience any problem, visit the page below:
@echo off
setlocal enabledelayedexpansion
chcp 437 >NULL
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 "old_rule=null"
set "new_rule=%ip% %target_domain%"
set "comment=# Fix Google Translate CN"
for /f "tokens=*" %%i in ('type %hosts_file%') do (
set "line=%%i"
:: Retrieve the rule If the target domain exists.
if not "!line:%target_domain%=!"=="%%i" set "old_rule=%%i"
)
if not "%old_rule%"=="null" (
echo A rule has been added to the hosts file.
echo [1] Update [2] Delete
set /p action="Enter a number to choose an action: "
if "!action!"=="1" (
if not "%old_rule%"=="%new_rule%" (
echo Deleting the rule "%old_rule%"
echo Adding the rule "%new_rule%"
set "new_line=false"
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%"
if "!new_line!"=="true" >>%hosts_file% echo.
>>%hosts_file% <NUL set /p="!rule!"
set "new_line=true"
)
) else (
echo The rule already exists, nothing to do.
)
)
if "!action!"=="2" (
echo Deleting the rule "%old_rule%"
set "new_line=false"
for /f "tokens=*" %%i in ('
type "%hosts_file%" ^| findstr /v /c:"%comment%" ^| findstr /v "%target_domain%" ^| find /v /n "" ^& break ^> "%hosts_file%"
') do (
set "line=%%i"
set "line=!line:*]=!"
if "!new_line!"=="true" >>%hosts_file% echo.
>>%hosts_file% <NUL set /p="!line!"
set "new_line=true"
)
)
) else (
echo Adding the rule "%new_rule%"
echo.>>%hosts_file%
echo %comment%>>%hosts_file%
<NUL set /p="%new_rule%">>%hosts_file%
)
echo Done.
pause