I would not create 4 columns stating which language it would be like in the example you quoted:
titulo_br | titulo_en | conteudo_br | conteudo_en
I would make a normal table and only create a column to know which language that record is in
id | titulo | conteudo | idioma
An example record in this table:
1 | Um título | Conteudo da tabela em português | pt
2 | One Title | Content of the table in english | en
If it is specific content to be displayed, create a column
call for example identification and in it put a word, ID
or what you find easier and in SELECT
make a WHERE
pulling that
contents.
Create links to select site language/content, for example
<a href="<?php echo base_url('idioma/pt');?>">Português</a>
<a href="<?php echo base_url('idioma/en');?>">Inglês</a>
In application/config/Routes.php add:
$route['idioma/(:any)'] = 'idioma/selecionar_idioma/$1';
Controller language
<?php
class Idioma extends CI_Controller{
public function selecionar_idioma($idioma){
$this->session->set_userdata('idioma', $idioma);
redirect('index'); //Página inicial ou outra página
}
}
?>
When displaying table content for example:
$idioma = $this->session->userdata('idioma');
$this->db->where('idioma', $idioma);
$query = $this->db->get('tabela_do_conteudo');
foreach($query->result() as $result){
echo $result->titulo.'<br />';
echo $result->conteudo.'<br /><br />';
}
I would do more or less like this. You can also use cookies
think better than session
.
You have some questions on the subject: Translation of pages into php files, How to make a multilingual site? and How to translate a website into PHP?.
– rray
Stay tuned for date formats or masks, monetary values, and more if you handle fields of these types. Another option is to do the translation via javascript some plugins: message js, jquery-global, jquery-localize
– rray