summaryrefslogtreecommitdiff
path: root/weather-widget
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@users.noreply.github.com>2021-08-03 15:29:14 -0400
committerGitHub <noreply@github.com>2021-08-03 15:29:14 -0400
commita83ba6ff78987414c7480f04e9ec294a2b54e7ef (patch)
tree7efa8e096d3e7b1778b109d5444b6aee23c12171 /weather-widget
parentbabb4254dbf350fb170dd3ee5b981bbf8732715c (diff)
parentc505ae70cc6d6844c88cc78cd4263128bcda5521 (diff)
Merge pull request #292 from cobacdavid/weather-languages
[weather-widget] enable locale
Diffstat (limited to 'weather-widget')
-rw-r--r--weather-widget/locale/en.lua14
-rw-r--r--weather-widget/locale/fr.lua14
-rw-r--r--weather-widget/weather.lua35
3 files changed, 50 insertions, 13 deletions
diff --git a/weather-widget/locale/en.lua b/weather-widget/locale/en.lua
new file mode 100644
index 0000000..377dc6f
--- /dev/null
+++ b/weather-widget/locale/en.lua
@@ -0,0 +1,14 @@
+local en = {
+ warning_title = "Weather Widget",
+ parameter_warning = "Required parameters are not set: ",
+ directions = {
+ "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW",
+ "WSW", "W", "WNW", "NW", "NNW", "N"
+ },
+ feels_like = "Feels like ",
+ wind = "Wind: ",
+ humidity = "Humidity: ",
+ uv = "UV: "
+}
+
+return en
diff --git a/weather-widget/locale/fr.lua b/weather-widget/locale/fr.lua
new file mode 100644
index 0000000..de50814
--- /dev/null
+++ b/weather-widget/locale/fr.lua
@@ -0,0 +1,14 @@
+local fr = {
+ warning_title = "Widget Météo",
+ parameter_warning = "Les paramètres suivants sont obligatoires : ",
+ directions = {
+ "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSO", "SO",
+ "OSO", "O", "ONO", "NO", "NNO", "N"
+ },
+ feels_like = "ressentie à ",
+ wind = "Vent : ",
+ humidity = "Humidité : ",
+ uv = "Indice UV : "
+}
+
+return fr
diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua
index 1847fd4..9daabf1 100644
--- a/weather-widget/weather.lua
+++ b/weather-widget/weather.lua
@@ -17,14 +17,25 @@ local HOME_DIR = os.getenv("HOME")
local WIDGET_DIR = HOME_DIR .. '/.config/awesome/awesome-wm-widgets/weather-widget'
local GET_FORECAST_CMD = [[bash -c "curl -s --show-error -X GET '%s'"]]
+local SYS_LANG = os.getenv("LANG"):sub(1, 2)
+-- default language is ENglish
+local LANG = gears.filesystem.file_readable(WIDGET_DIR .. "/" .. "locale/" ..
+ SYS_LANG .. ".lua") and SYS_LANG or "en"
+local LCLE = require("awesome-wm-widgets.weather-widget.locale." .. LANG)
+
+
local function show_warning(message)
naughty.notify {
preset = naughty.config.presets.critical,
- title = 'Weather Widget',
+ title = LCLE.warning_title,
text = message
}
end
+if SYS_LANG ~= LANG then
+ show_warning("Your language is not supported yet. Language set to English")
+end
+
local weather_widget = {}
local warning_shown = false
local tooltip = awful.tooltip {
@@ -69,10 +80,7 @@ local icon_map = {
local function to_direction(degrees)
-- Ref: https://www.campbellsci.eu/blog/convert-wind-directions
if degrees == nil then return "Unknown dir" end
- local directions = {
- "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW",
- "WSW", "W", "WNW", "NW", "NNW", "N"
- }
+ local directions = LCLE.directions
return directions[math.floor((degrees % 360) / 22.5) + 1]
end
@@ -120,9 +128,9 @@ local function worker(user_args)
--- Validate required parameters
if args.coordinates == nil or args.api_key == nil then
- show_warning('Required parameters are not set: ' ..
- (args.coordinates == nil and '<b>coordinates</b>' or '') ..
- (args.api_key == nil and ', <b>api_key</b> ' or ''))
+ show_warning(LCLE.parameter_warning ..
+ (args.coordinates == nil and '<b>coordinates</b>' or '') ..
+ (args.api_key == nil and ', <b>api_key</b> ' or ''))
return
end
@@ -144,7 +152,8 @@ local function worker(user_args)
'?lat=' .. coordinates[1] .. '&lon=' .. coordinates[2] .. '&appid=' .. api_key ..
'&units=' .. units .. '&exclude=minutely' ..
(show_hourly_forecast == false and ',hourly' or '') ..
- (show_daily_forecast == false and ',daily' or ''))
+ (show_daily_forecast == false and ',daily' or '') ..
+ '&lang=' .. LANG)
weather_widget = wibox.widget {
{
@@ -256,12 +265,12 @@ local function worker(user_args)
ICONS_DIR .. icon_map[weather.weather[1].icon] .. icons_extension)
self:get_children_by_id('temp')[1]:set_text(gen_temperature_str(weather.temp, '%.0f', false, units))
self:get_children_by_id('feels_like_temp')[1]:set_text(
- 'Feels like ' .. gen_temperature_str(weather.feels_like, '%.0f', false, units))
+ LCLE.feels_like .. gen_temperature_str(weather.feels_like, '%.0f', false, units))
self:get_children_by_id('description')[1]:set_text(weather.weather[1].description)
self:get_children_by_id('wind')[1]:set_markup(
- 'Wind: <b>' .. weather.wind_speed .. 'm/s (' .. to_direction(weather.wind_deg) .. ')</b>')
- self:get_children_by_id('humidity')[1]:set_markup('Humidity: <b>' .. weather.humidity .. '%</b>')
- self:get_children_by_id('uv')[1]:set_markup('UV: ' .. uvi_index_color(weather.uvi))
+ LCLE.wind .. '<b>' .. weather.wind_speed .. 'm/s (' .. to_direction(weather.wind_deg) .. ')</b>')
+ self:get_children_by_id('humidity')[1]:set_markup(LCLE.humidity .. '<b>' .. weather.humidity .. '%</b>')
+ self:get_children_by_id('uv')[1]:set_markup(LCLE.uv .. uvi_index_color(weather.uvi))
end
}