Created
May 4, 2022 21:33
-
-
Save dridk/1c93e4147183ad39149d5f72e25d1050 to your computer and use it in GitHub Desktop.
Use espanso to translate text with deepl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- regex: ":tr\"(?P<text>.*)\"" | |
replace: "{{translate}}" | |
vars: | |
- name: translate | |
type: shell | |
params: | |
cmd: "python ~/translate.py \"{{text}}\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import deepl | |
auth_key = "xxxxxxxxx" | |
translator = deepl.Translator(auth_key) | |
def translate(word): | |
result = translator.translate_text(word, target_lang="EN-GB", source_lang="fr") | |
return result.text | |
if __name__ == "__main__": | |
print(translate(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment