Skip to content

Commit

Permalink
update DeepL Translator
Browse files Browse the repository at this point in the history
  • Loading branch information
dofy committed Oct 11, 2024
1 parent 0084e8f commit ce0519c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ Options:
- [DeepL Translator][ext13]

> Translate selected text via DeepL App or Website.
>
> The second language option is only available in the web version of DeepL.
>
> - Clicking the translation icon will translate the selected text from the **second language** to the **system language**
> - Clicking the icon while holding the `Option` key will translate the selected text from the **system language** to the **second language**
- [Generate Password][ext14]

Expand Down
Binary file modified dist/DeepLTranslator.popclipextz
Binary file not shown.
14 changes: 7 additions & 7 deletions src/DeepLTranslator/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ options:
zh-hans: DeepL 网站
default value: app
inset: true
- identifier: sourceLanguage
- identifier: secondLanguage
label:
en: Source Language
zh-hant: 源語言
zh-hans: 源语言
en: Second Language
zh-hant: 第二語言
zh-hans: 第二语言
description:
en: 'The language of the text you want to translate. (Only works in Website mode)'
zh-hant: '您要翻譯的文本的語言。(僅在網站模式下有效)'
zh-hans: '您要翻译的文本的语言。(仅在网站模式下有效)'
en: 'You can translate the selected text from this language into the system language or from the system language into this language (held the Option key, only valid in Web mode).'
zh-hant: '您可以將選中的文本從此語言翻譯為系統語言,或從系統語言翻譯為此語言(按住 Option 鍵,僅在網站模式下有效)'
zh-hans: '您可以将选中的文本从此语言翻译为系统语言,或从系统语言翻译为此语言(按住 Option 键,仅在网站模式下有效)'
type: multiple
default value: en
values:
Expand Down
14 changes: 9 additions & 5 deletions src/DeepLTranslator/Main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
const DeepL_URL =
'https://www.deepl.com/{languageCode}/translator#{sourceLanguage}/{localLanguage}/'
'https://www.deepl.com/{languageCode}/translator#{secondLanguage}/{localLanguage}/'

const extension: Extension = {
actions: [
{
title: 'Translate',
code(
{ text },
{ runMode, sourceLanguage, defaultShortcut, customShortcut }
{ runMode, secondLanguage, defaultShortcut, customShortcut }
) {
if (runMode === 'website') {
const { languageCode, localeIdentifier } = util.localeInfo
const optionIsHeld = popclip.modifiers.option
const localLanguage =
localeIdentifier.split('_')[0].toLowerCase() || 'en'
popclip.openUrl(
`${DeepL_URL.replace('{languageCode}', languageCode)
.replace('{localLanguage}', localLanguage)
.replace(
'{sourceLanguage}',
sourceLanguage.toString() || 'en'
'{secondLanguage}',
optionIsHeld ? languageCode : (secondLanguage as string)
)
.replace(
'{localLanguage}',
optionIsHeld ? (secondLanguage as string) : localLanguage
)}${encodeURIComponent(text)}`
)
} else {
Expand Down

0 comments on commit ce0519c

Please sign in to comment.