diff options
author | Christopher Davis <brainblasted@disroot.org> | 2020-11-25 19:14:40 -0800 |
---|---|---|
committer | Christopher Davis <brainblasted@disroot.org> | 2021-02-10 10:48:54 -0800 |
commit | 18be3e5a2dc579ee6ebcaf34b7be1197f3f101a2 (patch) | |
tree | eb3002c538055aeda9ec173ee8cd09891e43fc2d | |
parent | 0f78e9d4d76e5e2fbef2c1a50aea628fd7ea45d8 (diff) | |
download | libgweather-18be3e5a2dc579ee6ebcaf34b7be1197f3f101a2.tar.gz |
gweather-weather: Add function to turn a speed unit to string
-rw-r--r-- | doc/libgweather-sections.txt | 1 | ||||
-rw-r--r-- | libgweather/gweather-weather.c | 37 | ||||
-rw-r--r-- | libgweather/gweather-weather.h | 2 |
3 files changed, 40 insertions, 0 deletions
diff --git a/doc/libgweather-sections.txt b/doc/libgweather-sections.txt index faa8421..f9589d8 100644 --- a/doc/libgweather-sections.txt +++ b/doc/libgweather-sections.txt @@ -161,6 +161,7 @@ GWeatherMoonPhase GWeatherDistanceUnit GWeatherPressureUnit GWeatherSpeedUnit +gweather_speed_unit_to_string GWeatherTemperatureUnit <SUBSECTION> diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c index 0d7b1f1..17711ac 100644 --- a/libgweather/gweather-weather.c +++ b/libgweather/gweather-weather.c @@ -1135,6 +1135,43 @@ gweather_info_get_wind (GWeatherInfo *info) } } +/** + * gweather_speed_unit_to_string: + * @unit: a speed unit, or %GWEATHER_SPEED_UNIT_DEFAULT + * + * Creates a human-readable, localized representation of @unit + */ +const gchar * +gweather_speed_unit_to_string (GWeatherSpeedUnit unit) +{ + unit = speed_unit_to_real (unit); + + switch (unit) { + case GWEATHER_SPEED_UNIT_KNOTS: + /* TRANSLATOR: This is the wind speed in knots */ + return _("knots"); + case GWEATHER_SPEED_UNIT_MPH: + /* TRANSLATOR: This is the wind speed in miles per hour */ + return _("mph"); + case GWEATHER_SPEED_UNIT_KPH: + /* TRANSLATOR: This is the wind speed in kilometers per hour */ + return _("km/h"); + case GWEATHER_SPEED_UNIT_MS: + /* TRANSLATOR: This is the wind speed in meters per second */ + return _("m/s"); + case GWEATHER_SPEED_UNIT_BFT: + /* TRANSLATOR: This is the wind speed as a Beaufort force factor + * (commonly used in nautical wind estimation). + */ + return _("Beaufort force"); + case GWEATHER_SPEED_UNIT_INVALID: + case GWEATHER_SPEED_UNIT_DEFAULT: + g_assert_not_reached (); + } + + return NULL; +} + static GWeatherPressureUnit pressure_unit_to_real (GWeatherPressureUnit unit) { diff --git a/libgweather/gweather-weather.h b/libgweather/gweather-weather.h index 00134c2..3df30de 100644 --- a/libgweather/gweather-weather.h +++ b/libgweather/gweather-weather.h @@ -345,6 +345,8 @@ const gchar * gweather_conditions_to_string_full (GWeatherConditions *conditions GWeatherTemperatureUnit gweather_temperature_unit_to_real (GWeatherTemperatureUnit unit); +const gchar * gweather_speed_unit_to_string (GWeatherSpeedUnit unit); + G_END_DECLS #endif /* __WEATHER_H_ */ |