event-editor/schedule-section: Fix localization mix

The gcal_util_translate_time_string function is a plain copy of
gnome-shells shell_util_translate_time_string solving the same problem.

Fixes: https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/581
This commit is contained in:
Björn Daase
2022-02-12 17:43:49 +01:00
parent 02343e6b37
commit ad7ff65a4d
3 changed files with 39 additions and 2 deletions
+35
View File
@@ -1325,3 +1325,38 @@ gcal_utils_ask_recurrence_modification_type (GtkWidget *parent,
gtk_window_present (GTK_WINDOW (dialog));
}
/**
* gcal_util_translate_time_string:
* @str: String to translate
*
* Translate @str according to the locale defined by LC_TIME; unlike
* dcgettext(), the translations is still taken from the LC_MESSAGES
* catalogue and not the LC_TIME one.
*
* Returns: the translated string
*/
const gchar *
gcal_util_translate_time_string (const gchar *str)
{
const gchar *locale = g_getenv ("LC_TIME");
const gchar *res;
gchar *sep;
locale_t old_loc;
locale_t loc = (locale_t) 0;
if (locale)
loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
old_loc = uselocale (loc);
sep = strchr (str, '\004');
res = g_dpgettext (NULL, str, sep ? sep - str + 1 : 0);
uselocale (old_loc);
if (loc != (locale_t) 0)
freelocale (loc);
return res;
}
+2
View File
@@ -135,4 +135,6 @@ void gcal_utils_ask_recurrence_modification_type (GtkWidget
GcalAskRecurrenceCallback callback,
gpointer user_data);
const gchar * gcal_util_translate_time_string (const gchar *str);
#endif /* __GCAL_UTILS_H__ */