Name of months in Portuguese and English

Asked

Viewed 824 times

6

On the site where I work, I use the following query to display in English the dates that are stored in the database:

$conn->exec("SET lc_time_names = 'pt_PT'");

However, I discovered that the site will be bilingual (Portuguese and English) and I need to show the dates in both languages. How should I proceed?

  • 3

    It’s not enough to make a if to change the pt_PT for en_US?

  • @Felipeavelar I could do that, but this line is from the file that makes the connection to the bd. And the include of it in the pages happens before picking up the language.

2 answers

5


To solve this, create a page called index.php, within it, you will have language options, only flags of each country for example.

You will then have a choice, which depending on the choice you will be redirected to the same page but with different parameter, could be used this code in index.php for example:

<a href=pagina_inicial.php?lang=pt_PT >Português</a>
<a href=pagina_inicial.php?lang=en_US >Inglês</a>

And then inside your "bd-connected file" from which you posted the code in your question, it would work as follows:

$lang = $_GET['lang'];
if ($lang == "pt_PT")
  $conn->exec("SET lc_time_names = 'pt_PT'");
else
  $conn->exec("SET lc_time_names = 'en_US'");

You must be wondering "'Cause I didn’t just do it this way?:"

$lang = $_GET['lang'];
$conn->exec("SET lc_time_names = '".$lang."'");

Because it would become an extremely vulnerable target to attacks via SQL Injection, so I’d be very insecure(never use variables that can be sent by the user within SQL code)

This way I told you, you can know which language the user wants, at the time of execution of your command, via a parameter that it sent when choosing which language on the page index.php.

-3

Use this

mysql_query('SET lc_time_names = "pt_BR"');

Browser other questions tagged

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