Lv_calendar change month name

Hello,

the lv_calendar widget has a label which displays the current month. Is it possible to set a list of month names? There’s a function called lv_calendar_set_name_dates, however, the month names will always be in English. Could I somehow set these too? I can’t find any functions for it. I currently create the calendar via SquareLine Studio, so maybe I am missing something.

Kind regards

There isn’t a function to set them I believe. I think you are going to have to go into the structure returned by calendar_create to get access to the children that are more than likely lv_label’s and change the text for them. Let me do some looking and I will tell you what you need to do.

I am pretty sure it cannot be done in squareline studio and it has to be done in code.

1 Like

Thanks KD,

you are right. Most definitely not possible within Squareline, I had to change some settings within the lv_conf.h file. There’s some lines here pertaining to the calendar widget:

#define LV_USE_CALENDAR   1
#if LV_USE_CALENDAR
    #define LV_CALENDAR_WEEK_STARTS_MONDAY 0
    #if LV_CALENDAR_WEEK_STARTS_MONDAY
        #define LV_CALENDAR_DEFAULT_DAY_NAMES {"ma", "di", "wo", "do", "vr", "za", "zo"}
    #else
        #define LV_CALENDAR_DEFAULT_DAY_NAMES {"zo", "di", "wo", "do", "vr", "za", "ma"}
    #endif

    #define LV_CALENDAR_DEFAULT_MONTH_NAMES {"januari", "februari", "maart", "april", "mei",  "juni", "juli", "augustus", "september", "oktober", "november", "december"}
    #define LV_USE_CALENDAR_HEADER_ARROW 1
    #define LV_USE_CALENDAR_HEADER_DROPDOWN 1
    #define LV_CALENDAR_USE_DUTCH_NOTATION 1
#endif  /*LV_USE_CALENDAR*/

Where LV_CALENDAR_DEFAULT_MONTH_NAMES does what it says on the tin.

I added #define LV_CALENDAR_USE_DUTCH_NOTATION myself. In Dutch, it makes more sense to write the date like “juli 2023” instead of “2023 juli”. This define is then used later in
lv_calendar_header_arrow.c:

#if LV_CALENDAR_USE_DUTCH_NOTATION
    static void(*print_date)(lv_obj_t*, uint16_t, int8_t) = print_date_month_first;
#else
    static void(*print_date)(lv_obj_t*, uint16_t, int8_t) = print_date_year_first;
#endif

I edited this file slightly further on too, but it’s probably not the neatest solution. To me it makes more sense to write the month first and then the year: dates in Dutch are generally also written as dd-mm-yyyy.

At times like this I’m very happy LVGL is open-source. I should probably make a Github account at some point so I can actively contribute :slight_smile: perhaps a lv_calendar_set_name_months or lv_calendar_header_set_name_months function would be in order.

That is great that you found the solution to your problem. You should open a Github account and contribute. Functions like that for the calendar would be useful for developers wanting to support multiple languages.

1 Like