Pony of Shadows

Queen of Truth & King of Practice


Translation Solution on Wayland

Introduction

Today I read an inspiring solution on Reddit

@kupiqu I will not address your question directly but I will give you a “solution” that at least for me works even better: One possibility [Not Okular specific] is to use a klipper action on top of trans (https://github.com/soimort/translate-shell/tree/develop) and notify-send (to display the result as a system notification).

This has the advantage that can be triggered anywhere (not only, but) also from Okular, and define a word or translate a sentence to any language (or even display multiple language translations at once). My two actions for this are the following (translation to English/Catalan/Spanish from whatever language your selection is):

notify-send “definition: %s” “$(trans -e google -no-ansi -d %s)”

notify-send “translation: %s” “$(trans -e google -no-ansi -t en+ca+es -b %s)”

These are by far the klipper actions I use the most, I have no statistics but I think it would be hard to find a past day on which I didn’t use them at least once.

According to this below tools is needed:

  • trans a translator
  • sway a window manager to bind hotkey with translation action.
  • wl-clipboard clipboard manager for sway
  • mako notification manager for sway

config of sway

# startup
exec_always --no-startup-id mako --max-history 5

(why --max-history doesn’t work?)

# translator
bindsym $mod+x exec bash -c 'translated=$(wl-paste | trans -b :zh); notify-send "[Trans]" "$translated"; echo -n "$translated" | wl-copy'
bindsym $mod+Shift+x exec bash -c 'translated=$(wl-paste | trans -b :en); notify-send "[Trans]" "$translated"; echo -n "$translated" | wl-copy'