Question

I've started using frameworks(CodeIgniter) recently and after lots of research still have many doubts , specially regarding a multilingual website.

I'm trying to "translate" the url , for instance, I have en/home and fr/home , but I'd like to have for each language its own translation like fr/accueil , pt/inicio, and so on... So far all my system is doing is to change the language but the url(controller) remains in the same language(english): en/home , fr/home, pt/home instead of fr/accueil and pt/inicio

What do I have to do to achieve this sort of "translation" or routing? Is it better to create a controller for each language and call them separately? I started doing that but at some point I realized it was extremely massive and probably it isn't a good practice. But I found much easier to create a controller for each language, but then I don't know where and in which file I have to set an "auto run function" to detect/save the language preferences.

Also when I type just the language in my url ( e.g /en , /fr ) it doesn't "redirect" to the main controller (home):

// '/en', '/de', '/fr' and '/nl' URIs -> use default controller
$route['^(en|fr|pt)$'] = $route['default_controller'];

This is not working for me unless I type "/" after the language: /fr/ works fine!, /fr doesn't work!

Was it helpful?

Solution

I successfully use the approach of setting a cookie for the language instead of having it in the URI, then having all URI segments set in my pages database, for each language, then in my page model I load the correct language URI and text based on the language cookie.

Now the only remaining problem is routing, I set something like this in the end of my routes file, redirecting all remaining requests to the page controller method:

$route['(:any)'] = "main/pages";
$route['(:any)/(:any)'] = "main/pages";

This way I can have both page URI and submeny URIs with my localized version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top