Does setlocale not work on Amazon EC2 instances?

Asked

Viewed 197 times

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)?

  • 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.

  • The page is updated to make this happen. I installed pt_BR and pt_BR.utf-8

  • Started restarting the server after installation?

  • @Answer your question with what solved the problem and create a new question for the new problem, linking this question in the question below.

  • @Andersoncarloswoss not yet, I’ll do it.

  • 1

    @Cypherpotato, okay, soon I’ll answer my question.

Show 2 more comments

1 answer

0


The problem is not in the Amazon instance. This occurs when the linux server of your Amazon instance does not have the desired location installed. To install on your server, you must run the following command on the terminal (precisely on linux servers):

locale-gen pt_BR.utf-8

pt_BR.utf-8 is used for the English language and can support characters such as "ç". Also you can reconfigure your location manually using the command below. Look for pt_BR.utf-8 to set as default.

sudo dpkg-reconfigure locales

Or you can use the command below to define how default its location.

sudo update-locale LANG=pt_BR.utf-8

Browser other questions tagged

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