Use nl_langinfo() for month and day names

Use the locale setting to fetch the month names and abbreviated day
names.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2017-08-27 10:23:36 +02:00 committed by Lukas Fleischer
parent fad4a5f4e0
commit 26aeddd490
3 changed files with 8 additions and 35 deletions

View File

@ -742,7 +742,6 @@ long ui_calendar_end_of_year(void);
const char *ui_calendar_get_pom(time_t); const char *ui_calendar_get_pom(time_t);
/* config.c */ /* config.c */
void config_load(void); void config_load(void);
unsigned config_save(void); unsigned config_save(void);
@ -1176,8 +1175,6 @@ extern int quiet;
extern int want_reload; extern int want_reload;
extern const char *datefmt_str[DATE_FORMATS]; extern const char *datefmt_str[DATE_FORMATS];
extern int days[12]; extern int days[12];
extern const char *monthnames[12];
extern const char *daynames[8];
extern char path_dir[BUFSIZ]; extern char path_dir[BUFSIZ];
extern char path_todo[BUFSIZ]; extern char path_todo[BUFSIZ];
extern char path_apts[BUFSIZ]; extern char path_apts[BUFSIZ];

View File

@ -40,6 +40,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <langinfo.h>
#include "calcurse.h" #include "calcurse.h"
@ -379,6 +380,7 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day,
int w, ofs_x, ofs_y; int w, ofs_x, ofs_y;
int item_this_day = 0; int item_this_day = 0;
struct tm t = get_first_weekday(sunday_first); struct tm t = get_first_weekday(sunday_first);
char *cp;
mo = slctd_day.mm; mo = slctd_day.mm;
yr = slctd_day.yyyy; yr = slctd_day.yyyy;
@ -411,9 +413,9 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day,
werase(sw_cal.inner); werase(sw_cal.inner);
} }
custom_apply_attr(sw->inner, ATTR_HIGHEST); custom_apply_attr(sw->inner, ATTR_HIGHEST);
mvwprintw(sw->inner, ofs_y, cp = nl_langinfo(MON_1 + mo - 1);
(w - (strlen(_(monthnames[mo - 1])) + 5)) / 2, mvwprintw(sw->inner, ofs_y, (w - (strlen(cp) + 5)) / 2,
"%s %d", _(monthnames[mo - 1]), slctd_day.yyyy); "%s %d", cp, slctd_day.yyyy);
custom_remove_attr(sw->inner, ATTR_HIGHEST); custom_remove_attr(sw->inner, ATTR_HIGHEST);
++ofs_y; ++ofs_y;
@ -421,7 +423,7 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day,
custom_apply_attr(sw->inner, ATTR_HIGHEST); custom_apply_attr(sw->inner, ATTR_HIGHEST);
for (j = 0; j < WEEKINDAYS; j++) { for (j = 0; j < WEEKINDAYS; j++) {
mvwaddstr(sw->inner, ofs_y, ofs_x + 4 * j, mvwaddstr(sw->inner, ofs_y, ofs_x + 4 * j,
_(daynames[1 + j - sunday_first])); nl_langinfo(ABDAY_1 + (1 + j - sunday_first) % WEEKINDAYS));
} }
custom_remove_attr(sw->inner, ATTR_HIGHEST); custom_remove_attr(sw->inner, ATTR_HIGHEST);
WINS_CALENDAR_UNLOCK; WINS_CALENDAR_UNLOCK;
@ -507,7 +509,7 @@ draw_weekly_view(struct scrollwin *sw, struct date *current_day,
/* print the day names, with regards to the first day of the week */ /* print the day names, with regards to the first day of the week */
custom_apply_attr(sw->inner, ATTR_HIGHEST); custom_apply_attr(sw->inner, ATTR_HIGHEST);
mvwaddstr(sw->inner, OFFY, OFFX + 4 * j, mvwaddstr(sw->inner, OFFY, OFFX + 4 * j,
_(daynames[1 + j - sunday_first])); nl_langinfo(ABDAY_1 + (1 + j - sunday_first) % WEEKINDAYS));
custom_remove_attr(sw->inner, ATTR_HIGHEST); custom_remove_attr(sw->inner, ATTR_HIGHEST);
/* Check if the day to be printed has an item or not. */ /* Check if the day to be printed has an item or not. */

View File

@ -71,36 +71,10 @@ int want_reload = 0;
const char *datefmt_str[DATE_FORMATS]; const char *datefmt_str[DATE_FORMATS];
/* /*
* variables to store calendar names * variable to store month lengths
*/ */
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const char *monthnames[12] = {
N_("January"),
N_("February"),
N_("March"),
N_("April"),
N_("May"),
N_("June"),
N_("July"),
N_("August"),
N_("September"),
N_("October"),
N_("November"),
N_("December")
};
const char *daynames[8] = {
N_("Sun"),
N_("Mon"),
N_("Tue"),
N_("Wed"),
N_("Thu"),
N_("Fri"),
N_("Sat"),
N_("Sun")
};
/* /*
* variables to store data path names, which are initialized in * variables to store data path names, which are initialized in
* io_init() * io_init()