Error in the language of the month Django

0

Good morning guys,

Next, I have a very uncomfortable problem. When I try to use the date that was stored in the database, it comes with the month in English.

settings.py:

LANGUAGE_CODE = 'pt-br'

TIME_ZONE = 'America/Sao_Paulo'

USE_I18N = False

USE_L10N = True

USE_TZ = True

And then the template looks like this:

A última atualização foi no dia 5 de February de 2017 às 09:19

My version of Django is 1.10.4

    
asked by anonymous 05.02.2017 / 12:20

1 answer

2

If you are using the MySQL database, the problem must be in the lc_time_names variable. To verify, use the following statement:

SELECT @@lc_time_names;

The return should look something like this:

+-----------------+
| @@lc_time_names |
+-----------------+
| en_US           |
+-----------------+
1 row in set (0.00 sec)

en_US is the default value in MySQL and this is probably your problem. To change it to pt_BR , execute the statement:

SET lc_time_names = 'pt_BR';

In this way, when checking the value of the variable again, the return will be:

+-----------------+
| @@lc_time_names |
+-----------------+
| pt_BR           |
+-----------------+
1 row in set (0.00 sec)

And so, if you test with the date:

SELECT DATE_FORMAT(CURDATE(), '%d de %M de %Y');

Your return will be:

+-------------------------------------------------+
| SELECT DATE_FORMAT(CURDATE(), '%d de %M de %Y') |
+-------------------------------------------------+
| 05 de fevereiro de 2017                         |
+-------------------------------------------------+
1 row in set (0.00 sec)

Notice the date in Portuguese. However, when you close the session with MySQL, the variable will return to its default value, requiring you to update to pt_BR each time you connect to the database. To work around this problem, you can set the variable in global scope, with the statement:

SET GLOBAL lc_time_names=pt_BR;

But I do not know if defining it globally brings some risk to your application.

    
05.02.2017 / 14:33