![]() |
Multilanguage support? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Multilanguage support? (/showthread.php?tid=42186) Pages:
1
2
|
Multilanguage support? - El Forum - 05-29-2011 [eluser]Y0shi[/eluser] Hello everybody. I’ve been having some headaches recently because a client of mine. Since I’ve been working on a CMS which uses CodeIgniter as driving engine development of any kind hasn’t ever been a problem to me. But my new client is the first one who wants to manage multiple languages. So if this was a project from scratch it would be much work anyway but in this case (the CMS has been started getting developed about 1,5 years ago) it’s hard for me to find a nice solution. Creating articles, managing forms or adjusting options for SEO issues – everything works fine. So how would you (in case you had a CMS which fits the scheme above) start developing a multi-language management in there? Duplicating the database, setting a prefix and write a route? Please tell me your thoughts. Very excited to hear them ![]() Thanks in advance! Regards Multilanguage support? - El Forum - 05-29-2011 [eluser]web-johnny[/eluser] [quote author="Y0shi" date="1306703706"]Hello everybody. I’ve been having some headaches recently because a client of mine. Since I’ve been working on a CMS which uses CodeIgniter as driving engine development of any kind hasn’t ever been a problem to me. But my new client is the first one who wants to manage multiple languages. So if this was a project from scratch it would be much work anyway but in this case (the CMS has been started getting developed about 1,5 years ago) it’s hard for me to find a nice solution. Creating articles, managing forms or adjusting options for SEO issues – everything works fine. So how would you (in case you had a CMS which fits the scheme above) start developing a multi-language management in there? Duplicating the database, setting a prefix and write a route? Please tell me your thoughts. Very excited to hear them ![]() Thanks in advance! Regards[/quote] A quick solution may be to add just a lang_id to each table. It will be hidden so the customer will not see it . You will have it though as hidden field. Also the queries will be easy because you will add just a $this->db->where('lang_id',$language); Multilanguage support? - El Forum - 05-29-2011 [eluser]Y0shi[/eluser] Nice solution but if you think further - are routes like www.domain.com/lang/articles/lorem-ipsum possible? Multilanguage support? - El Forum - 05-29-2011 [eluser]web-johnny[/eluser] [quote author="Y0shi" date="1306723411"]Nice solution but if you think further - are routes like www.domain.com/lang/articles/lorem-ipsum possible?[/quote] The route you could write is something like this Code: $route["(greece|english|italian)/(.*)"] = '$2'; Multilanguage support? - El Forum - 05-30-2011 [eluser]osci[/eluser] As of the routes you can have a look at URI Language Identifier Multilanguage support? - El Forum - 05-30-2011 [eluser]Y0shi[/eluser] Thanks a lot for the replies ! Do you think it would be a secure way to do following: 1. Grab web-johnny's idea and implement a lang_id to each entry 2. Add a hidden field of the language id to each form via jQuery 2.1 Alternative would be to set a CONSTANT with for example define('current_language', $this->uri->segment(1)) - or something like it 3. Grab the 1st segment of the route always as lang, interpret it in the core controller and execute mysql queries according to that 3.1 If done with the constant way much time would be saved here What do you think? Regards Multilanguage support? - El Forum - 05-31-2011 [eluser]web-johnny[/eluser] [quote author="Y0shi" date="1306792286"]Thanks a lot for the replies ! Do you think it would be a secure way to do following: 1. Grab web-johnny's idea and implement a lang_id to each entry 2. Add a hidden field of the language id to each form via jQuery 2.1 Alternative would be to set a CONSTANT with for example define('current_language', $this->uri->segment(1)) - or something like it 3. Grab the 1st segment of the route always as lang, interpret it in the core controller and execute mysql queries according to that 3.1 If done with the constant way much time would be saved here What do you think? Regards[/quote] That's right the only thing that you can do extra is not to use the first parameter for the default language. For example Code: $language_string = $this->uri->segment(1); Multilanguage support? - El Forum - 05-31-2011 [eluser]Y0shi[/eluser] Well you guys helped me a lot! But there's a last question - is there a way to append something to every mysql query executed? For example inserts should alway have a varible set which tells them to insert 'lang_id' => 1,2,3... and so on The same should occur for updates update where entry_id = $id and lang_id => 1,2,3, etc... Would you set this manually or automaticly? Best regards and many thanks! Multilanguage support? - El Forum - 05-31-2011 [eluser]web-johnny[/eluser] [quote author="Y0shi" date="1306910188"]Well you guys helped me a lot! But there's a last question - is there a way to append something to every mysql query executed? For example inserts should alway have a varible set which tells them to insert 'lang_id' => 1,2,3... and so on The same should occur for updates update where entry_id = $id and lang_id => 1,2,3, etc... Would you set this manually or automaticly? Best regards and many thanks![/quote] I actually have a function helper and it something like this : Code: if ( ! function_exists('db_language_auto_language_id')) Code: $this->db->where('status','active'); Code: db_language_auto_language_id(); Multilanguage support? - El Forum - 06-01-2011 [eluser]Y0shi[/eluser] Thanks a lot ![]() I allow my clients to set their routes manually. For example article/showarticle/1 gets lorem-ipsum-is-great as SEO route. So that means surfing to domain.tld/lorem-ipsum-is-great will bring the article with id = 1 up. The same goes for forms (e.g. domain.tld/contact) and other stuff. I need a method to make sure, that only the routes which are in the current language enviroment (de, en etc.) are loaded. Currently I load my routes dynamicly via a hook. But neither in the hook nor in the config files a constant will be echoed correctly... because it isn't set of course. So what can I do? I also got this in my routes: // General Language Rerouting $route['(\w{2})/(.*)'] = '$2'; $route['(\w{2})'] = $route['default_controller']; which is from the URI library. I think this will override anything if im trying to include the language abbreviation in my dynamically set routes. For example route['lorem-ipsum-is-great'] would then be route['en/lorem-ipsum-is-great'] and in German route['de/lorem-ipsum-ist-superklasse']... Any thoughts? Best regards ![]() |