-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Ali translate service #271
Conversation
野生的网页 API 可能不稳定,有时候接口会变动,或者有频次限制等,DeepL 是没办法,获取官方 API key 太难了。 对于这种有官方 API,且提供一定免费额度的接口,建议还是优先用官方的 API,这样更稳定可靠。
|
if let data = response.data { | ||
do { | ||
let errorResponse = try JSONDecoder().decode(TencentErrorResponse.self, from: data) | ||
ezError?.errorDataMessage = errorResponse.response.error.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
阿里翻译,怎么会用到腾讯翻译的模型 TencentErrorResponse
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个报错类型如果未知,干脆包一层抛给 EZError,直接显示原始的报错信息。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦,我忘记了,Alamofire 和 AFNetworking 的错误类型不同,AFError 没有带 userInfo 信息,因此 Swift 这边如果不自己解析错误信息,就需要把 response.data
传过去。
let ezError = EZError(nsError: error, errorResponseData: response.data)
sorry,这次弄的有点仓促了,我明天改下。 |
没事,这个网页接口也不用删,可以放着。 |
优化了一下,让阿里翻译各种语言都支持了繁体中文。 对于一些不支持繁体中文的服务,例如 DeepL,此时只要将繁体中文视为简体中文 <traditionalChinese: "zh">,然后让 autoConvertTraditionalChinese 返回 YES,就能自动支持繁体中文了。 至于原理,简单来说,就是内部我们自己手动将简体中文转为繁体中文。 具体可以看这个提交 94cf2e0 override public func autoConvertTraditionalChinese() -> Bool {
true
} |
|
GitGuardian id | Secret | Commit | Filename | |
---|---|---|---|---|
- | Generic High Entropy Secret | bcd5bd2 | Easydict/Feature/Service/Ali/AliResponse.swift | View secret |
- | Generic High Entropy Secret | 29e2763 | Easydict/Feature/Service/Ali/AliResponse.swift | View secret |
- | Alibaba Cloud Keys | 50c01b9 | Easydict/Feature/Service/Ali/AliService.swift | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Our GitHub checks need improvements? Share your feedbacks!
发现一个很奇怪的事情,有些中文翻译会报错,例如“生死难料”这个词在阿里翻译里会直接报错,网页上翻页也会报错。 |
这个GitGuardian错误应该是我注释里面有个token,但是我现在删掉也不行,也检查不过去。。。 |
GitGuardian 这个主要是提醒作用,如果是一些隐私的 key 之类的,revoke 掉就好。 如果要去掉这个警告,可能需要你本地重写一下提交历史,把 token 相关的去掉,然后强推。 |
我没看懂,你这个修改,好像只添加了一个 _csrf 参数,之前的 get 接口有什么问题? |
另外,其实我是希望你能添加阿里翻译的官方 API |
这个post是我抓的网页翻译的接口,之前get是我看bob的插件写的,但是我没看到那个get在哪里有用,可能是网页之前用的是get现在换成了post了吧。所以我两个都保留了,算是做一个兜底。 |
额,我看那个api是需要收费的啊😳 |
我们这是开源的软件,用个人账号的api key授权不会有问题么,而且我看api调用好像QPS还限制了50。 |
额,有什么问题? 参考目前已添加的腾讯翻译,大体上我们只负责接入官方 API,至于需要 API key,这个让用户自己去申请就好了。 但为了新用户方便使用,我们可以内置一个有免费额度限制的 API key,这个通常用的是我自己额外注册申请的一个账号下的 key。比如腾讯翻译每月有 500 万免费额度,我在程序内简单限制了一下每个新用户的使用额度。另外如果这个月 500 万免费额度用完了,也同样不能使用了,会报错提示。 具体你可以看一下腾讯翻译的代码。 |
啊,我理解错了,我以为是要内置一个apikey给所有人用呢。 |
可以,那这个下周再上也行。 |
周末准备发布一个新版本,这个如果还没做完,那就放到下一个版本吧。 |
昨晚写了,代码还没提呢,中午提一下 |
# Conflicts: # Easydict/App/Easydict-Bridging-Header.h
@choykarl 还有什么问题吗,如果没问题了,需要解决所有的 Resolve conversation,不然 PR 流程会卡住。 另外有新的 commit 后,需要重新 Re-request review |
close #65