summaryrefslogtreecommitdiff
path: root/translate-widget
diff options
context:
space:
mode:
Diffstat (limited to 'translate-widget')
-rw-r--r--translate-widget/README.MD38
-rw-r--r--translate-widget/translate.lua6
2 files changed, 6 insertions, 38 deletions
diff --git a/translate-widget/README.MD b/translate-widget/README.MD
index 498b36e..bff749f 100644
--- a/translate-widget/README.MD
+++ b/translate-widget/README.MD
@@ -13,46 +13,16 @@ This widget allows quickly translate words or phrases without opening a browser
## Installation
1. Clone repo under **~/.config/awesome/**
-1. Get an [API key](https://translate.yandex.com/developers/keys) and paste it in **secrets.lua**
-1. Require widget and secrets in **rc.lua**:
+1. Get an [API key](https://translate.yandex.com/developers/keys) and paste it in **translate.lua** as value of the `API_KEY` variable
+1. Require widget in **rc.lua**:
```lua
- local secrets = require("awesome-wm-widgets.secrets")
local translate = require("awesome-wm-widgets.translate-widget.translate")
```
-1. Create a translate prompt, just under `mypromptbox`:
+1. Add a shortcut to run translate prompt (note that we pass an API key from secrets.lua in method call):
```lua
- s.mypromptbox = awful.widget.prompt()
- s.translateprompt = awful.widget.prompt()
- ```
-
-1. Add it to the left widgets of the wibox, just after `mypromptbox`:
-
- ```lua
- -- 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,
- },
- ```
-
-1. Add a shortcut to run this prompt (note that we pass an API key from secrets.lua in method call):
-
- ```lua
- 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
- }
+ awful.key({ modkey }, "c", function() translate.show_translate_prompt() end, { description = "run translate prompt", group = "launcher" }),
```
diff --git a/translate-widget/translate.lua b/translate-widget/translate.lua
index f32f44b..3f7afa3 100644
--- a/translate-widget/translate.lua
+++ b/translate-widget/translate.lua
@@ -81,7 +81,6 @@ w:setup {
--- Main function - takes the user input and shows the widget with translation
-- @param request_string - user input (dog enfr)
local function translate(to_translate, lang)
--- local to_translate, lang = extract(request_string)
local urll = BASE_URL .. '?lang=' .. lang .. '&text=' .. urlencode(to_translate) .. '&key=' .. API_KEY
local resp_json, code = https.request(urll)
@@ -152,7 +151,7 @@ input_widget:setup {
bordet_color = '#000000'
}
-local function show_input()
+local function show_translate_prompt()
awful.placement.top(input_widget, { margins = {top = 40}})
input_widget.height = 40
input_widget.visible = true
@@ -181,6 +180,5 @@ local function show_input()
end
return {
- show_input = show_input,
- translate = translate
+ show_translate_prompt = show_translate_prompt
}