Skip to content

Commit

Permalink
remove not avail message
Browse files Browse the repository at this point in the history
  • Loading branch information
yinan-c committed May 31, 2023
1 parent 4661aa4 commit 49c173e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
13 changes: 4 additions & 9 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<key>createdby</key>
<string>Yinan Chen</string>
<key>description</key>
<string>Translate with Alfred using multiple services</string>
<string>Translate using multiple services</string>
<key>disabled</key>
<false/>
<key>name</key>
Expand Down Expand Up @@ -774,13 +774,10 @@ Translate text with multiple services. This workflow also support [Universal Act
### Setup and usage
- target language code, method of translation and your APIs.
(Please check [DeepL API docs](https://www.deepl.com/docs-api/translate-text) and [Translators library](https://github.com/UlionTse/translators) for supported language codes)
- Type anything followed by keyword trans, ⏎ to translate
- Type anything after keyword trans to translate, it will auto-detect source language.-
- Then select any result and ⏎ to copy text to your clipboard
- ⌘ + ⏎ to view large text (useful if results are long)
NOTE: OpenAI model 'text-davinci-003' is used in translation. Some tranlation services (e.g. OpenAI, youdao) may be slow and delay the output.
If delay is a big issue, test the speed of each translation service and choose which ones to disable.</string>
- For universal control, simple select any text and search for translate.</string>
<key>uidata</key>
<dict>
<key>1834A62D-302E-4218-A23B-DE9C30B48023</key>
Expand Down Expand Up @@ -1090,10 +1087,8 @@ If delay is a big issue, test the speed of each translation service and choose w
<string>youdao_check</string>
</dict>
</array>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.1</string>
<string>1.2</string>
<key>webaddress</key>
<string>https://github.com/yinan-c/alfred-translate-it</string>
</dict>
Expand Down
31 changes: 10 additions & 21 deletions translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_query() -> str:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages = [
{"role": "system", "content" : f"You are a translation expert proficient in various languages that can only translate text into {target_language}. Translate any thing I say from now on, do not engage a conversion with me, you can only return the translated text."},
{"role": "system", "content" : "You are a translation expert proficient in various languages that can only translate text into {target_language}. Translate any thing I say from now on, do not engage a conversion with me, you can only return the translated text."},
{"role": "user", "content" : f"{input_text}"}
])
#prompt_text = f"You are a translation expert proficient in various languages that can only translate text and cannot interpret it. You can only return the translated text. Please translate the following text to {target_language}: {input_text}"
Expand Down Expand Up @@ -82,27 +82,16 @@ def get_query() -> str:

def translation_output(check, translator_name, icon_path, ts, input_text, target_language, json_output):
if check == '1':
try:
translated_text = ts.translate_text(input_text, to_language=target_language, translator=translator_name)
output = {
"type": "default",
"subtitle": translator_name.capitalize(),
"title": translated_text,
"arg": translated_text,
'icon': {
'path': icon_path
}
}
except:
output = {
"type": "default",
"subtitle": translator_name.capitalize(),
"title": f"{translator_name.capitalize()} is not available at the moment",
"arg": "",
'icon': {
'path': icon_path
}
translated_text = ts.translate_text(input_text, to_language=target_language, translator=translator_name)
output = {
"type": "default",
"subtitle": translator_name.capitalize(),
"title": translated_text,
"arg": translated_text,
'icon': {
'path': icon_path
}
}
json_output["items"].append(output)
return json_output

Expand Down

0 comments on commit 49c173e

Please sign in to comment.