tags:

views:

69

answers:

2

Let's say I want to make a system which can afford a multilingual web project. The system will consist of the modules that are put in Kohana's standard directory modules. Let's say that the standard access to the particular language can be done via lang parameter (i.e. somesite.com/en/somepage). The problem is that I have to repeat myself in defining my modules routes prepending each uri with (<lang>). Is there any way to avoid that? I thought about a separate language route declaration (for example in bootstap.php file), but I guess it won't solve the problem.

It's all about Kohana 3. Thanks to all.

UPDATE: I think that the way suggested by The Pixel Developer is what one need if some part of the rule in route repeats everywhere.

+1  A: 

Move up a level and extend the route class.

http://github.com/kohana/core/blob/master/classes/kohana/route.php#L69

public static function set($name, $uri, array $regex = NULL)
{
    return parent::set($name, '(<lang>)'.$uri, $regex);
}

Not tested, but that's the general idea.

The Pixel Developer
hm. Interesting idea. Why I didn't think about it. I'll try it later and update the question.
franzose
No problem. Don't forget to accept the answer if it's correct. People will be more likely to help in the future if you have a high accept ratio.
The Pixel Developer
Of course, I'll definitely do it right after I'll have tried it!
franzose
A: 

If lang is required in route, why don't you just put it in the default route? Surely that's the easiest way to go about. Something like:

Route::set('default', '<lang>(<controller>(/<action>(/<id>)))', array('lang'=> '[a-z]{2}'))
->defaults(array(
    'controller' => 'somepage',
    'action'     => 'index',
    'lang'       => 'en',
));

Where lang is any 2 letters alphabets which defaults to 'en'.

SyaZ
Maybe I don't quite understand the routing system, but in such a case I'll have to put <lang> in each next route I'll define, shan't I? Now I can't verify all the ways I have already got here, but I guess that The Pixel Developer is right... In next several hours I'll try.
franzose
Yes you will need to put it for every routes. See this page for examples doing it more elegantly: http://kerkness.ca/wiki/doku.php?id=routing:multi-language_with_a_route
SyaZ

related questions