few changes

This commit is contained in:
streetturtle 2018-01-21 16:27:19 -05:00
parent 26bf019c91
commit 26d795ee79
2 changed files with 6 additions and 38 deletions

View File

@ -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" }),
```

View File

@ -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
}