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
+2 -2
View File
@@ -235,7 +235,7 @@ format_datetime_for_display (GDateTime *date,
{
case -7 ... -2:
/* Translators: %A is the weekday name (e.g. Sunday, Monday, etc) */
formatted_date = g_date_time_format (local_dt, _("Last %A"));
formatted_date = g_date_time_format (local_dt, gcal_util_translate_time_string (_("Last %A")));
break;
case -1:
@@ -252,7 +252,7 @@ format_datetime_for_display (GDateTime *date,
case 2 ... 7:
/* Translators: %A is the weekday name (e.g. Sunday, Monday, etc) */
formatted_date = g_date_time_format (local_dt, _("This %A"));
formatted_date = g_date_time_format (local_dt, gcal_util_translate_time_string (_("This %A")));
break;
default:
+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__ */