diff options
| author | venomade <venomade@venomade.com> | 2026-02-11 11:42:58 +0000 |
|---|---|---|
| committer | venomade <venomade@venomade.com> | 2026-02-11 11:42:58 +0000 |
| commit | 0bd150185551b6d8835d022c15a5f6e832d51113 (patch) | |
| tree | 10bf3f3443df49a44eb47b328b73b7e76b0a4924 /.local/bin/rofi-translate | |
| parent | 8d688d1107c46b6dfdcaf02fa5c9c4c8a4640e65 (diff) | |
Asahi
Soft reset of dotfiles specific to Asahi, Sway and Neovim.
Diffstat (limited to '.local/bin/rofi-translate')
| -rwxr-xr-x | .local/bin/rofi-translate | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/.local/bin/rofi-translate b/.local/bin/rofi-translate new file mode 100755 index 0000000..f71557d --- /dev/null +++ b/.local/bin/rofi-translate @@ -0,0 +1,60 @@ +#!/usr/bin/env lua + +local function rofi(prompt, lines) + local cmd = string.format( + 'printf "%s" | rofi -dmenu -i -p "%s"', + table.concat(lines, "\n"), + prompt + ) + local handle = io.popen(cmd) + local selection = handle:read("*a") + handle:close() + selection = selection:gsub("%s+$", "") + if selection == "" then return nil end + return selection +end + +local function contains(tbl, val) + for _, v in pairs(tbl) do + if v == val then + return true + end + end + return false +end + +local directions = { + "English → Portuguese", + "Portuguese → English" +} + +local choice = rofi("Translate:", directions) +if (not choice) or (not contains(directions,choice)) then os.exit() end + +local lang_pair = { + ["English → Portuguese"] = "en:pt", + ["Portuguese → English"] = "pt:en" +} +local pair = lang_pair[choice] + +local text = rofi("", { "" }) +if not text then os.exit() end + +local trans_cmd = string.format('trans -b %s "%s"', pair, text:gsub('"', '\\"')) +local trans_handle = io.popen(trans_cmd) +local translation = trans_handle:read("*a") +trans_handle:close() +translation = translation:gsub("%s+$", "") + +if translation == "" then + translation = "(no translation returned)" +else + io.popen("wl-copy " .. translation) +end + +local notify_cmd = string.format( + 'notify-send -- "Translation (%s)" "%s"', + choice, + translation:gsub('"', '\\"') +) +os.execute(notify_cmd) |
