Skip to content

Instantly share code, notes, and snippets.

@dridk
Created May 4, 2022 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dridk/1c93e4147183ad39149d5f72e25d1050 to your computer and use it in GitHub Desktop.
Save dridk/1c93e4147183ad39149d5f72e25d1050 to your computer and use it in GitHub Desktop.
Use espanso to translate text with deepl
- regex: ":tr\"(?P<text>.*)\""
replace: "{{translate}}"
vars:
- name: translate
type: shell
params:
cmd: "python ~/translate.py \"{{text}}\""
#!/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