Multiple language CI web site? |
[eluser]invision[/eluser]
Hi, I have a site with 2 pages (home page and a contact page) and I'd like to have it in both English and Spanish. I have the translated text all ready but just wondered what is the best way of doing this. Should I have: mysite.com/en/ and mysite.com/es/ And /es/ would just receive "Spanish" views files? Thanks for any advice you can give.
[eluser]smilie[/eluser]
I am not sure how would that (positively or negatively) effect search engines. I myself prefer to store language info in the session and based on that load appropriate language file. Code: $this->load->lang('some_lang',$this->session->userdata('language')); This way, my url is always same. Cheers, Smilie
[eluser]michalsn[/eluser]
Take a look at this lib: http://codeigniter.com/wiki/URI_Language_Identifier
[eluser]invision[/eluser]
Hey, Thanks for the quick reply. Out of interest, would this automatically translate my 'English' text to 'Spanish'? Currently my main English 'template' file is 'template.php'. Does this mean I should then load a 'template_es.php' for the Spanish language? Thanks again for your help.
[eluser]smilie[/eluser]
@invision: With my approach - no; you would always use one and same 'template'. Only thing you have to make sure is that in both language files you have same 'config'. A small example. English language file admin_lang.php Code: $lang['title'] = "This is my title"; Spanish language file admin_lang.php Code: $lang['title'] = "Este es mi título"; Then, in your view file / template: Code: $this->lang->load('admin',$this->session->userdata('language')); And so on, you can add 'dynamic' language with 1 (template) file. By the way, same approach may be used in the controllers / libraries and so on (i.e. for error handling, logging, sending mail and such). Cheers, Smilie
[eluser]invision[/eluser]
[quote author="michalsn" date="1292859906"]Take a look at this lib: http://codeigniter.com/wiki/URI_Language_Identifier[/quote] Thanks for this I think I'll plan it out a little more on paper and report back.
[eluser]invision[/eluser]
[quote author="smilie" date="1292860238"]@invision: With my approach - no; you would always use one and same 'template'. Only thing you have to make sure is that in both language files you have same 'config'. A small example. English language file admin_lang.php Code: $lang['title'] = "This is my title"; Spanish language file admin_lang.php Code: $lang['title'] = "Este es mi título"; Then, in your view file / template: Code: $this->lang->load('admin',$this->session->userdata('language')); And so on, you can add 'dynamic' language with 1 (template) file. By the way, same approach may be used in the controllers / libraries and so on (i.e. for error handling, logging, sending mail and such). Cheers, Smilie[/quote] Aaaah brilliant. Now that makes a lot of sense. Many thanks for your efforts, Smilie. For the time being I'm going to have some really basic HTML files with the different languages, but ultimately move to this solution. Wish me luck
[eluser]smilie[/eluser]
[quote author="invision" date="1292860340"] Wish me luck [/quote] Good luck :cheese: Regards, Smilie |
Welcome Guest, Not a member yet? Register Sign In |