Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing routing.yml based on user culture?

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.

like image 507
Erland Wiencke Avatar asked Mar 01 '23 02:03

Erland Wiencke


2 Answers

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.

like image 84
phidah Avatar answered Mar 05 '23 15:03

phidah


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 :)

like image 26
jkrnak Avatar answered Mar 05 '23 17:03

jkrnak