Date field output not localized
- This topic has 13 replies, 4 voices, and was last updated 7 months, 2 weeks ago by
Bogdan Michitele.
-
AuthorPosts
-
May 6, 2021 at 10:17 PM #27972
[email protected]
ParticipantI 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?
May 7, 2021 at 8:25 AM #27976Long Nguyen
ModeratorHi,
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) }}
May 7, 2021 at 2:51 PM #27983[email protected]
ParticipantThanks for the reply. Where does that code go?
May 7, 2021 at 7:45 PM #27995Long Nguyen
ModeratorHi,
You are talking about View so of course, the code is added to View.
https://share.getcloudapp.com/E0uYB20ZMay 7, 2021 at 8:02 PM #27998[email protected]
ParticipantI thought so, but that didn't work.
May 8, 2021 at 9:01 AM #28014Long Nguyen
ModeratorHi,
Can you please share some screenshots of your View and post page?
May 8, 2021 at 12:31 PM #28021[email protected]
ParticipantThese 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.
May 9, 2021 at 1:40 PM #28033Long Nguyen
ModeratorHi,
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) }}
May 9, 2021 at 2:11 PM #28036[email protected]
ParticipantAaah, 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".
May 9, 2021 at 2:23 PM #28037[email protected]
ParticipantOh 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.
May 9, 2021 at 2:46 PM #28042[email protected]
ParticipantAs 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.
May 9, 2021 at 9:43 PM #28047Long Nguyen
ModeratorHi,
If the code
post.erster_termin
show the date as well, please try to use this codeTermine: {{ mb.date_i18n('j. F Y', post.erster_termin) }} bis {{ mb.date_i18n('j. F Y', post.letzter_termin) }}
If it still does not work, please share your site credentials via this contact form https://metabox.io/contact/, I will help you to check it out.
October 11, 2022 at 12:55 AM #38620Vince Balk
ParticipantI use Oxygen with a repeater and my date is in English (Oct) and not in Dutch (okt). What can I do to solve this? On an other site same code is correct.
September 4, 2024 at 2:50 AM #46321Bogdan Michitele
Participanti have same problem like Vince Balk . How can i traduce the date month ? Website is set correct , date input is set correct , in gridBuilder the month is showing in my language but in elementor date month appear in english . Can you help please ?
-
AuthorPosts
- You must be logged in to reply to this topic.