Skip to content
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

Support Baidu Api Key And Switch Ali Service type #613

Merged
merged 31 commits into from
Jul 25, 2024

Conversation

choykarl
Copy link
Collaborator

@choykarl choykarl commented Jul 14, 2024

Close #484 , #617

tisfeng and others added 10 commits May 4, 2024 21:16
…eng#558)

Bumps the bundler group with 1 update in the / directory: [rexml](https://github.com/ruby/rexml).


Updates `rexml` from 3.2.6 to 3.2.8
- [Release notes](https://github.com/ruby/rexml/releases)
- [Changelog](https://github.com/ruby/rexml/blob/master/NEWS.md)
- [Commits](ruby/rexml@v3.2.6...v3.2.8)

---
updated-dependencies:
- dependency-name: rexml
  dependency-type: indirect
  dependency-group: bundler
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
# Conflicts:
#	Easydict.xcodeproj/project.pbxproj
#	Easydict/App/Easydict-Bridging-Header.h
#	Easydict/Swift/Feature/Configuration/Configuration+Defaults.swift
#	Easydict/Swift/View/SettingView/Tabs/ServiceConfigurationView/ConfigurationView/BaiduTranslate+ConfigurableService.swift
@choykarl choykarl requested review from tisfeng, phlpsong and Jerry23011 and removed request for tisfeng and phlpsong July 14, 2024 15:06
@choykarl
Copy link
Collaborator Author

百度通用翻译API接入文档
目前来看通过API翻译只有翻译功能,没有词典相关的功能。

@choykarl
Copy link
Collaborator Author

@tisfeng 加了个picker view,做了只有输入appid和key才允许选择api type的逻辑,所以没有做默认选中api type,因为没有appid和key, 默认选中api type也没有意义。

还有我对swiftui和它的观察者模式不是很熟悉,不知道我目前的写法正不正确。

@tisfeng
Copy link
Owner

tisfeng commented Jul 19, 2024

你这个整的有点复杂了,而且和单个服务(百度)绑定太死了,其实我是想添加一个通用的 Picker 组件,参考目前 OpenAI 系列的配置,用于处理这种可以同时支持官方 API 和 Web API 的服务,除了百度,还有后面的 Google,阿里翻译等。

@tisfeng
Copy link
Owner

tisfeng commented Jul 19, 2024

做了只有输入appid和key才允许选择api type的逻辑,所以没有做默认选中api type,因为没有appid和key, 默认选中api type也没有意义。

这个没必要,我希望用户知道这些服务支持官方 API(需要 API key),并且默认使用官方 API,Picker 的选中值是单独存在的,不需要判断用户是否输入了 API key,如果没有,调用对应的 API 请求时应该会报错,我们野直接报错提示就行了。

@choykarl
Copy link
Collaborator Author

okok,我还想着用户体验呢😄。
但是默认用户肯定是没有输入过key的,但是我们默认选项却是用的官方api,这样用户更新到新版百度的翻译应该全都是报错的。
如果我们就是要默认使用官方api的话,我觉得我可以判断如果没有输入key,我直接在翻译结果里提示让用户去输入或者去切换到web翻译。
因为我觉得只靠报错信息,是没发让用户知道需要去输入key或者去切换到web api的

@tisfeng
Copy link
Owner

tisfeng commented Jul 19, 2024

明白了,你说的也有道理,这里我们可以优化一下报错提示信息,如果当前是选中的是官方 API 类型,并且缺少 API ID 或者 Secret Key,我们可以提前判断并报错,报错时可以明确提示用户这一点,例如提示 “当前正使用 Web API,Secret Key 为空,请前往服务设置页,填写相关配置信息,或切换 API 类型”。

@choykarl
Copy link
Collaborator Author

@tisfeng 处理了,麻烦重新review一下

@tisfeng
Copy link
Owner

tisfeng commented Jul 20, 2024

看了一下,整体没有什么问题,但代码有些地方还是和百度绑定了,不方便扩展,后面阿里也要改成可手动选择 API 类型。

我把 #617 阿里这个修改也给你吧,你看是这次一并改了,或是后面再优化修改也行。

tisfeng and others added 4 commits July 20, 2024 23:36
- Updated localization keys and values for Baidu API configuration
- Refactored `BaiduServiceApiType` enum to `ServiceAPIType` for consistency

Signed-off-by: tisfeng <[email protected]>
@choykarl
Copy link
Collaborator Author

@tisfeng 目前key找不到给的错误文案里用的是App IDSecret Key,这个可能并不通用,每个平台的对id或者密钥的命名可能也不太一样。这个看下是否需要调整。

@choykarl choykarl changed the title Support Baidu Api Key Support Baidu Api Key And Switch Ali Service type Jul 25, 2024
@tisfeng
Copy link
Owner

tisfeng commented Jul 25, 2024

@choykarl 编译报错了,你是不是把 ServiceAPIType 这个类型删了? CI 也报错 😑

44752

@choykarl
Copy link
Collaborator Author

sorry,配置文件忘记提交了,因为本地有配置文件的变动,所以没提,忘记有新增文件了。。。

@choykarl choykarl requested a review from tisfeng July 25, 2024 14:41
@tisfeng
Copy link
Owner

tisfeng commented Jul 25, 2024

我刚已经添加过了。。

Copy link
Owner

@tisfeng tisfeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@tisfeng tisfeng merged commit 9288bae into tisfeng:dev Jul 25, 2024
5 checks passed
@choykarl choykarl deleted the baidu_key branch August 8, 2024 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants