Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing an issue where the PHP

date()

function is not displaying dates in the correct language on their Spanish translation page. The dates are being output with the data-date attribute set to "1970-01-01" instead of the correct effective date. The client has custom fields for dates that are set to COPY, and while the effective date is displayed next to the post title, the data attribute in the HTML is incorrect.

Solution:
We understand that the issue arises because the PHP

date()

function is using the server's locale to generate month names, which may not be translated by WPML's String Translation. This feature is intended for static strings and might not apply to dynamic content such as PHP-formatted dates. To translate month names and dates in WordPress using WPML, additional steps or configurations might be necessary, such as using WordPress-specific functions or hooks to localize the date strings. We found a solution on StackOverflow that could be helpful:

Please note that support for issues arising from custom coding is beyond our support scope. If you require assistance with custom coding, consider hiring a professional developer who specializes in customizing WPML and its extensions from https://wpml.org/contractors/.

If this solution is not relevant to your case, because it's outdated or not applicable, we recommend opening a new support ticket. We also highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins.

If you need further assistance, please do not hesitate to contact us in the WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Prosenjit Barman 9 months, 1 week ago.

Assisted by: Prosenjit Barman.

Author Posts
February 23, 2024 at 10:04 pm #15339565

kurtK-7

hidden link

The link above lists posts with dates and the allows them to be sorted by taking the effective date and adding it as a data-attribute. Each post has the data-date attribute

The Effective Date is also shown after the post title in Parenthesis.

The link below is my spanish translation

hidden link

As you can see the effective date next to the post title in parenthesis is working but for some reason the data-attribute is not. All my data-attributes are listed as data-date="1970-01-01"

All 3 of my custom fields are listed as COPY and it seems to be working
announcement_date
manufacturer_announcement
effective_date

But my code for the $effective_format is not reading the $effective value correctly

$effective = get_field('effective_date', $post->ID );
$effective_format = date("Y-m-d", strtotime($effective) );

echo '<li data-title="'. $mfr_update_title .'" data-date="'. $effective_format .'" >';
echo '';
echo $mfr_update_title;
echo '
';
echo ' ('. $effective .')';

Can you help me understand why the php date() format is not working when viewing as spanish?

February 24, 2024 at 12:41 am #15339735

kurtK-7

I made some update

$effective = get_field('effective_date', $post->ID );
$effective_format = date("F j, Y", strtotime($effective) );

// Display post title.
if ( $title = get_the_title() ) {
echo '<li data-title="'. $mfr_update_title .'" data-date="'. $effective .'" >';
echo '';
echo $mfr_update_title;
echo '
';
echo ' ('. $effective_format . ')';

Its funtioning better now but previously the date formating for F j, Y was automatically converting to spanish language months. How can I get that to work again? String Translation perhaps?

February 26, 2024 at 10:41 am #15343521

Prosenjit Barman
Supporter

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hello There,
Thanks for contacting WPML Support. Sorry for the delay in responding due to the weekend.

I understand the issue you're having. In the previous code, the value from the "$effective" variable was displayed on the frontend, which doesn't have any date formatting. This mainly causes the dates to be shown in a basic format. It's good to know you've pinpointed the cause of the issue, and I can see that the dates are now being presented in the desired "Month day, Year" format.

Since the month names are generated by PHP's date formatting functions based on the server's locale, there's a significant chance that these names may not be translated by WPML's String Translation. This feature is primarily intended for translating static strings within WordPress, and might not directly apply to dynamic content such as dates and month names formatted by PHP.

To translate month names and dates within WordPress using WPML, additional steps or configurations may be required, such as using WordPress-specific functions or hooks to localize the date strings. While searching, I found a solution in StackOverflow that might help in this matter.

- https://wordpress.stackexchange.com/a/312762

Please be informed that providing support for the issue that arises due to custom coding is beyond the scope of our support. Therefore, while I may not be able to assist you directly with custom coding issues, I will do my utmost to offer guidance within the limits of our support capabilities. if you need assistance with custom coding, you can hire a professional developer, who specializes in customizing WPML and its extensions from here: https://wpml.org/contractors/

Feel free to let me know if you need further assistance in this matter. I will be happy to help.

Best regards,
Prosenjit