0
votes

I've searched a lot and found even more topics on CI's multilanguage URLs. But most of the answers have no longer working links to CI wiki or doesn't explain a bit of what I want.

My default is a non English language, but I want controllers and methods named in English. I also don't want language segment appear in my URL (at least not for default language).

Eg.:

  • Default uri - example.com/blogas/irasas/123
  • English uri - example.com/blog/item/123 or example.com/en/blog/item/123

Links in both languages should call Blog::item()

Generating uris should be similar - site_url('blog/item/123'); should result a link in user language:

  • Default - example.com/blogas/irasas/123
  • English - example.com/blog/item/123 or example.com/en/blog/item/123

User language should be set in a cookie or session preferably. Is there any way to achieve this?
Using latest CI 2.2.0

I believe this solution for 2.1 should work, but I can't figure out how URI's should be translated (where to put translations) and how to remove language part from URI.

1

1 Answers

0
votes

May be I am wrong but what I understood is that you are trying to generate different urls based on active language using same words in site_url. If this is correct you can simply translate your words using language helper.

site_url(lang('blog_item_url') . '123);

And in your english langugae file.

$lang['blog_item_url']        =   "blog/item/";

And in your other langugae

$lang['blog_item_url']        =   "blogas/irasas/";

And define routes in route.php in configurations.

$route['blog/item/(:num)'] = "blog/item/$1";
$route['blogas/irasas/(:num)'] = "blog/item/$1";