1
I am developing an application in Laravel where I needed to use the function resources setlocale
to translate the months of a given day into Portuguese. A month ago I had published a question concerning this functionality performed in PHP. Locally on my machine it works normally. Every month is picked up correctly. Below is the code I used to "force" the location and take the translated values.
date_default_timezone_set('America/Sao_Paulo');
setlocale(LC_ALL, 'pt_BR.utf-8', 'ptb', 'pt_BR', 'portuguese-brazil', 'portuguese-brazilian', 'bra', 'brazil', 'br');
setlocale(LC_TIME, 'pt_BR.utf-8', 'ptb', 'pt_BR', 'portuguese-brazil', 'portuguese-brazilian', 'bra', 'brazil', 'br');
Below is the example of what could catch your date. Where I use the command formatLocalized('%B')
.
$mes = $datas->copy()->subMonth()->formatLocalized('%B');
However, a simple error occurred. My functionality was uploaded to a server of an instance of Amazon EC2, and the months do not come out in Portuguese, both months appear in English.
I found someone who has the same problem as mine at that link. But it still left me doubtful what might happen with it. Remembering that I’m using the API of Carbon. What could be this problem, could be from my instance of Amazon?
The PHP version of my local machine is 7.3 and the Amazon server is 7.2.
Already checked if the locale you are using is properly installed on the server (
$ locale -a
)?– Woss
It was not installed, it worked. However, there was another error now. I used the locale-gen pt_BR.utf-8 command. After that, it worked normally. Only now it is occurring of times appear translated and times appear in English.
– Arthur Abitante
The page is updated to make this happen. I installed pt_BR and pt_BR.utf-8
– Arthur Abitante
Started restarting the server after installation?
– Woss
@Answer your question with what solved the problem and create a new question for the new problem, linking this question in the question below.
– CypherPotato
@Andersoncarloswoss not yet, I’ll do it.
– Arthur Abitante
@Cypherpotato, okay, soon I’ll answer my question.
– Arthur Abitante