1

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 
tshepang
  • 12,111
  • 21
  • 91
  • 136
tiriana
  • 668
  • 1
  • 7
  • 24

1 Answers1

2

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 ..

Community
  • 1
  • 1
j0k
  • 22,600
  • 28
  • 79
  • 90
  • That's just sooo cool. Thanks. I knew about the last option before, but it not the solution our customer would like. I'll try to use plugins and write in some time if they worked. – tiriana Aug 09 '13 at 10:03
  • I used zxI18nRoutingPlugin, and it seems to work partially, but... it still generates URLs that are not transleted. It resolves translated route correlcty if I type it in the address input literally. I'll put an example to my question in a moment. – tiriana Aug 20 '13 at 07:46
  • How to you generate url? What's the value of `cultures_into_url`? What's the value of `use_cultures` ? – j0k Aug 20 '13 at 11:43
  • See my update for my full routing conf. `use_cultures: [pl, de, en, ru]` , `cultures_into_url: false` – tiriana Aug 21 '13 at 09:22