Date in Portuguese returning in English

0

I'm using this code to return the current date in Portuguese (locally):

<?
setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');
echo utf8_encode(strftime('%A, %d de %B de %Y', strtotime('today')));
//domingo, 22 de outubro de 2017
?>

However in production it is returning, changing this line, otherwise it will not load, so I removed utf8_encode:

echo strftime('%A, %d de %B de %Y', strtotime('today'));

Sunday, 22 de October de 2017

The server operating system is America/Sao_Paulo

Any tips?

    
asked by anonymous 22.10.2017 / 16:13

2 answers

1

The error actually occurs in the operating system:

I solved, changing the language with the following command in promt of debian:

export LANG=pt_BR.UTF-8

That's the tip, I've tried in a number of ways.

    
22.10.2017 / 16:42
0

One way to solve the problem is also to use a class that translates the string Mes .

Create an array of date with the function explode native to php.

$data = explode('/', date('d/m/Y'));

Then get this array and print the current month.

  

function

function Mes($nomemes, $formato = 'extenso'){
$formatoValido = array('extenso', 'abreviado');

if(!in_array($formato, $formatoValido)){
    return "Formato de data invalido";
}

$mes = array(
1 => array(
    'abreviado' => 'Jan',
    'extenso'   => 'Janeiro'
    ),
2 => array(
    'abreviado' => 'Fev',
    'extenso'   => 'Fevereiro'
    ),
3 => array(
    'abreviado' => 'Mar',
    'extenso'   => 'Março'
    ),
4 => array(
    'abreviado' => 'Abr',
    'extenso'   => 'Abril'
    ),
5 => array(
    'abreviado' => 'Mai',
    'extenso'   => 'Maio'
    ),
6 => array(
    'abreviado' => 'Jun',
    'extenso'   => 'Junho'
    ),
7 => array(
    'abreviado' => 'Jul',
    'extenso'   => 'Julho'
    ),
8 => array(
    'abreviado' => 'Ago',
    'extenso'   => 'Agosto'
    ),
9 => array(
    'abreviado' => 'Set',
    'extenso'   => 'Setembro'
    ),
10 => array(
    'abreviado' => 'Out',
    'extenso'   => 'Outubro'
    ),
11 => array(
    'abreviado' => 'Nov',
    'extenso'   => 'Novembro'
    ),
12 => array(
    'abreviado' => 'Dez',
    'extenso'   => 'Dezembro'
    )
);
return $mes[$nomemes][$formato];
}

In this function I have created two ways to call it with a string in full and abbreviated as follows

echo "São Paulo, ".$data[0]." de ".Mes($data[1])." de ".$data[2];//string no extenso São Paulo, 22 de Outubro de 2017

And short value

echo "São Paulo, ".$data[0]." de ".Mes($data[1],'abreviado')." de ".$data[2];// abreviado para São Paulo, 22 de Out de 2017
    
22.10.2017 / 17:02