Choosing routing.yml based on user culture?

In my Symfony application, I would like to select routing.yml based on the current user culture;

'en' => routing.en.yml 'no' => routing.no.yml 

etc.

Any suggestion on how to do this?

Edit: I'm not trying to make i18n this way - I use Symfony's built-in methods for this. I just want the β€œstatic” URLs to display 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 categories "internal" and "project name" are stored in the database.

+4
source share
5 answers

I had the same issue with a recent site that I made. However, I did not find the right solution and eventually made all the URLs English.

I think you should take a look at ysfDimensionsPlugin - I have not checked this but it may come in handy for you.

+4
source

I wanted to do the same. In Symfony 1.4, this is what I did:

Created a domain map => culture in app.yml

 all: languages: domain_map: www.example.com: en www.example.it: it www.example.es: es 

The myPatternRouting class has been myPatternRouting that extends 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 factory for routing in factories.yml

 all: routing: class: myPatternRouting 

Created a configuration handler entry for the new routing.yml file template in config_handlers.yml

 config/routing.*.yml: class: sfRoutingConfigHandler 

And then create the routing files as routing.[culture].yml

And it works :)

+3
source

There may be no way to do this without dynamically loading routing using a filter. You can override sfPatternRouting and write a custom loadConfiguration function, but you need to know the user culture when the routing class is created *. If you go through the filter route, simply load the appropriate routing file into the first half of the filter chain.

* If you are following this route, make sure you also replace factories.yml.

+1
source

I'm not sure if this is the right way to implement i18n. What goal are you trying to achieve with this solution? Symfony has all the built-in i18n tools, and you should have no problems using integrated methods.

Take a look here: http://www.symfony-project.org/book/1_2/13-I18n-and-L10n and scroll down to the "Culture in URL" field. It should solve your problem.

0
source

I am using this plugin . My routes look like this:

 news_ro: url: /ro/stiri/:slug requirements: { sf_culture: (?:ro), page: \d+ } param: { module: news, action: index, page: 1, sf_culture: ro} news_en: url: /en/news/:slug requirements: { sf_culture: (?:en), page: \d+ } param: { module: news, action: index, page: 1, sf_culture: en } 

I take slug basen to the current culture.

0
source

All Articles