In my Symfony application I would like to choose the routing.yml based on the current user's culture;
'en' => routing.en.yml
'no' => routing.no.yml
and so forth.
Any suggestion to how this can be done?
Edit: I am not trying to do i18n this way - I use Symfony's built-in methods for that. I simply want "static" urls to reflect the user's language:
/en/projects/internal/project-name
/no/prosjekter/interne/prosjektnavn
/fr/baguette/champs-elysee/foux-de-fafa
Where "projects" is a module, the category "internal" and "project-name" are stored in the database.
I had the same problem with a recent website I did. I, however, did not find a proper solution and ended up making all URLs english.
I think you should have a look at the ysfDimensionsPlugin - I haven't checked it out but it might be of use to you.
I wanted to achieve the same thing. In Symfony 1.4 here is what I've did:
Created a domain => culture map in app.yml
all:
languages:
domain_map:
www.example.com: en
www.example.it: it
www.example.es: es
Created a myPatternRouting
class extending the sfPatternRouting
class myPatternRouting extends sfPatternRouting
{
public function getConfigFileName()
{
$domain_map = sfConfig::get('app_languages_domain_map');
$domain = $_SERVER['SERVER_NAME'];
$culture = isset($domain_map[$domain]) ? $domain_map[$domain] : 'en';
$routing = sprintf('config/routing.%s.yml', $culture);
return sfContext::getInstance()->getConfigCache()->checkConfig($routing, true);
}
}
Changed the factory for routing in factories.yml
all:
routing:
class: myPatternRouting
Created a config handler entry for the new pattern of the routing.yml files into config_handlers.yml
config/routing.*.yml:
class: sfRoutingConfigHandler
And then created the routing files as routing.[culture].yml
And it works :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With