Delete secrets.lua as translate widget will receive it as a parameter

This commit is contained in:
Pavel Makhov 2019-11-25 10:21:05 -05:00
parent 2e67a1f37e
commit 44e9b4e14e
3 changed files with 6 additions and 21 deletions

View File

@ -1,14 +0,0 @@
-------------------------------------------------
-- Allows to store client specific settings in one place
--
-- @author Pavel Makhov
-- @copyright 2019 Pavel Makhov
--------------------------------------------
local secrets = {
-- Yandex.Translate API key - https://tech.yandex.com/translate/
translate_widget_api_key = os.getenv('AWW_TRANSLATE_API_KEY') or 'trnsl.1.1.20170708T010252Z.8b3fcacab3396ad1.88df3f48339672bce016a0e85a4db3aeb34dc7ae',
}
return secrets

View File

@ -13,7 +13,7 @@ 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** as value of the ` translate_widget_api_key` variable
1. Get an [API key](https://translate.yandex.com/developers/keys)
1. Require widget in **rc.lua**:
```lua
@ -24,7 +24,7 @@ This widget allows quickly translate words or phrases without opening a browser
```lua
awful.key({ modkey }, "c",
function() translate.show_translate_prompt() end,
function() translate.show_translate_prompt('<api-key>') end,
{ description = "run translate prompt", group = "launcher" }),
```

View File

@ -14,7 +14,6 @@ local naughty = require("naughty")
local wibox = require("wibox")
local gears = require("gears")
local gfs = require("gears.filesystem")
local secrets = require("awesome-wm-widgets.secrets")
local BASE_URL = 'https://translate.yandex.net/api/v1.5/tr.json/translate'
local ICON = '/usr/share/icons/Papirus-Dark/48x48/apps/gnome-translate.svg'
@ -87,8 +86,8 @@ 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 urll = BASE_URL .. '?lang=' .. lang .. '&text=' .. urlencode(to_translate) .. '&key=' .. secrets.translate_widget_api_key
local function translate(to_translate, lang, api_key)
local urll = BASE_URL .. '?lang=' .. lang .. '&text=' .. urlencode(to_translate) .. '&key=' .. api_key
local resp_json, code = https.request(urll)
if (code == 200 and resp_json ~= nil) then
@ -162,7 +161,7 @@ input_widget:setup {
left = 10
}
local function show_translate_prompt()
local function show_translate_prompt(api_key)
awful.placement.top(input_widget, { margins = {top = 40}, parent = awful.screen.focused()})
input_widget.height = 40
input_widget.visible = true
@ -183,7 +182,7 @@ local function show_translate_prompt()
})
return
end
translate(to_translate, lang)
translate(to_translate, lang, api_key)
end,
done_callback = function()
input_widget.visible = false