![]() |
2 Languages on my site: how to start ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: 2 Languages on my site: how to start ? (/showthread.php?tid=16306) |
2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]yannyannyann[/eluser] Hello, I am very new to codeIgniter, I started setting up my MVC but now I am asking myself how to deal with my database entries when I have to deal with languages. 1. Here is what I'd like to achieve : www.mysite.com -> should be french www.mysite.com/en -> should be english What is the best, cookies ? session ? other magical solution ? 2. Then I have in my database some photos: PHOTO table -> id -> title_fr -> title_en -> description_fr -> description_en -> ... In my model how do I check what is current language to retrieve the title in the good language ? thanks in advance 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]pistolPete[/eluser] Have a look at the wiki: http://codeigniter.com/wiki/Category:Internationalization/ I would rather use 3 tables instead of one: Code: photo Code: english Code: french Depending on the current language you would then join the photo table and the corresponding language table. Quote:In my model how do I check what is current language to retrieve the title in the good language ?In your controller you pass the current language to your model. controller: Code: (...) model: Code: class Photo_model extends Model { 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]yannyannyann[/eluser] Good and quick answer I'll try that. Thanks ! 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] 1. You'll need to have your configuration file check the URI, extract the language from it, and set the default. Code: preg_match('/^\/([a-z]+)\//', $_SERVER['REQUEST_URI'], $matches); There are other ways to do it too, but that's probably one of the easiest ways. 2. I'd suggest you change your table slightly. PHOTO table -> id -> title -> description -> language Define some constants in the constants.php file Code: DEFINE('ENGLISH', 1); Then you can do things like this. Code: $result = $this->db->get_where('PHOTOS', array('id' => $id, 'language' => FRENCH)); or Code: $data = array( Hope this helps. 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]xwero[/eluser] 1 why not use the url? check out the uri language identifier. add a default_language setting to the config file and add a function to the MY_language_helper.php or MY_url_helper.php Code: function current_language() And that brings us to 2. I like to separate the language dependent data from the language independent data so i have two tables; photo with the fields id and file and photo_lang with the fields photo_id,lang,title,description. So the query to get a photo is: Quote:SELECT t1.id, t1.file, t2.title, t2.description EDIT : i'm getting to old for this ![]() 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]xwero[/eluser] [quote author="pistolPete" date="1236100834"] I would rather use 3 tables instead of one: Code: photo Code: english Code: french A table for each language, isn't that a bit too much? 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] Wow. Spoilt for choice. ![]() [quote author="xwero" date=""] EDIT : i’m getting to old for this ![]() [/quote] You're starting to sound like Danny Glover in Lethal Weapon. 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]yannyannyann[/eluser] Quote:2. I’d suggest you change your table slightly. In this case I don't see how you can keep one photo id but having 2 languages ? Because all the pictures will have both en + fr information. I think I will go for 3 tables with the SELECT ... JOIN solution. 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]yannyannyann[/eluser] 1. I will try this : - add a default_language setting to the config file and Code: function current_language() 2. And I will create 2 tables (not 3 as I said before) : - photo (id, filename, date_added, date_shoot, author, copyright) - photo_lang (id, lang, photoid, title, description, keywords) 2 Languages on my site: how to start ? - El Forum - 03-03-2009 [eluser]TheFuzzy0ne[/eluser] You're totally right. My bad. Having a table for each is definitely the way forward. EDIT, the id column in your second table is probably not necessary. |