Welcome Guest, Not a member yet? Register   Sign In
multilanguage database struct
#11

[eluser]Isern Palaus[/eluser]
No problem, it's a pleasure.

Don't ask me why, but if you make this changes:

- Rename the class to MY_Controller:
Code:
class Web extends MY_Controller {

- Make the constructor PHP5 like:
Code:
function __construct()
{
    parent::MY_Controller();
}

- Rename the file to MY_Controller.php

- Extend MY_Controller in the Web controller (and change parent to parent::MY_Controller()).

... works! :-)

Well, I can't promise but shows me a database error so recognises the MY_Controller one ;-).

Whish it helps!!
#12

[eluser]siubie[/eluser]
great this thing works Big Grin
another million thanks for you Isern Wink
#13

[eluser]onuryasar[/eluser]
guess this doesn't work "as is" in 2.0. what should be changed?
#14

[eluser]Unknown[/eluser]
[quote author="Isern Palaus" date="1266406574"]Hello,

I have a table called 'idioma' (language in spanish):

Code:
CREATE TABLE IF NOT EXISTS `idioma` (
  `ididioma` int(11) NOT NULL AUTO_INCREMENT,
  `nombre` varchar(45) COLLATE utf8_spanish2_ci DEFAULT NULL,
  `codigo` varchar(5) COLLATE utf8_spanish2_ci DEFAULT NULL,
  `locale` varchar(255) COLLATE utf8_spanish2_ci DEFAULT NULL,
  `imagen` varchar(125) COLLATE utf8_spanish2_ci DEFAULT NULL,
  `orden` int(11) DEFAULT NULL,
  `activo` tinyint(4) DEFAULT NULL,
  `fecha` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`ididioma`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci

nombre -> name
codigo -> code
locale -> locale
imagen -> image
orden -> order
activo -> active
fecha -> date

I add entries like: Name = English, Code = EN, Locale = en_US, Image = en.jpg, Order = 1, Active = 1, Date = 2010-02-17.

Then, to detect the language I personally use URI Language founded on the wiki for the detect the languages like .com/en, .com/es, .com/fr... and my BaseController (that I extend on every controller) looks like:

Code:
<?php

class BaseController extends Controller {

    public $idioma = NULL;

    public function BaseController()
    {
        parent::Controller();
        
        $language = $this->config->item('language_abbr');
        $this->session->set_userdata('language', $language);
        
        $query = $this->_getLanguageId($language);
            
        if($query->num_rows() > 0)
        {
            $row = $query->row();
            
            $languageId = $row->ididioma;
            
            $this->session->set_userdata('language_id',$languageId);
        }
        
        $this->idioma = getLanguageId();
    }

    private function _getLanguageId($codigo)
    {
        return $this->db->get_where('idioma', array('codigo' => $codigo));
    }

}

And in the MY_Language.php helper:

Code:
function getLanguage()
{
    $CI =& get_instance();
    
    return $CI->session->userdata('language');
}

function getLanguageId()
{
    $CI =& get_instance();
    
    return $CI->session->userdata('language_id');
}

So I can access in every controller with $this->idioma.

Then all my tables that contents multilingual content has this structure:

news
----
idnews
image
user_id
date

news_description
----------------
idnews_description
text
news_idnews
idioma_ididioma

Then for every new you will add a text for every language.

A query will look like:
Code:
public function get_new($idnews = 1, $ididioma = 1)
{
    $this->db->from('news')
             ->join('news_description','news.idnews = news_description.news_idnews','left')
             ->where('news_description.idioma_ididioma', $ididioma)
             ->where('news.idnews', $idproducto)
             ->limit(1);
    
    return $this->db->get();
}

And you will call it with get_news($new_id, $this->idioma).

I wish it helps and sorry for my school English.

Regards,
Isern[/quote]


Hello dear Isern!
I read your tutorial on how to make a multi-language application, and some things i understand but there are some thing that i don`t. Unfortunately for me it is not clearly described, like what i should do before the tutorial?
My example
I have a CodeIniter application totally on english language now i want to make it 2 language.
my DB structure:
table called Main:
id
title_en
description_en
keywords_en
category_en
title_fr
description_fr
keywords_fr
category_fr
And i have content in this db structure.
Like i told you my application is working now only in english language, i want to add 2 flags on the top of header to switch between 2 languages using database content?? From what i read on this forum you are a CodeIgniter pro and i hope you can explain me what steps i need to do from the beginning.








Theme © iAndrew 2016 - Forum software by © MyBB