谷歌翻译为何退出中国?被迫的还是主动的?该如何恢复 Chrome 翻译功能? | 零度解说

谷歌翻译退出中国后该如何恢复 Chrome 翻译的正常使用?

 

 

下面是获取可用 IP 地址以及修改 Windows 系统和 macOS 系统 hosts 文件的自动化脚本代码:

只需一键即可完成所有修改步骤。

脚本托管在 GitHub Gist 上,你也可以通过以下链接直接下载到本地使用。

把代码保存为bat’文件,最后以管理员身份运行脚本即可完成!

:: 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

 

如果你用的是 macOS 系统

 

打开“终端”,拷贝以下命令并将其粘贴到终端上,按回车,输入你的系统密码,再按回车。注意,输入密码时是不显示任何信息的,只要确保输入的密码是正确的就可以。

 

sudo bash -c "$(curl -skL https://fere.link/ow3cld)"

如果看到如下所示提示,表示规则添加成功,也就可以正常使用 Chrome 的谷歌翻译功能了。

Adding the rule "142.250.70.195 translate.googleapis.com"
Done.

* 提示:终端打开的方式为,打开“访达(Finder)”,在左侧边栏找到并进入“应用程序(Applications)”文件夹,在里面找到并进入“实用工具(Utilities)”文件夹,在这里面就可以找到“终端(Terminal)”,双击打开。

​* 注意:​由于代码是托管在 GitHub 的,因此在请求 URL 的时候可能会遇到网络不通畅的情况,如果运行命令后长时间没反应,建议按 Ctrl + C 中止运行,​然后再重新运行一遍上面的命令,一般最多尝试两三次。

此命令可以重复使用。添加规则后再次使用时会出现交互提示信息,输入 1 会尝试更新已添加规则的 IP 地址,如果没有变化则不做任何修改,输入 2 会删除已添加的规则。

 

Github 开源项目地址:https://gist.github.com/bookfere

 

THE END
喜欢就支持一下吧
点赞2251 分享
相关推荐
Chrome OS安装教程,笔记本/台式机都可以,保证成功!-零度博客

Chrome OS安装教程,笔记本/台式机都可以,保证成功!

Ubuntu Mate 镜像下载:https://ubuntu-mate.org/download/ Rufus写盘工具:https://rufus.ie/ Chrome 安装框架下载:https://github.com/sebanc/brunch/releases Chrome OS 恢复镜像下载:http...
Windows 11 升级文件资源管理器的现代 UI 设计-零度博客

Windows 11 升级文件资源管理器的现代 UI 设计

据报道,微软正在对文件资源管理器进行重大更新,该更新将深度集成 OneDrive 和 Microsoft 365 据报道,微软正在对 Windows 11 中的文件资源管理器进行重大更新,以改进其用户界面和功能。Windo...
admin的头像-零度博客admin
1.3W+6539
6个超有意思的网站!你一定会喜欢的....| 零度解说-零度博客
Windows 7 免费升级到 Windows 10 / 11(最简单的方法)100% 激活!亲测有效 | 零度解说-零度博客

Windows 7 免费升级到 Windows 10 / 11(最简单的方法)100% 激活!亲测有效 | 零度解说

https://www.youtube.com/watch?v=9rB3uIMJyA0 Windows 10/11 官方免费下载:https://www.freedidi.com/19154.html
最新可用的【免费域名】注册教程!无需实名验证,不需要信用卡-零度博客

最新可用的【免费域名】注册教程!无需实名验证,不需要信用卡

  1.免费注册域名:【链接直达】 2.免费容器:【点击打开】 3.VPS 推荐:【链接直达】 4.一键安装网站服务器环境,有2种简单方案: a). lnmp wget http://soft.vpser.net/lnmp/lnmp2.0.ta...
admin的头像-零度博客admin
1.9W+1684
狗狗币最新挖矿教程!附挖矿软件,新手也能快速上手! 2024-零度博客

狗狗币最新挖矿教程!附挖矿软件,新手也能快速上手! 2024

自从特朗普成功竞选以后,各路加密货币应声上涨!作为深受马斯克影响的狗狗币突然又火了,价格暴涨。当然不仅仅狗狗币,其它任何加密货币也一样,比特币也在一周内涨了5000多美金,当然比特币普...
admin的头像-零度博客admin
7.7W+5783
adb命令的文件安装包-零度博客

adb命令的文件安装包

    adb命令文件安装包:platform-tools_r31.0.3-windows
admin的头像-零度博客admin
1.1W+652
OpenAI 再次震撼世界!推出全新 Sora 技术, 简直是AI视频的颠覆性革命!我们离实现AGI更近了.... | 零度解说-零度博客

OpenAI 再次震撼世界!推出全新 Sora 技术, 简直是AI视频的颠覆性革命!我们离实现AGI更近了…. | 零度解说

https://youtu.be/7rB0lPvtXuo?si=hqKtcc6EAcnbA_El =============== OpenAI Sora 体验入口:https://www.freedidi.com/11604.html
admin的头像-零度博客admin
1.3W+1527
我们的童年记忆为何如此高度相似?70后、80后、90后 看完就知道为啥了!-零度博客