[evolution-data-server] Replace e_cal_recur_nth array with e_cal_recur_get_localized_nth()



commit 99ba5aa57c1d5dbec570f229d0ba1a0591515d37
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jan 29 18:14:13 2018 +0100

    Replace e_cal_recur_nth array with e_cal_recur_get_localized_nth()
    
    The usage of e_cal_recur_nth array could properly work only if either
    the user of it used g_dgettext() with "evolution-data-server" domain,
    or the domain in use was the "evolution-data-server" (for bare _()),
    or the domain in use had translations for the items in the array, which
    makes the translation here too complicated. The new function always
    translates in the correct translation domain, thus avoids all the above
    issues and also allows to check for array boundary.

 src/calendar/libecal/e-cal-recur.c |   22 ++++++++++++++++++++++
 src/calendar/libecal/e-cal-recur.h |    6 ++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/calendar/libecal/e-cal-recur.c b/src/calendar/libecal/e-cal-recur.c
index 691496c..35892df 100644
--- a/src/calendar/libecal/e-cal-recur.c
+++ b/src/calendar/libecal/e-cal-recur.c
@@ -4737,6 +4737,8 @@ static
  *
  * An array of 31 translated strings for each day of the month (i.e. "1st",
  * "2nd", and so on).
+ *
+ * Deprecated: 3.28: Use e_cal_recur_get_localized_nth() instead
  */
 const gchar *e_cal_recur_nth[31] = {
        N_("1st"),
@@ -4781,6 +4783,8 @@ const gchar *e_cal_recur_nth[31] = {
  * (i.e. "1st", "2nd", and so on).
  *
  * Returns: a pointer to an array of strings.  This array is static, do not free it.
+ *
+ * Deprecated: 3.28: Use e_cal_recur_get_localized_nth() instead
  */
 const gchar **
 e_cal_get_recur_nth (void)
@@ -4789,3 +4793,21 @@ e_cal_get_recur_nth (void)
 }
 
 #endif
+
+/**
+ * e_cal_recur_get_localized_nth:
+ * @nth: the nth index, counting from zero
+ *
+ * Returns: Localized text for the nth position, counting from zero, which means
+ *    for '0' it'll return "1st", for '1' it'll return "2nd" and so on, up to 30,
+ *    when it'll return "31st".
+ *
+ * Since: 3.28
+ **/
+const gchar *
+e_cal_recur_get_localized_nth (gint nth)
+{
+       g_return_val_if_fail (nth >= 0 && nth < G_N_ELEMENTS (e_cal_recur_nth), NULL);
+
+       return _(e_cal_recur_nth[nth]);
+}
diff --git a/src/calendar/libecal/e-cal-recur.h b/src/calendar/libecal/e-cal-recur.h
index 9d87562..0798829 100644
--- a/src/calendar/libecal/e-cal-recur.h
+++ b/src/calendar/libecal/e-cal-recur.h
@@ -86,6 +86,8 @@ e_cal_recur_ensure_end_dates (ECalComponent   *comp,
                            ECalRecurResolveTimezoneFn  tz_cb,
                            gpointer             tz_cb_data);
 
+#ifndef EDS_DISABLE_DEPRECATED
+
 /* Localized nth-day-of-month strings. (Use with _() ) */
 #ifdef G_OS_WIN32
 extern const gchar **e_cal_get_recur_nth (void);
@@ -94,6 +96,10 @@ extern const gchar **e_cal_get_recur_nth (void);
 extern const gchar *e_cal_recur_nth[31];
 #endif
 
+#endif /* EDS_DISABLE_DEPRECATED */
+
+const gchar *          e_cal_recur_get_localized_nth           (gint nth);
+
 G_END_DECLS
 
 #endif


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