views:

322

answers:

4

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.

+1  A: 

There may not be a way to do this without dynamically loading the routing using a filter. You could override sfPatternRouting and write a custom loadConfiguration function, but you'd need to know the user's culture when the routing class gets instantiated*. If you go the filter route, simply load the proper routing file on the first half of the filter chain.

*If you go this route, make sure you change factories.yml as well.

jeremy
A: 

I am not sure this is a correct way to implement i18n. What goal are you trying to achieve with this solution? Symfony has all i18n tools built-in and you should have no problems to use integrated ways.

Look here: http://www.symfony-project.org/book/1%5F2/13-I18n-and-L10n and scroll down to the "Culture in the URL" box. It should solve your problem.

FractalizeR
@FractalizeR: Thanks for your reply. However, I am not trying to implement i18n this way; for tha, I use Symfony's built in i18n - both in terms of database content and "hardcoded" values (e.g. labels stored in xliff etc.).I want to be able to have static urls, based on my modules. The module "projects" in english would be "prosjekter" in norwegian.An example:/en/projects/internal/project-namebecomes/no/prosjekter/interne/prosjektnavnand/fr/baguette/champs-elysee/foux-de-fafa
Erland Wiencke
+3  A: 

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.

phidah
Thanks a bunch! The plugin seems interesting. I will look into it.
Erland Wiencke
Please tell us the results of looking into it ;) We all want to know for the question is really interesting.
FractalizeR
Hi all, it turns out that ysfDimensionsPlugin requires APC and (apparently) only supports Symfony 1.1. Thus, I haven't been able to check it out. Will keep on digging.
Erland Wiencke
A: 

i use 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 the slug basen on the current culture.

Daniel