前言:2022年10月1日,谷歌翻译彻底退出中国市场,这意味着谷歌翻译在国内无法使用,下面介绍三种方法解决这个问题。

第一种方法 修改host文件

  • 按win+r输入CMD,调出命令行

  • 输入命令

1
nslookup google.cn

会得到以下类似的信息:

1
2
3
4
5
服务器:dns1.tpgi.com.au
Address:203.12.160.35
非权威应答:
名称:google.cn
Addresses:142.250.70.195

复制最后一行的ip地址,后面会用到

  • 找到host文件

host文件地址:”C:\Windows\System32\drivers\etc\hosts”

  • 选中这个文件,右键用记事本打开,文件末尾输入一行代码,保存退出。
1
142.250.70.195 translate.googleapis.com

IP地址换成上面自己生成的

第二种方法 bat代码

第一种方法的ip地址是固定,一旦被GFW墙了就不能用了,需要手动修改。第二种方法可以全自动处理选择可用的IP。

bat代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
:: Copyright (c)2022 https://bookfere.com
:: 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:
:: https://bookfere.com/post/1020.html

@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

代码源地址: GitHub Gist,把代码保存为bat文件,最后用管理员身份运行即可。

第三种方法 科学上网或者第三方插件

第三方翻译插件:deepl翻译,有道词典划词翻译插件

原创地址