解决Google翻译不能使用的问题

1、概述

上个月,Google宣布停止在中国的翻译服务器,虽然对其他人来说没有啥影响,但是对于程序员来说,真的影响太大了,尤其是英语水平太差的。然后我到处找方法,也在百度上搜索了很多方法,都失效了,昨晚去B站看了一下,找到一个up主更新的教程,本人今天亲测有效,更新时间是

2022-11-05 09:17,也不知道能管多久,废话不多说,直接上干货。

2、解决办法

在windows本地新建一个名字叫 "谷歌翻译.bat" 的脚本,名字随意,然后输入下面的内容到脚本里面,双击运行即可。

@setlocal enabledelayedexpansion
@echo off

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 "ip=172.253.124.90"
set "old_rule=null"
set "new_rule=%ip% %target_domain%"

for /f "tokens=*" %%i in ('type %hosts_file%') do (
    set "line=%%i"
    :: Retrieve the rule If the target domain has been exists in the line.
    if not "!line:%target_domain%=!"=="%%i" set "old_rule=%%i"
)

if not "%old_rule%"=="null" (
    if not "%old_rule%"=="%new_rule%" (
        echo Deleting the rule "%old_rule%"
        echo Adding the rule "%new_rule%"
        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%"
            >>%hosts_file% echo(!rule!
        )
    ) else (
        echo The rule already exists, nothing to do.
    )
) else (
    echo Adding the rule "%new_rule%"
    echo.>>%hosts_file%
    echo.>>%hosts_file%
    echo # Fix Google Translate CN>>%hosts_file%
    echo %new_rule%>>%hosts_file%
)

@ipconfig /flushdns
@echo   "Ð޸Ĺȸ跭ÒëºÍË¢ÐÂdnsÍê³É£¬Çë¹Ø±Õ£¡"
echo Done.
pause

文本里面的乱码不用管它,拷贝粘贴到你的脚本里面,双击运行即可。

双击运行:

查看效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

国服TB第一人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值