Welcome Guest, Not a member yet? Register   Sign In
Multilingual i18n enviroment for CodeIgniter
#1

[eluser]keevitaja[/eluser]
Hi,

i just wrote Multilingual i18n enviroment for CodeIgniter
Differences from other similar is: language segment for the default languge can be hidden by configuration.

https://github.com/keevitaja/mci-codeigniter

Demo: http://mci.vebia.ee/
#2

[eluser]Volder[/eluser]
I'm struggling with the routing problem.

I want that default index() method would be used for Category controller, e.g:

if I visit mysite.com/category/2 I want controller "Category" to be invoked, function index() with a passed argument 2.

For this I usually write in routes the rule:
Code:
$route['category/(:num)'] = "category/index/$1";

Now as I use multilingual I want also the following URL to go same path:
mysite.com/en/category/2
So I want controller Category to be invoked function index() with 2 passed as argument.

As I have in my routes file before the previous rule the following:
Code:
$route['^(en|de|fr|it)/(.+)$'] = "$2";
$route['^(en|de|fr|it)$'] = $route['default_controller'];

I assume that the rule about "index" before should give the same result as the rules in routes are executed in the order of appearence. And when the last rule reached the url is already cleaned from language component. But that's not working and I get 404 error page.
Any ideas?

PS
The whole routes now:
Code:
$route['default_controller'] = "main";
$route['404_override'] = '';

// All re-mappings must begin with '^(en|et|ru)' !!!

$route['^(en|de|fr|it)/(.+)$'] = "$2";
$route['^(en|de|fr|it)$'] = $route['default_controller'];

// readdress category and subcategory pages - to index controller
$route['category/(:num)'] = "category/index/$1";
#3

[eluser]keevitaja[/eluser]
don't have time to test it, but this should work:

Code:
$route['^((en|de|fr|it)/)?category/(.+)$'] = "category/index/$3";
#4

[eluser]Volder[/eluser]
Thanks it worked. But the idea was to put it before all the general multilingual rules, otherwise it doesn't work.

I mistakenly thought that in the routes files all the rules are evaluated one by one. But it is not so. When the engine meets the first rule that applies, it basically doesn't look at the rest.

Thanks!
#5

[eluser]umefarooq[/eluser]
really nice library, is there any way we can hide all language from url after switching to other language. same like default language.
#6

[eluser]tiborlovas[/eluser]
Hello,
I'm using a _remap function in the controller, and if there is an url without language code, I'm getting a 404_error.

For example:
localhost/mysite/en/controller - works
localhost/mysite/en/ - works
localhost/mysite/controller - doesnt' work (getting a 404 page)

Here are the __construct and _remap part of my controller:
public function __construct()
{
parent::__construct();

$this->load->language('mci');
}
public function _remap($method, $params = array())
{
$this->load->model('links');
$this->load->library('form_validation');
$this->load->helper(array('url'));
$data['i18n'] = $this->lang->mci_current();

$links['links'] = $this->links->get_links();
$data['menu'] = $this->load->view('link_list', $links, true);
if($method=="index") $method = "rolunk";
$data['title'] = lang($method.'.title');
$data['content'] = lang($method.'.content');

if (method_exists($this, $method))
{
return $this->$method($data, $params);
}
$this->error_404($data);
}

My routes.php:
$route['default_controller'] = "page";
$route['404_override'] = 'page/error404';

// URI like '/en/about' -> use controller 'about'
$route['^(hu|en|de)/(.+)$'] = "page/$2";

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

[eluser]keevitaja[/eluser]
it should be routing problem, please see my previous note:

http://ellislab.com/forums/viewthread/225196/#1038110
#8

[eluser]tiborlovas[/eluser]
I changed the next line
$route['^(hu|en|de)/(.+)$'] = "page/$2";
to
$route['^((hu|en|de)/)?(.+)$'] = "page/$2";

Still doesn't run Sad
#9

[eluser]tiborlovas[/eluser]
Great, I found the solution in this:
$route['^((hu|en|de)/)?(.+)$'] = "page/$3";

Thank you much! Smile
#10

[eluser]keevitaja[/eluser]
[quote author="umefarooq" date="1351596877"]really nice library, is there any way we can hide all language from url after switching to other language. same like default language.[/quote]

with this approach no. you have to store the language information somewhere. my solution stores the language in url, other option would be cookie or session but it is highly unrecommended due to SEO issues. one url can't have multiple content.




Theme © iAndrew 2016 - Forum software by © MyBB