From 49c173e7d24c051284c082e6a750cfa046c6aa23 Mon Sep 17 00:00:00 2001 From: Yinan <95043151+yinan-c@users.noreply.github.com> Date: Wed, 31 May 2023 15:42:48 +0100 Subject: [PATCH] remove not avail message --- info.plist | 13 ++++--------- translate.py | 31 ++++++++++--------------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/info.plist b/info.plist index 3af72b3..ba7c7e8 100644 --- a/info.plist +++ b/info.plist @@ -150,7 +150,7 @@ createdby Yinan Chen description - Translate with Alfred using multiple services + Translate using multiple services disabled name @@ -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. +- For universal control, simple select any text and search for translate. uidata 1834A62D-302E-4218-A23B-DE9C30B48023 @@ -1090,10 +1087,8 @@ If delay is a big issue, test the speed of each translation service and choose w youdao_check - variablesdontexport - version - 1.1 + 1.2 webaddress https://github.com/yinan-c/alfred-translate-it diff --git a/translate.py b/translate.py index 894818d..9a8459f 100644 --- a/translate.py +++ b/translate.py @@ -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}" @@ -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