I've never done this so I am merely attempting to describe how I would approach the problem as if I was faced with it.
Firstly, I'd start with setting up the server so all domains point to one, single application (which I assume you already have in place).
Next, in your bootstrap.php
, when setting the language, I'd use a helper function which would define it for me, based on the URL the website is accessed at, and my bootstrap would then probably look like this:
/**
* Set the default language
*/
I18n::lang(MyApp::get_request_language_code());
I would expect my MyApp::get_request_language_code()
to return a string that would match the language code used for I18n class. This helper should also redirect the request if the url was invalid (e.g. xxx.example.com).
Then, I'd probably set the base url using $_SERVER['HTTP_HOST']
, i.e.:
Kohana::init(array(
'base_url' => $_SERVER['HTTP_HOST'],
));
Alternatively, I'd have another helper function which would return the domain prefix which I would concatenate with my actual domain, e.g.:
Kohana::init(array(
'base_url' => MyApp::get_request_language_url_prefix().'example.com',
));
By setting the domain name with language prefix in base_url
during Kohana::init() you ensure that all urls generated using either Route or URL class have appropriate language included.
And that's how I would try to solve my problem. Again, I'd like to stress that I am only attempting here to come up with a solution to a problem and the above approach has not been tested.