admin管理员组

文章数量:1327982

I'm having a little (and annoying) problem in Wordpress. I'm using a Restaurant Reservation plugin. Everything works fine, all date format are well translated in my language (Italian). All website is set to it_IT.

However, there is a Control Panel inside my Wordpress Admin Panel, in which the date is still in English:

The code that returns that date is:

            case 'qrr_date':
                $date_str = $model->get_date();
                if (!empty($date_str)){
                    $date_obj = new DateTime( $date_str );
                    $format = apply_filters( 'qrr_admin_booking_column_date', 'j F Y, H:i');
                    echo $date_obj->format($format);

I'm trying to use the date_i18n() function in order to have everything in my lang. But I think i'm using it wrongly (or maybe some strings are corrupted).

I tried:

echo date_i18n($date_obj->format($format));

But this is what it returns:

22 J000000lunedi20 2020, 20:15

It's like "July" is "J000000lunedi20", but of course it should be "Luglio".

Am I doing something wrong? I'm not good in PHP. This is not my field :( I hope you can help me with that.

I'm having a little (and annoying) problem in Wordpress. I'm using a Restaurant Reservation plugin. Everything works fine, all date format are well translated in my language (Italian). All website is set to it_IT.

However, there is a Control Panel inside my Wordpress Admin Panel, in which the date is still in English:

The code that returns that date is:

            case 'qrr_date':
                $date_str = $model->get_date();
                if (!empty($date_str)){
                    $date_obj = new DateTime( $date_str );
                    $format = apply_filters( 'qrr_admin_booking_column_date', 'j F Y, H:i');
                    echo $date_obj->format($format);

I'm trying to use the date_i18n() function in order to have everything in my lang. But I think i'm using it wrongly (or maybe some strings are corrupted).

I tried:

echo date_i18n($date_obj->format($format));

But this is what it returns:

22 J000000lunedi20 2020, 20:15

It's like "July" is "J000000lunedi20", but of course it should be "Luglio".

Am I doing something wrong? I'm not good in PHP. This is not my field :( I hope you can help me with that.

Share Improve this question asked Jul 20, 2020 at 8:28 mois23mois23 1
Add a comment  | 

1 Answer 1

Reset to default 0

So to see how that date_i18n function works you can search for it, then hopefully find the documentation.

That's here: https://developer.wordpress/reference/functions/date_i18n/

It's technical to read it, but what it says is that the first parameter on the function is not the date you want to translate but the date format that you want the date in, and the second is the time in a timestamp format. (It exlpains that weird output because you're giving it a date where it's expecting a date format string)

So what you probably want is:

echo date_i18n($format, $date_obj->getTimestamp());

I didn't test this, but looking at docs for DateTime here https://www.php/manual/en/class.datetime.php , it looks like it should be right.

Post again if it doesn't work.

本文标签: pluginsProblem with Date translation in Wordpress