• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correct Multi-Language Approach

#1
[eluser]harbooz[/eluser]
Hello!

I am Koz, new to codeigniter and I am using it for a multilingual website with cms. I would really appreciate some documented or expert advice on this.

Introduction

The challenge of this website is that it needs to be available in 3 languages. I've first considered storing the current_language that the user has chosen in a session, but in this case the url's would not be search engine friendly and only one the default language would be indexed. (I am using segmented uri's)

So the structure I've implemented until now looks like this:

I have 3 controllers, one for each language, called "en", "fr", "it". Each controller contains functions corresponding to the pages/views. This way, by changing the first segment, I can switch to a new language. The URI looks like this:

Code:
myurl.com/index.php/en/portfolio/branding/project_name

Questions

1. Is this a correct way to approach the language change, in order for the site to be search engine friendly? If not, what would be the best method?

2. If this method is OK, what problems I may encounter during development. I'm thinking I may get to a stage when some things will get tricky (contact forms, etc), because of using the first segment for the language instead of a page controller.

Thank you!

Best Regards,
Koz

Later Edit: The text in various languages comes from the DB, not from language files

#2
[eluser]darkhouse[/eluser]
Not that I've done much multilingual work, I personally prefer keeping my URIs the same for all languages, and storing the user's language preference in a cookie. I have setup a couple sites where I have a default language (en) and then either a drop down or a link to switch languages. This remembers the current URI, switches languages and redirects back to the original URI, but displaying everything in the appropriate language. Another method I used was switching the entire domain for different languages, but again, the URI was the same. It was just 2 domains that were pointing to the same content, and I had my redirect change the entire domain on language select.

Again, that's just my preference, so I don't have to worry about the language in the URI and messing around with routes and controllers and whatnot.

Edit: but it might not work that great for multilingual searches on search engines - not sure.

#3
[eluser]harbooz[/eluser]
[quote author="harbooz" date="1252101515"]
I've first considered storing the current_language that the user has chosen in a session, but in this case the url's would not be search engine friendly and only one the default language would be indexed.[/quote]

Thank you for your answer, but like I said in my initial post, I've tried a similar method and it does not solve the problem.

#4
[eluser]renownedmedia[/eluser]
Use four different subdomains, e.g. en.example.com and de.example.com, etc.

You can do this and keep one central code area, but that is the topic of a separate forum post :p

Perhaps default www.example.com to english. If users would ever want to switch between the four domains, store cookies tied to *.example.com instead of the sepecific FQDN's.

#5
[eluser]harbooz[/eluser]
Thanks Thomas, it's a good idea. If I find myself in trouble because of my approach, I will check into it.

In the mean time, I've managed to make it work my way.
The language is stored in the first segment of the uri and a session is also set up in order to keep the user preference until the next visit.

Cheers,
K

#6
[eluser]n0xie[/eluser]
Have you looked here?
http://codeigniter.com/wiki/URI_Language_Identifier/
http://maestric.com/doc/php/codeigniter_i18n

#7
[eluser]harbooz[/eluser]
As I've mentioned earlier, I'm not getting the text from language files, but from a database. Would i18n bring any improvements to my method described above?

Also, I want to thank you all for answering my questions and for you patience. I am new to php and code igniter.

#8
[eluser]BrianDHall[/eluser]
Spify site - you seem to be doing a good job so far Smile

#9
[eluser]n0xie[/eluser]
[quote author="harbooz" date="1252131125"]As I've mentioned earlier, I'm not getting the text from language files, but from a database. Would i18n bring any improvements to my method described above?
[/quote]
Yes.

Instead of having 3 controllers for your languages and having a language session, you just grab the language portion from the url which gives a cleaner solution. You can design/build your website just as you would for 1 language.

The only thing you have to do is pass the language identifier as part of your WHERE clause in your queries. I imagine you have queries like this:
Code:
SELECT somefield FROM sometable WHERE somefield = 'somevalue' AND language = 'languagevalue'

#10
[eluser]harbooz[/eluser]
Thanks

Your are right, it would be a cleaner solution, but from what I see on the forums, that language component causes problems and needs tweaks to work properly. I got it running without problems until now with 3 language controllers and I'm happy with how it works.

The language session is used only to remember the last language selection for a user's next visit, so I would need this with i18n too.

As for the queries, of-course this is how I'm doing things. I'm grabbing the language from the first segment into a global variable, and using it in queries.

Cheers!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.