2

I'm developing a multilanguage application, and use routes with translated segments. For multilingual support I created special Multilingual plugin.

To use translated segments I need set translator for Zend_Controller_Router_Route before routes init. So only possible place for this in my plugin is routeStartup method, but there is one problem here - for determine right locale I need to use properties of request (Zend_Controller_Request_Abstract), like module, controller and action names, but they are not defined yet here in routeStartup method. They are already defined, for example, in routeShutdown - but I can't set translator for route there, because it have to be done before routes init.

So what can I do:

  • can I get request properties somehow in routeStartup

  • or can I re-setup translator later in routeShutdown

P.S: there is a question with exactly the same problem Zend_Controller_Router_Route: Could not find a translator, but proposed answers is not the option for me, because I can't just retrieve language code from url with Regex, I have much more complicated code to define right language code.

Thanks.

Community
  • 1
  • 1
Vovkin
  • 436
  • 1
  • 5
  • 14
  • Could you provide us with some code you're using? – akond Feb 01 '12 at 14:42
  • As I understand there is no way to do this as I want. So I had to parse url to get not only language code, but also other necessary info, like current module, and define some rules to determine if module is multilingual, and others. It's not so flexible as I desired, but at least it works ok for now. – Vovkin Feb 08 '12 at 11:15
  • The main reason most multilingual sites start the url with a locale or language code is to circumvent this exact problem. I would definitely advice you to create a simple way of determining the requested language. This could either be by domain name (if each language is served on a different domain) or via a fixed value inside the url. You could even create an extremely simple url parser yourself and feed one or more parts to a translation lookup table to find out which language it belongs to. In any way, the language should never be defined based on the module/controller/action itself. – Pieter Mar 13 '12 at 20:13

1 Answers1

0

What about putting your code in preDispatch? That's what I personally do when I need to check if the person is logged in. Maybe you can move your code there too?

Andris
  • 5,853
  • 3
  • 28
  • 34