Skip to content

Commit

Permalink
update: youdao free api is no longer supported
Browse files Browse the repository at this point in the history
  • Loading branch information
wo52616111 committed Oct 22, 2023
1 parent 6fe8c4f commit 1d21886
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CapsLock+.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Menu, Tray, Icon,,, 1

SetStoreCapslockMode, Off

global CLversion:="Version: 3.2.0.0 | 2020-10-24`n`nCopyright Junkai Chen"
global CLversion:="Version: 3.3.0.0 | 2023-10-22`n`nCopyright Junkai Chen"

global cClipboardAll ;capslock+ clipboard
global caClipboardAll ;capslock+alt clipboard
Expand Down
32 changes: 18 additions & 14 deletions language/English.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ global lang_yd_errorNoFunds:="Insufficient account balance"
global lang_yd_trans:= "------------------------------ Youdao Translation -----------------------------"
global lang_yd_dict:= "------------------------------ Youdao dictionary ------------------------------"
global lang_yd_phrase:= "----------------------------------- Phrase ------------------------------------"
global lang_yd_free_key_unavailable_warning:="Youdao Translate no longer provides free translation API, now you can only use the paid API (new accounts have a trial amount), please refer to the instructions in the [TTranslate] section of the CapsLock+settingsDemo.ini file to set up the key and use the translation function."

global lang_settingsFileContent:=""
lang_settingsFileContent=
Expand Down Expand Up @@ -282,24 +283,27 @@ progressColor=0x00cc99
[TTranslate]
; About Youdao API
; The translation function is implemented by calling Youdao API.
; The request frequency of the API is limited to 1000 times per hour, In other words, all the people who are using
; Capslock+ translation can not translate more than 1000 times in one hour.
; Youdao API website: http://fanyi.youdao.com/openapi
; paid version website: https://ai.youdao.com/console/#/

; The key of Youdao API. Leave blank to use the built-in key, shared by all users.
apiKey=0123456789
; Youdao's paid version API website: https://ai.youdao.com/console/#/
; Getting started docs about Youdao's API: https://ai.youdao.com/doc.s#guide

; API key type, 0 is the free version, 1 is the paid version. The free version of the key can be applied through the
; above URL.
apiType=0
; Translation API type, currently can only be 1
; 0: Free version of Youdao API (no longer available, no longer provided by Youdao)
; 1: Paid version of Youdao API (default value)
apiType=1

; The "keyfrom" parameter of the API key
keyFrom=xxx
; Parameters for paid version Youdao application

; The key of paid Youdao API.
appPaidID=0123456789
appPaidKey=0123456789
; Application ID
appPaidID=xxx

; Application key
appPaidKey=xxx

; Capslock+ could use either the free version or the paid version of the Yodao API before, to provide translation functions, now Yodao no longer provides the free version of the API,
; only the paid version of the API can be used. The following parameters related to the free version of the API have been deprecated, please delete them if they are used in your settings file.
; apiKey=xxx
; keyFrom=xxx


;----------------------------------------------------------------;
Expand Down
28 changes: 16 additions & 12 deletions language/Simplified_Chinese.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ global lang_yd_errorNoFunds:="帐户余额不足"
global lang_yd_trans:="------------------------------------有道翻译------------------------------------"
global lang_yd_dict:="------------------------------------有道词典------------------------------------"
global lang_yd_phrase:="--------------------------------------短语--------------------------------------"
global lang_yd_free_key_unavailable_warning:="有道翻译已经不再提供免费的翻译 API,现在只能使用收费 API(新账号有试用额度),请参考 CapsLock+settingsDemo.ini 文件中 [TTranslate] 部分的说明设置密钥后使用翻译功能。"

global lang_settingsFileContent:=""
lang_settingsFileContent=
Expand Down Expand Up @@ -257,24 +258,27 @@ progressColor=0x00cc99
[TTranslate]
;有道api接口
;翻译功能通过调用有道的api实现。
;接口的请求频率限制为每小时1000次,超过限制会被封禁。也就是说所有使用Capslock+翻译的人一小时内翻译的次数加起来不能超过1000次。
;有道api网址:http://fanyi.youdao.com/openapi

;收费版api申请网址: https://ai.youdao.com/console/#/
;有道翻译 API 入门指南: https://ai.youdao.com/doc.s#guide

;有道api的key,如果自己申请到key,可以填入,这样就不用和其他人共用api接口,留空则使用自带的key,所有人共用
;注意如果是免费版的key,apiType也要相应设置为0,收费版的填写1
apiKey=0123456789
;翻译 API 类型,目前只能为 1
;0: 免费版有道 API(已不可使用,有道翻译不再提供)
;1: 收费版有道 API(默认值)
apiType=1

;接口类型,0为免费版,1为收费版。通过上面的网址申请的是免费版的,收费版是需要 email 他们来申请的。
apiType=0
;收费版申请的参数

;免费版的有道 api key 的 keyfrom 参数,申请 api 时要求填写的。收费版的不需要填写。
keyFrom=xxx
;应用ID
appPaidID=xxx

;收费版申请的key
appPaidID=0123456789
appPaidKey=0123456789
;应用密钥
appPaidKey=xxx

;曾经 Capslock+ 可以选择使用免费版或收费版的有道 API 来提供翻译功能,现在有道已经不再提供免费版 API,
;只能使用收费版的 API,以下与免费版 API 相关的参数已经废弃,如果你的设置文件中有使用,请删除掉。
;apiKey=xxx
;keyFrom=xxx

;----------------------------------------------------------------;

Expand Down
21 changes: 12 additions & 9 deletions lib/lib_ydTrans.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ youdaoApiKey0=12763084
global appID=""
global appKey=""

; 收费版改版
; free key
if(CLSets.TTranslate.apiType=1)
; 收费版 API
if (CLSets.TTranslate.appPaidID != "" && CLSets.TTranslate.appPaidID != "")
{
if (CLSets.TTranslate.appPaidID != "" && CLSets.TTranslate.appPaidID != "")
{
appID:=CLSets.TTranslate.appPaidID
appKey:=CLSets.TTranslate.appPaidKey
}
appID:=CLSets.TTranslate.appPaidID
appKey:=CLSets.TTranslate.appPaidKey
youdaoApiString=http://openapi.youdao.com/api?signType=v3&from=auto&to=auto&appKey=%appID%
}
else
Expand All @@ -48,6 +44,11 @@ return

ydTranslate(ss)
{
if(CLSets.TTranslate.apiType = 0 || CLSets.TTranslate.appPaidID = "")
{
MsgBox, %lang_yd_free_key_unavailable_warning%
return
}
transStart:
; if(StrLen(ss) >= 2000)
; {
Expand Down Expand Up @@ -112,7 +113,9 @@ if(youdaoApiString="")
goto, setTransText
}

if (CLSets.TTranslate.apiType=1) {
; 目前 apiType 只可能为 1,暂时保留对 apiType 的判断结构,以防以后需要添加其他 api 类型的支持
; youdao api docs: https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html
if (true || CLSets.TTranslate.apiType=1) {
; salt sign curtime
; sign=sha256(应用ID+input+salt+curtime+应用密钥)
myNow := A_NowUTC
Expand Down

0 comments on commit 1d21886

Please sign in to comment.