awesome-wm-widgets/translate-widget/README.MD

2.0 KiB

Translate Widget

This widget allows quickly translate words or phrases without opening a browser - just using Awesome. To provide direction of the translation add the 2 letters code of the source and target languages at the end of the phrase, for example hello enfr will translate hello from English to French. This widget is based on Yandex.Translate API.

demo

Controls

  • Mod4 + c - opens a translate prompt;
  • left click on the popup widget - copies the translation to the clipboard and closes widget;
  • right click on the popup widget - copies text to translate to the clipboard and closes widget.

Installation

  1. Get an API key and paste it secrets.lua

  2. Require widget and secrets in rc.lua:

    local secrets = require("awesome-wm-widgets.secrets")
    local translate = require("awesome-wm-widgets.translate-widget.translate")
    
  3. Create a translate prompt (just under mypromptbox):

    s.mypromptbox = awful.widget.prompt()
    s.translateprompt = awful.widget.prompt()
    
  4. Add it to the left widgets of the wibox, just after mypromptbox:

    -- Add widgets to the wibox
    s.mywibox:setup {
        layout = wibox.layout.align.horizontal,
        { -- Left widgets
            layout = wibox.layout.fixed.horizontal,
            mylauncher,
            s.mytaglist,
            s.mypromptbox,
            s.translateprompt,
        },
    
  5. Add a shortcut to run this prompt (note that we pass an API key from secrets.lua in method call):

    awful.key({ modkey }, "c", function()
            awful.prompt.run {
                prompt = "trnslt: ",
                textbox = awful.screen.focused().translateprompt.widget,
                exe_callback = function(text)
                    translate.translate(text, secrets.translate_widget_api_key)
                end
            }