[libgweather/wip/cdavis/windspeed-string] gweather-weather: Add function to turn a speed unit to string




commit 271dd026802e6bb7d1c2886bc12b51af375fe5d6
Author: Christopher Davis <brainblasted disroot org>
Date:   Wed Nov 25 19:14:40 2020 -0800

    gweather-weather: Add function to turn a speed unit to string

 libgweather/gweather-weather.c | 31 +++++++++++++++++++++++++++++++
 libgweather/gweather-weather.h |  3 +++
 2 files changed, 34 insertions(+)
---
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
index 5f9230c9..5702542d 100644
--- a/libgweather/gweather-weather.c
+++ b/libgweather/gweather-weather.c
@@ -1159,6 +1159,37 @@ gweather_info_get_wind (GWeatherInfo *info)
     }
 }
 
+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 g_strdup(_("knots"));
+    case GWEATHER_SPEED_UNIT_MPH:
+       /* TRANSLATOR: This is the wind speed in miles per hour */
+       return g_strdup(_("mph"));
+    case GWEATHER_SPEED_UNIT_KPH:
+       /* TRANSLATOR: This is the wind speed in kilometers per hour */
+       return g_strdup(_("km/h"));
+    case GWEATHER_SPEED_UNIT_MS:
+       /* TRANSLATOR: This is the wind speed in meters per second */
+       return g_strdup(_("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 g_strdup(_("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 1a800d06..b397c696 100644
--- a/libgweather/gweather-weather.h
+++ b/libgweather/gweather-weather.h
@@ -418,6 +418,9 @@ const gchar * gweather_conditions_to_string_full (GWeatherConditions *conditions
 GWEATHER_EXTERN
 GWeatherTemperatureUnit gweather_temperature_unit_to_real (GWeatherTemperatureUnit unit);
 
+GWEATHER_EXTERN
+const gchar * gweather_speed_unit_to_string (GWeatherSpeedUnit unit);
+
 G_END_DECLS
 
 #endif /* __WEATHER_H_ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]