Merge pull request #292 from cobacdavid/weather-languages

[weather-widget] enable locale
This commit is contained in:
streetturtle 2021-08-03 15:29:14 -04:00 committed by GitHub
commit a83ba6ff78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 13 deletions

View File

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

View File

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

View File

@ -17,14 +17,25 @@ local HOME_DIR = os.getenv("HOME")
local WIDGET_DIR = HOME_DIR .. '/.config/awesome/awesome-wm-widgets/weather-widget' 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 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) local function show_warning(message)
naughty.notify { naughty.notify {
preset = naughty.config.presets.critical, preset = naughty.config.presets.critical,
title = 'Weather Widget', title = LCLE.warning_title,
text = message text = message
} }
end end
if SYS_LANG ~= LANG then
show_warning("Your language is not supported yet. Language set to English")
end
local weather_widget = {} local weather_widget = {}
local warning_shown = false local warning_shown = false
local tooltip = awful.tooltip { local tooltip = awful.tooltip {
@ -69,10 +80,7 @@ local icon_map = {
local function to_direction(degrees) local function to_direction(degrees)
-- Ref: https://www.campbellsci.eu/blog/convert-wind-directions -- Ref: https://www.campbellsci.eu/blog/convert-wind-directions
if degrees == nil then return "Unknown dir" end if degrees == nil then return "Unknown dir" end
local directions = { local directions = LCLE.directions
"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW",
"WSW", "W", "WNW", "NW", "NNW", "N"
}
return directions[math.floor((degrees % 360) / 22.5) + 1] return directions[math.floor((degrees % 360) / 22.5) + 1]
end end
@ -120,7 +128,7 @@ local function worker(user_args)
--- Validate required parameters --- Validate required parameters
if args.coordinates == nil or args.api_key == nil then if args.coordinates == nil or args.api_key == nil then
show_warning('Required parameters are not set: ' .. show_warning(LCLE.parameter_warning ..
(args.coordinates == nil and '<b>coordinates</b>' or '') .. (args.coordinates == nil and '<b>coordinates</b>' or '') ..
(args.api_key == nil and ', <b>api_key</b> ' or '')) (args.api_key == nil and ', <b>api_key</b> ' or ''))
return return
@ -144,7 +152,8 @@ local function worker(user_args)
'?lat=' .. coordinates[1] .. '&lon=' .. coordinates[2] .. '&appid=' .. api_key .. '?lat=' .. coordinates[1] .. '&lon=' .. coordinates[2] .. '&appid=' .. api_key ..
'&units=' .. units .. '&exclude=minutely' .. '&units=' .. units .. '&exclude=minutely' ..
(show_hourly_forecast == false and ',hourly' or '') .. (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 { weather_widget = wibox.widget {
{ {
@ -256,12 +265,12 @@ local function worker(user_args)
ICONS_DIR .. icon_map[weather.weather[1].icon] .. icons_extension) 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('temp')[1]:set_text(gen_temperature_str(weather.temp, '%.0f', false, units))
self:get_children_by_id('feels_like_temp')[1]:set_text( 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('description')[1]:set_text(weather.weather[1].description)
self:get_children_by_id('wind')[1]:set_markup( self:get_children_by_id('wind')[1]:set_markup(
'Wind: <b>' .. weather.wind_speed .. 'm/s (' .. to_direction(weather.wind_deg) .. ')</b>') LCLE.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('humidity')[1]:set_markup(LCLE.humidity .. '<b>' .. weather.humidity .. '%</b>')
self:get_children_by_id('uv')[1]:set_markup('UV: ' .. uvi_index_color(weather.uvi)) self:get_children_by_id('uv')[1]:set_markup(LCLE.uv .. uvi_index_color(weather.uvi))
end end
} }