Place Portuguese posting date using [processwire]

Asked

Viewed 269 times

1

I am using processwire and to put the post creation date I used the following code

<?php  echo ( date("F j, Y ", $page->created). "at " . date("g:i A", $page->created));  ?></p>

However this code does show the date in English format and I would like to translate to Portuguese

I’ll show you the change I made

<p><span class="glyphicon glyphicon-time"></span> Posted on <?php  echo ( date("F j, Y ", $page->created). "at " . date("g:i A", $page->created));  //antes
                                        //Alteração apartir daqui
                                      // strftime("%A, %d de %B de %Y", strtotime( $page->created));
                                        $en = ['','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
                                        $pt = [' de ', 'janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro']; 
                                            echo("<br>");
                                         echo str_replace($en, $pt, strftime("%d de %B de %Y as %H:%M", strtotime($date)));
                                        ?>
</p>

What was before September 2, 2015 at 10:31 AM

After amendment 1 January 1970 at 01:00

The dates are different

If anyone can add the processwire tag in the English stackoverflow already exists created

  • So you can’t change the locale?

1 answer

1


According to this discussion, you can do this by setting the language in your config.php:

$config->timezone = 'America/Sao_Paulo';
setlocale(LC_ALL, 'pt_BR');

And display the date as follows:

echo strftime("%A, %d de %B de %Y", strtotime( $page->created));

If you cannot change the default language, you can translate manually:

    $date = '1441186272'; // $page->created

    $en = array('','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    $pt = array(' de ', 'janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'); 

    echo str_replace($en, $pt, strftime("%d de %B de %Y as %H:%M", $date));

Will return:

September 28, 2015 at 08:54

  • Closing the Language would affect the entire template and I belong that only translates when I press the button I created "PT" so I made a variable that would replace depending on the button that was primed

  • ´$config->Timezone = 'America/Sao_paulo'; setlocale(LC_ALL, 'pt_BR'); echo strftime("%A, %d of %B of %Y", strtotime( $page->created));

  • I formatted the answer with one more alternative so that you can use without changing the default language.

  • Returned the following: Posted on September 2, 2015 at 10:31 AM Thursday, January 1, 1970

  • As you did??

  • edited up there @Marcelo de Andrade

  • You are giving a Return, I have edited my code. Change "Return" to "echo".

  • I showed you up there how it turned out.

  • I removed the strtotime function from the answer, its field should already be of the date/datetime type. Getting as follows: echo str_replace($en, $pt, strftime("%d de %B de %Y as %H:%M", $date));

  • returns the same without the function

  • Any idea how to solve this ?

  • What feedback do you have when giving an echo on $page->created ?

  • returns '1441186272' seems time in seconds or so

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.