Welcome Guest, Not a member yet? Register   Sign In
Multiple language CI web site?
#1

[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.
#2

[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
#3

[eluser]michalsn[/eluser]
Take a look at this lib: http://codeigniter.com/wiki/URI_Language_Identifier
#4

[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.
#5

[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";
$lang['user'] = "Username";

Spanish language file admin_lang.php
Code:
$lang['title'] = "Este es mi título";
$lang['user'] = "Nombre de usuario";
# Used google translate, may not be correct :))

Then, in your view file / template:
Code:
$this->lang->load('admin',$this->session->userdata('language'));
# session->userdata('language') would be same as your directory name in the language; i.e. english or spanish
// a lot of HTML here...
$this->lang->line('title'); // this will present "This is my title" in case session is english.

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
#6

[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 Smile I think I'll plan it out a little more on paper and report back.
#7

[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";
$lang['user'] = "Username";

Spanish language file admin_lang.php
Code:
$lang['title'] = "Este es mi título";
$lang['user'] = "Nombre de usuario";
# Used google translate, may not be correct :))

Then, in your view file / template:
Code:
$this->lang->load('admin',$this->session->userdata('language'));
# session->userdata('language') would be same as your directory name in the language; i.e. english or spanish
// a lot of HTML here...
$this->lang->line('title'); // this will present "This is my title" in case session is english.

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 Smile
#8

[eluser]smilie[/eluser]
[quote author="invision" date="1292860340"]
Wish me luck Smile[/quote]

Good luck :cheese:

Regards,
Smilie




Theme © iAndrew 2016 - Forum software by © MyBB