gui/date-chooser: Use translated weekday abbreviations
It matches what GNOME Shell does, and makes the app more localizable. Closes: https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/1122
This commit is contained in:
@@ -28,8 +28,10 @@
|
|||||||
#include "gcal-timeline-subscriber.h"
|
#include "gcal-timeline-subscriber.h"
|
||||||
#include "gcal-view.h"
|
#include "gcal-view.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <glib/gi18n.h>
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define ROWS 6
|
#define ROWS 6
|
||||||
#define COLS 7
|
#define COLS 7
|
||||||
@@ -243,38 +245,82 @@ calendar_compute_days (GcalDateChooser *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 0 == sunday */
|
/* 0 == sunday */
|
||||||
static gchar *
|
static const char *
|
||||||
calendar_get_weekday_name (gint i)
|
calendar_get_weekday_name (gint i)
|
||||||
{
|
{
|
||||||
GDateTime *date;
|
const char *locale = g_getenv ("LC_TIME");
|
||||||
gchar *formatted_date;
|
const char *res;
|
||||||
gchar *upcased_date;
|
locale_t old_loc;
|
||||||
gchar *text;
|
locale_t loc = (locale_t) 0;
|
||||||
|
|
||||||
date = g_date_time_new_local (2015, 1, 4 + i, 1, 1, 1);
|
if (locale)
|
||||||
formatted_date = g_date_time_format (date, "%a");
|
loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
|
||||||
g_date_time_unref (date);
|
|
||||||
|
|
||||||
upcased_date = g_utf8_strup (formatted_date, -1);
|
old_loc = uselocale (loc);
|
||||||
g_free (formatted_date);
|
|
||||||
|
|
||||||
text = g_utf8_substring (upcased_date, 0, 1);
|
switch (i)
|
||||||
g_free (upcased_date);
|
{
|
||||||
|
case 0:
|
||||||
|
/* Translators: Calendar grid abbreviation for Sunday.
|
||||||
|
*
|
||||||
|
* NOTE: These grid abbreviations are always shown together
|
||||||
|
* and in order, e.g. "S M T W T F S".
|
||||||
|
*
|
||||||
|
* Please make sure these abbreviations match GNOME Shell's
|
||||||
|
* abbreviations for your language.
|
||||||
|
*/
|
||||||
|
res = C_("grid sunday", "S");
|
||||||
|
break;
|
||||||
|
|
||||||
return text;
|
case 1:
|
||||||
|
/* Translators: Calendar grid abbreviation for Monday */
|
||||||
|
res = C_("grid monday", "M");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
/* Translators: Calendar grid abbreviation for Tuesday */
|
||||||
|
res = C_("grid tuesday", "T");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
/* Translators: Calendar grid abbreviation for Wednesday */
|
||||||
|
res = C_("grid wednesday", "W");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
/* Translators: Calendar grid abbreviation for Thursday */
|
||||||
|
res = C_("grid thursday", "T");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
/* Translators: Calendar grid abbreviation for Friday */
|
||||||
|
res = C_("grid friday", "F");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
/* Translators: Calendar grid abbreviation for Saturday */
|
||||||
|
res = C_("grid saturday", "S");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
|
uselocale (old_loc);
|
||||||
|
|
||||||
|
if (loc != (locale_t) 0)
|
||||||
|
freelocale (loc);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
calendar_init_weekday_display (GcalDateChooser *self)
|
calendar_init_weekday_display (GcalDateChooser *self)
|
||||||
{
|
{
|
||||||
gint i;
|
for (gint i = 0; i < COLS; i++)
|
||||||
gchar *text;
|
|
||||||
|
|
||||||
for (i = 0; i < COLS; i++)
|
|
||||||
{
|
{
|
||||||
text = calendar_get_weekday_name ((i + self->week_start) % COLS);
|
const char *text = calendar_get_weekday_name ((i + self->week_start) % COLS);
|
||||||
gtk_label_set_label (GTK_LABEL (self->cols[i]), text);
|
gtk_label_set_label (GTK_LABEL (self->cols[i]), text);
|
||||||
g_free (text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user