
谷歌已調用用戶退出使用“使用率太低”的谷歌翻譯顯示服務正式中國。現在訪問谷歌翻譯主頁,是香港谷歌翻譯的頁面,點擊頁面上的鏈接會進入香港谷歌翻譯頁面。
當然,如果不使用網絡代理是無法使用的。這給日常需要使用谷歌翻譯的小伙伴帶來了不便。
下面是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
呢 稱: | |
表 情: | |
內 容: |
評論內容:不能超過 1000 字,需審核,請自覺遵守互聯網相關政策法規。 |
驗證碼: | |
您發布的評論即表示同意遵守以下條款:
一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會、集體和公民的合法權益;
二、不得發布國家法律、法規明令禁止的內容;互相尊重,對自己在本站的言論和行為負責;
三、本站對您所發布內容擁有處置權。