Custom Fields
Re-Envisioned
Support MB Views Date field output not localized

  • Creator
    Topic
  • #27972

    I have set up a field group for collecting course date information in posts belonging to the catgorty "courses". I have then set up a view for the data with MB Views which is working, it puts the information before the content. So far, so good.

    However, the website is in German and uses the DE version of WordPress. But the names of the months from the date picker field remain in English: January, May, July instead of Januar, Mai, Juli for example. What do I have to do to translate these names correctly?

Viewing 10 replies - 1 through 10 (of 11 total)
  • Author
    Replies
  • #27976
    Long Nguyen
    Moderator

    Hi,

    Thank you for reaching out.

    You can use the WordPress function date_i18n() via the proxy mb to show the date in localized format, the field date should be saved in timestamp.

    Here is the sample code

    {% set field_date = mb.rwmb_meta('field_id') %}
    Date: {{ mb.date_i18n('j. F Y', field_date) }}
    #27983

    Thanks for the reply. Where does that code go?

    #27995
    Long Nguyen
    Moderator

    Hi,

    You are talking about View so of course, the code is added to View.
    https://share.getcloudapp.com/E0uYB20Z

    #27998

    I thought so, but that didn't work.

    #28014
    Long Nguyen
    Moderator

    Hi,

    Can you please share some screenshots of your View and post page?

    #28021

    Screenshots

    These are the View code and its settings and the front end output. I copied your code before the View code and that did not change anything. You can see the word "July" in the front end. "August" is the same in both languages.

    #28033
    Long Nguyen
    Moderator

    Hi,

    I do not see the function date_i18n() in your code. Can you please re-check it?

    The code with your field ID is

    {% set field_date = mb.rwmb_meta('erster_termin') %}
    Date: {{ mb.date_i18n('j. F Y', field_date) }}

    or

    Date: {{ mb.date_i18n('j. F Y', post.erster_termin) }}

    #28036

    Aaah, I see now that I should have included the field id instead of "field_id". My bad. However, it still isn't working. There is a new fourth screenshot in Screenshots.

    This is the currently active code. I also tried your second line. There are actually two date fields, so I used the code twice.

    The page displaying the result is here: https://klang-entspannung-ruhe.de/lachyoga-jung-und-gesund-bleiben-durch-lachen/

    It is still "July".

    #28037

    Oh my. Now I get where the code is supposed to go. Forget that screenshot. I put your code into the view and replaced {{ post.erster_termin | date( 'd. F Y' ) }} with it.

    However, it now displays Mai (May) instead of July. German, but two months off. The content of the field hasn't changed.

    #28042

    As I can't edit the message with the link to the actual page anymore: The code adds today's date instead of the date set with the date picker. As the website is live I reverted everything to simply putting the date in numbers instead of month names.

Viewing 10 replies - 1 through 10 (of 11 total)
  • You must be logged in to reply to this topic.