fix-google-translate
修复 Chrome 浏览器翻译功能(Windows Hosts 配置)
一、现状检测
CMD 执行 nslookup google.cn 域名解析测试,当前 google.cn 已正常解析到目标 IP:
C:\Windows\System32>nslookup google.cn
服务器: UnKnown
Address: 10.10.10.252
名称: google.cn
Address: 198.18.1.118
二、手动修改 Hosts 文件
1. 打开 Hosts 文件
CMD 执行以下命令进入目录并打开文件:
cd C:\Windows\System32\drivers\etc
notepad hosts
2. Hosts 完整内容
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
198.18.1.118 translate.googleapis.com
3. 补充完整解析规则
在文件末尾追加 google.cn 映射,完善配置:
198.18.1.118 translate.googleapis.com google.cn
修改后保存文件。
三、一键自动修复脚本(推荐)
1. CMD 快速生成脚本
以管理员身份打开 CMD,执行以下命令,在桌面生成 fix-google-translate.bat 自动修复脚本:
@echo off
chcp 65001 >nul
title 谷歌翻译 Hosts 自动修复
echo 正在更新 Hosts 解析规则 ...
echo ==============================
set "hostsFile=%SystemRoot%\System32\drivers\etc\hosts"
set "rule=198.18.1.118 translate.googleapis.com google.cn"
:: 移除旧条目
findstr /v "translate.googleapis.com google.cn" "%hostsFile%" > "%temp%\hosts.tmp"
move /y "%temp%\hosts.tmp" "%hostsFile%" >nul
:: 写入新规则
echo. >> "%hostsFile%"
echo %rule% >> "%hostsFile%"
:: 刷新DNS
ipconfig /flushdns >nul
echo.
echo 操作完成!
echo 已成功写入解析规则:%rule%
echo DNS 缓存已刷新完毕。
echo.
echo ==============================
echo 按任意键退出 ...
pause >nul
2. 脚本使用方法
- 找到桌面
fix-google-translate.bat; - 右键 → 以管理员身份运行;
- 执行完成后自动刷新 DNS 缓存,立即生效。
四、验证是否生效
重新执行解析命令,域名解析为 198.18.1.118 即配置成功:
nslookup translate.googleapis.com
nslookup google.cn
五、补充说明
- 若配置反复失效,可将
hosts文件设置为只读,防止安全软件、网络工具篡改; - 脚本采用 GBK 编码,适配 Windows 控制台,无中文乱码;
- 每次网络重连、系统重启后,可重新运行脚本恢复解析。