Error in month language Django

Asked

Viewed 296 times

2

Good morning guys,

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

py Settings.:

LANGUAGE_CODE = 'pt-br'

TIME_ZONE = 'America/Sao_Paulo'

USE_I18N = False

USE_L10N = True

USE_TZ = True

And then in the template appears 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

  • Is using Mysql?

  • I don’t remember if it’s case sensitive, but I think correct be it LANGUAGE_CODE = 'pt-BR'.

  • Remained the same

1 answer

4

If you are using the Mysql database, the problem must be in the variable lc_time_names. To check, use the following instruction:

SELECT @@lc_time_names;

The return must be something like this:

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

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

SET lc_time_names = 'pt_BR';

This way, when checking again the value of the variable, 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)

Note the date in English. However, this way, when you close the session with Mysql, the variable will return to its default value, requiring you to update to pt_BR every time you connect to the bank. To get around this problem, you can set the variable in the global scope, with the instruction:

SET GLOBAL lc_time_names=pt_BR;

But I can’t say if defining it globally brings some risk to its application.

  • No, I’m using Postgresql. However it is set for Brazil.

  • Running the command on PSQL: SELECT to_char(DATE'2017-02-06','Tmday - d "de" Tmmonth "de" YYYY'); to_char ---------------------------------------- Monday - February 2, 2017 (1 record)

Browser other questions tagged

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