Skip to content

Commit

Permalink
Merge branch 'dev' into add_setting_icon_to_shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
phlpsong authored Feb 25, 2024
2 parents 9946f2a + 4e7fbbb commit f1e65bd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Easydict/NewApp/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SwiftUI
enum EasydictCmpatibilityEntry {
static func main() {
parseArmguments()
if NewAppManager.shared.enable {
if #available(macOS 13, *), NewAppManager.shared.enable {
EasydictApp.main()
} else {
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
Expand Down
36 changes: 23 additions & 13 deletions Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,29 @@ private struct ServiceItems: View {
}
}

private class ServiceItemViewModel: ObservableObject {
@Published var isEnable = false

init(isEnable: Bool) {
self.isEnable = isEnable
}
}

@available(macOS 13.0, *)
private struct ServiceItemView: View {
let service: QueryService

@EnvironmentObject private var viewModel: ServiceTabViewModel

private var enabled: Binding<Bool> {
.init {
service.enabled
} set: { newValue in
guard service.enabled != newValue else { return }
service.enabled = newValue
if newValue {
service.enabledQuery = newValue
}
EZLocalStorage.shared().setService(service, windowType: viewModel.windowType)
viewModel.postUpdateServiceNotification()
}
@ObservedObject private var serviceItemViewModel: ServiceItemViewModel

init(service: QueryService) {
self.service = service
serviceItemViewModel = ServiceItemViewModel(isEnable: service.enabled)
}

var body: some View {
Toggle(isOn: enabled) {
Toggle(isOn: $serviceItemViewModel.isEnable) {
HStack {
Image(service.serviceType().rawValue)
.resizable()
Expand All @@ -153,6 +154,15 @@ private struct ServiceItemView: View {
.fixedSize()
}
}
.onReceive(serviceItemViewModel.$isEnable) { newValue in
guard service.enabled != newValue else { return }
service.enabled = newValue
if newValue {
service.enabledQuery = newValue
}
EZLocalStorage.shared().setService(service, windowType: viewModel.windowType)
viewModel.postUpdateServiceNotification()
}
.padding(4.0)
.toggleStyle(.switch)
.controlSize(.small)
Expand Down
57 changes: 20 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

## Easydict

`Easydict` 是一个简洁易用的词典翻译 macOS App,能够轻松优雅地查找单词或翻译文本。Easydict 开箱即用,能自动识别输入文本语言,支持输入翻译,划词翻译和 OCR 截图翻译,可同时查询多个翻译服务结果,目前支持 [有道词典](https://www.youdao.com/)[**🍎 苹果系统词典**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md)[🍎 **苹果系统翻译**](./docs/How-to-use-macOS-system-translation-in-Easydict-zh.md)[OpenAI (ChatGPT)](https://chat.openai.com/)[DeepL](https://www.deepl.com/translator)[Google](https://translate.google.com)[腾讯](https://fanyi.qq.com/)[Bing](https://www.bing.com/translator)[百度](https://fanyi.baidu.com/)[小牛翻译](https://niutrans.com/)[彩云小译](https://fanyi.caiyunapp.com/)[阿里翻译](https://translate.alibaba.com/)[火山翻译](https://translate.volcengine.com/translate)
`Easydict` 是一个简洁易用的词典翻译 macOS App,能够轻松优雅地查找单词或翻译文本。Easydict 开箱即用,能自动识别输入文本语言,支持输入翻译,划词翻译和 OCR 截图翻译,可同时查询多个翻译服务结果,目前支持 [有道词典](https://www.youdao.com/)[**🍎 苹果系统词典**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md)[🍎 **苹果系统翻译**](./docs/How-to-use-macOS-system-translation-in-Easydict-zh.md)[OpenAI (ChatGPT)](https://chat.openai.com/)[Gemini](https://gemini.google.com/)[DeepL](https://www.deepl.com/translator)[Google](https://translate.google.com)[腾讯](https://fanyi.qq.com/)[Bing](https://www.bing.com/translator)[百度](https://fanyi.baidu.com/)[小牛翻译](https://niutrans.com/)[彩云小译](https://fanyi.caiyunapp.com/)[阿里翻译](https://translate.alibaba.com/)[火山翻译](https://translate.volcengine.com/translate)

![Log](https://raw.githubusercontent.com/tisfeng/ImageBed/main/uPic/Log-1688378715.png)

Expand All @@ -42,7 +42,7 @@
- [x] 支持系统 TTS,支持 Bing,Google,有道和百度在线 TTS 服务。
- [x] 支持 [🍎 苹果系统词典](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md),支持第三方词典,可手动导入 mdict 词典。
- [x] 支持 macOS 系统翻译。详情请看 [如何在 Easydict 中使用 🍎 macOS 系统翻译?](./docs/How-to-use-macOS-system-translation-in-Easydict-zh.md)
- [x] 支持有道词典,OpenAI (ChatGPT),DeepL,Google,Bing,腾讯,百度,小牛,彩云,阿里和火山翻译。
- [x] 支持有道词典,OpenAI (ChatGPT),Gemini,DeepL,Google,Bing,腾讯,百度,小牛,彩云,阿里和火山翻译。
- [x] 支持 48 种语言。

**如果觉得这个应用还不错,给个 [Star](https://github.com/tisfeng/Easydict) ⭐️ 支持一下吧 (^-^)**
Expand All @@ -64,7 +64,6 @@
- [2. Homebrew 安装](#2-homebrew-安装)
- [开发者构建](#开发者构建)
- [构建环境](#构建环境)
- [签名问题 ⚠️](#签名问题-️)
- [使用](#使用)
- [鼠标划词](#鼠标划词)
- [关于权限](#关于权限)
Expand All @@ -74,10 +73,11 @@
- [查询服务](#查询服务)
- [🍎 苹果系统词典](#-苹果系统词典)
- [OpenAI(ChatGPT)翻译](#openaichatgpt翻译)
- [使用内置 Gemini key](#使用内置-gemini-key)
- [使用内置 APIKey](#使用内置-apikey)
- [配置个人的 APIKey](#配置个人的-apikey)
- [OpenAI 查询模式](#openai-查询模式)
- [OpenAI 自定义参数](#openai-自定义参数)
- [Gemini 翻译](#gemini-翻译)
- [DeepL 翻译](#deepl-翻译)
- [配置 AuthKey](#配置-authkey)
- [自定义 DeepL 接口地址](#自定义-deepl-接口地址)
Expand Down Expand Up @@ -160,36 +160,6 @@ Xcode 13+, macOS Big Sur 11.3+。为避免不必要的问题,建议使用最

</details>

### 签名问题 ⚠️

Easydict 是开源软件,本身是安全的,但由于苹果严格的检查机制,打开时可能会遇到警告拦截。

常见问题

1. 如果遇到下面 [无法打开 Easydict 问题](https://github.com/tisfeng/Easydict/issues/2),请参考苹果使用手册 [打开来自身份不明开发者的 Mac App](https://support.apple.com/zh-cn/guide/mac-help/mh40616/mac)

> 无法打开“Easydict.dmg”,因为它来自身份不明的开发者。
<div>
<img src="https://user-images.githubusercontent.com/25194972/219873635-46e9d318-7237-462b-be69-44ad7a3ea760.png" width="30%">
<img src="https://user-images.githubusercontent.com/25194972/219873670-7ce67946-87c2-4d45-84fd-3cc59936f7be.png" width="30%">
<img src="https://user-images.githubusercontent.com/25194972/219873722-2e780565-fe26-4ce3-9648-f1cbdd393843.png" width="30%">
</div>

<div style="display: flex; justify-content: space-between;">
<img src="https://user-images.githubusercontent.com/25194972/219873809-2b407852-7f77-4aef-9206-3f6393cb7c31.png" width="100%" />
</div>

2. 如果提示应用已损坏,请参考 [macOS 绕过公证和应用签名方法](https://www.5v13.com/sz/31695.html)

> “Easydict”已损坏,无法打开。
在终端里输入以下命令,并输入密码即可。

```bash
sudo xattr -rd com.apple.quarantine /Applications/Easydict.app
```

---

## 使用
Expand Down Expand Up @@ -350,11 +320,16 @@ Easydict 自动支持词典 App 中系统自带的词典,如牛津英汉汉英

例如 [one-api](https://github.com/songquanpeng/one-api),one-api 是一个很好的 OpenAI 接口管理开源项目,支持多家 LLM 接口,包括 Azure、Anthropic Claude、Google PaLM 2 & Gemini、智谱 ChatGLM、百度文心一言、讯飞星火认知、阿里通义千问、360 智脑以及腾讯混元等,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用。

目前 GUI 方式配置 API key 功能还在开发中 [[#227](https://github.com/tisfeng/Easydict/issues/227)],暂时需要在 Easydict 的输入框中使用命令方式配置。
[2.6.0](https://github.com/tisfeng/Easydict/releases) 版本实现了新的 SwiftUI 设置页(支持 macOS 13+),支持 GUI 方式配置服务 API key,其他则需要在 Easydict 的输入框中使用命令方式配置。

> [!NOTE]
> 如果电脑硬件支持的话,建议升级到最新的 macOS 系统,以享受更好的用户体验。
![](https://github.com/tisfeng/Easydict/assets/25194972/5b8f2785-b0ee-4a9e-bd41-1a9dd56b0231)

#### 使用内置 Gemini key
#### 使用内置 APIKey

目前 Google 的 Gemini API 免费,实测下来翻译效果不错,由于项目对 Gemini 支持 [#270](https://github.com/tisfeng/Easydict/issues/270) 还在开发中,可能需要一点时间,因此我内置了一个 key,方便用户直接使用 Gemini 模型来翻译。但请注意,这个 key 有一定使用限制且不稳定,因此如果有能力部署 one-api,建议优先使用自己的 APIKey。
目前 Google 的 Gemini API 免费,实测下来翻译效果不错,为方便用户使用,我内置了一个 key。但请注意,这个 key 有一定使用限制且不稳定,因此如果有能力部署 one-api,建议优先使用自己的 APIKey。

在 Beta 模式下,并且没有设置自己的 APIKey,这样就会自动使用内置的 Gemini key。

Expand Down Expand Up @@ -425,6 +400,14 @@ easydict://writeKeyValue?EZOpenAIModelKey=xxx

由于 OpenAI 官方接口对用户 IP 有限制,因此如果你需要反向代理,可以参考这个反代项目 [cloudflare-reverse-proxy](https://github.com/gaboolic/cloudflare-reverse-proxy)

### Gemini 翻译

[Gemini 翻译](https://gemini.google.com/) 需要 API key,可在官网[控制台](https://makersuite.google.com/app/apikey)免费获取。

```bash
easydict://writeKeyValue?EZGeminiAPIKey=xxx
```

### DeepL 翻译

DeepL 免费版网页 API 对用户单个 IP 有频率限制,频繁使用会触发 429 too many requests 报错,因此 1.3.0 版本增加了对 DeepL 官方 API 的支持,暂时还没写界面,需通过命令方式启用。
Expand Down
57 changes: 20 additions & 37 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

## Easydict

`Easydict` is a concise and easy-to-use translation dictionary macOS App that allows you to easily and elegantly look up words or translate text. Easydict is ready to use out of the box, can automatically recognize the language of the input text, supports input translate, select translate, and OCR screenshot translate, and can query multiple translation services results at the same time. Currently, it supports [Youdao Dictionary](https://www.youdao.com/), [**🍎 Apple System Dictionary**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-en.md), [**🍎 macOS System Translation**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md), [OpenAI(ChatGPT)](https://chat.openai.com/), [DeepL](https://www.deepl.com/translator), [Google](https://translate.google.com/), [Tencent](https://fanyi.qq.com/), [Bing](https://www.bing.com/translator), [Baidu](https://fanyi.baidu.com/), [Niutrans](https://niutrans.com/), [Lingocloud](https://fanyi.caiyunapp.com/#/), [Ali Translate](https://translate.alibaba.com/) and [Volcano Translation](https://translate.volcengine.com/translate).
`Easydict` is a concise and easy-to-use translation dictionary macOS App that allows you to easily and elegantly look up words or translate text. Easydict is ready to use out of the box, can automatically recognize the language of the input text, supports input translate, select translate, and OCR screenshot translate, and can query multiple translation services results at the same time. Currently, it supports [Youdao Dictionary](https://www.youdao.com/), [**🍎 Apple System Dictionary**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-en.md), [**🍎 macOS System Translation**](./docs/How-to-use-macOS-system-dictionary-in-Easydict-zh.md), [OpenAI(ChatGPT)](https://chat.openai.com/), [Gemini](https://gemini.google.com/), [DeepL](https://www.deepl.com/translator), [Google](https://translate.google.com/), [Tencent](https://fanyi.qq.com/), [Bing](https://www.bing.com/translator), [Baidu](https://fanyi.baidu.com/), [Niutrans](https://niutrans.com/), [Lingocloud](https://fanyi.caiyunapp.com/#/), [Ali Translate](https://translate.alibaba.com/) and [Volcano Translation](https://translate.volcengine.com/translate).

![Log](https://raw.githubusercontent.com/tisfeng/ImageBed/main/uPic/Log-1688378715.png)

Expand All @@ -41,7 +41,7 @@
- [x] Support system TTS, along with online services from Bing, Google, Youdao and Baidu Cloud.
- [x] Support [🍎 Apple System Dictionary](./docs/How-to-use-macOS-system-dictionary-in-Easydict-en.md), support third-party dictionaries with manual mdict dictionaries import functionalities.
- [x] Support macOS system translation. (_Please see [How to use 🍎 macOS system translation in Easydict?](./docs/How-to-use-macOS-system-dictionary-in-Easydict-en.md)_)
- [x] Support Youdao Dictionary, DeepL, OpenAI (ChatGPT), Google, Tencent, Bing, Baidu, Niutrans, Lingocloud, Ali and Volcano Translate.
- [x] Support Youdao Dictionary, DeepL, OpenAI (ChatGPT), Gemini, Google, Tencent, Bing, Baidu, Niutrans, Lingocloud, Ali and Volcano Translate.
- [x] Support for 48 languages.

**If you like this app, please consider giving it a [Star](https://github.com/tisfeng/Easydict) ⭐️, thanks! (^-^)**
Expand All @@ -63,7 +63,6 @@ We plan to refactor the project with Swift. If you are interested in this open s
- [2. Homebrew](#2-homebrew)
- [Developer Build](#developer-build)
- [Build Environment](#build-environment)
- [Signature Problem ⚠️](#signature-problem-️)
- [Usage](#usage)
- [Select text by Mouse](#select-text-by-mouse)
- [About Permissions](#about-permissions)
Expand All @@ -73,10 +72,11 @@ We plan to refactor the project with Swift. If you are interested in this open s
- [Translation Services](#translation-services)
- [🍎 Apple System Dictionary](#-apple-system-dictionary)
- [OpenAI (ChatGPT) Translation](#openai-chatgpt-translation)
- [Use the built-in Gemini key](#use-the-built-in-gemini-key)
- [Using the built-in APIKey](#using-the-built-in-apikey)
- [Configure Personal APIKey](#configure-personal-apikey)
- [OpenAI Query Mode](#openai-query-mode)
- [OpenAI Custom Settings](#openai-custom-settings)
- [Gemini Translate](#gemini-translate)
- [DeepL Translate](#deepl-translate)
- [Configure AuthKey](#configure-authkey)
- [Configure API endpoint](#configure-api-endpoint)
Expand Down Expand Up @@ -159,36 +159,6 @@ If the run encounters the following error, try updating CocoaPods and then `pod

</details>

### Signature Problem ⚠️

Easydict is open source software and is inherently secure, but due to Apple's strict checking mechanism, you may encounter warning blocks when opening it.

FAQ:

1. If you encounter the following [Cannot open Easydict problem](https://github.com/tisfeng/Easydict/issues/2), please refer to [Open Mac App from an unidentified developer](https://support.apple.com/en-us/guide/mac-help/mh40616/mac)

> Cannot open "Easydict.dmg" because Apple cannot check to see if it contains malware.
<div >
<img src="https://github.com/Jerry23011/Easydict/assets/89069957/5ecb4cc7-53e7-45c6-8606-df36cf4adb73" width="30%">
<img src="https://github.com/Jerry23011/Easydict/assets/89069957/7c44e542-62f3-458a-abbb-6ae555b743d7" width="30%">
<img src="https://github.com/Jerry23011/Easydict/assets/89069957/060f4927-8df5-4bfd-9283-363cc8d3fa52" width="30%">
</div>

<div style="display: flex; justify-content: space-between;">
<img src="https://github.com/Jerry23011/Easydict/assets/89069957/eb2852c1-6ffd-4575-8bb0-5c97d451d582" width="100%" />
</div>

2. If it indicates that the app is corrupted, please refer to [macOS Bypassing Notary and App Signing Methods](https://www.5v13.com/sz/31695.html)

> "Easydict" is corrupted and cannot be opened.
Just type the following command in the terminal and enter the password.

```bash
sudo xattr -rd com.apple.quarantine /Applications/Easydict.app
```

---

## Usage
Expand Down Expand Up @@ -348,11 +318,16 @@ If you don't have your own OpenAI APIKey, you can use some open source projects

For example, [one-api](https://github.com/songquanpeng/one-api), one-api is a good open source project for OpenAI interface management, which supports multiple LLM interfaces, including Azure, Anthropic Claude, Google PaLM 2 & Gemini, Zhupu ChatGLM, Baidu Wenxin Yiyu, Xunfei Xinghuo cognition, Ali Tongyi Qianwen, 360 Zhinao and Tencent Hunyuan, etc., which can be used for secondary distribution management key, only single executable file, Docker image has been packaged, one-click deployment, out of the box.

Currently, the GUI method of configuring API key is still under development [#227](https://github.com/tisfeng/Easydict/issues/227), so you need to configure it in the input box of Easydict in command mode for the time being.
The [2.6.0](https://github.com/tisfeng/Easydict/releases) version implements a new SwiftUI settings page (macOS 13+ support), which supports configuring the service API key in a GUI way, other system verions need to be configured using commands in Easydict's input box.

> [!NOTE]
> If your computer hardware supports it, it is recommended to upgrade to the latest macOS system to enjoy a better user experience.
![](https://github.com/tisfeng/Easydict/assets/25194972/5b8f2785-b0ee-4a9e-bd41-1a9dd56b0231)

#### Use the built-in Gemini key
#### Using the built-in APIKey

Currently, Google's Gemini API is free, and the translation effect is good. Since the project's support for Gemini [#270](https://github.com/tisfeng/Easydict/issues/270), it may take some time, so I have built in a key to facilitate users to use the Gemini model directly for translation. However, please note that this key has certain usage restrictions and is unstable, so if you have the ability to deploy one-api, it is recommended to use your own APIKey first.
Currently Google's Gemini API is free, the translation effect is good, in order to facilitate the use of users, I built-in a key, but please note that the use of this key has some limitations and is not stable, so if you have the ability to deploy one-api, it is recommended to prioritize the use of their own APIKey.

In Beta mode, and no APIKey is set, so the built-in Gemini key will be used automatically.

Expand Down Expand Up @@ -423,6 +398,14 @@ easydict://writeKeyValue?EZOpenAIModelKey=xxx

Since the official OpenAI interface has restrictions on user IPs, if you need a reverse proxy, you can refer to this project [cloudflare-reverse-proxy](https://github.com/gaboolic/cloudflare-reverse-proxy)

### Gemini Translate ##

[Gemini Translation](https://gemini.google.com/) requires an API key, which can be obtained for free on the official website [Console](https://makersuite.google.com/app/apikey).

```bash
easydict://writeKeyValue?EZGeminiAPIKey=xxx
```

### DeepL Translate

DeepL free version web API has a frequency limit for single IP, frequent use will trigger 429 too many requests error, so version 1.3.0 adds support for DeepL official API, but the interface has not been written yet, and needs to be enabled through command.
Expand Down

0 comments on commit f1e65bd

Please sign in to comment.