1
votes

Is it posible in Symfony 1.2 to change routing basing on lang?

In my system there are 2 langs - EN, PL

Sample route look like this:

produkt_show:
  url:   /products/:pslug/:idslug
  param: { module: product, action: show }

What I want to achieve: I want produkt_show route to match [and generate] different url depending on the current language. So in PL my url would look like this:

 /produkty/:pslug/:idslug

It is essential those routes to have the same names. I can't change all url_for/link_to etc. calls and pass different routes names to them.

If anything is unclear -please, ask ahead.

UPDATE

according to the advice of j0k I used plugin. I choosed zxI18nRoutingPlugin. It seems to partialy work - it resolves url to right route if I write it literally in browser address input. But it still generates URLs that are not translated.

e.g.

my route:

contact_form:
  url:   /contact_form
  param: { module: contact_request, action: new}

trans unit:

        <trans-unit>
            <source>contact_form</source>
            <target>formularz-kontaktowy</target>
        </trans-unit>

generated url:

<a href="/contact_form" title="Kontakt" class="menu-contact"> Kontakt </a>

But if I type BASE_URL/formularz-kontaktowy - right action is executed.

This is my configuration from dev toolbar:

Request:

    parameterHolder:
      action: new
      module: contact_request
      sf_culture: pl
    attributeHolder:
      sf_route: 'sfRoute Object()'

User

    options:
      auto_shutdown: false
      culture: pl
      default_culture: pl_PL
      use_flash: true
      logging: '1'
      timeout: 10800
    attributeHolder:
      symfony/user/sfUser/attributes: { LAST_CATEGORY_ID_PATH_VAR: null, product_elements_on_page: 50 }
    culture: pl_PL

I just can't figure it out, I would appreciate any help, suggestions, anything, because I'm stuck with this.

UPDATE 2

factories.yml:

all:
  routing:
#    class: sfPatternRouting
#    param:
#      generate_shortest_url:            true
#      extra_parameters_as_query_string: true
    class: zxPatternI18NRouting
    param:
     generate_shortest_url:            true
     extra_parameters_as_query_string: true
     use_cultures:                     [pl, de, en, ru]   # destination cultures. Plugin looks for translations for these cultures.
     culture_into_url:                 false      # defines if culture should be always placed in url 
1

1 Answers

2
votes

There are some plugins that can handle such case (or at least gave you a way to do this on your own):

  • zxI18nRoutingPlugin

    The zxI18nRoutingPlugin extends sfPatternRouting class giving possibility to translate routes patterns static text to different languages.

  • gbI18nRoutePlugin

    Easy way to have I18N Routing.

An other option can be to add the culture inside the route, like /pl/product, /en/product, etc ..