2

I have several routes defined in Zend's Bootstrap.php that I want to translate with Zend's translate function:

$trans = new Zend_View_Helper_Translate();
$router->addRoute(
  'myroute',
  new Zend_Controller_Router_Route(':lang/'.$trans->translate('mytitle').'/',
    array(
      'module' => 'default',
      'controller' => 'index',
      'action' => 'statistics'
    )
  )
);

The helper itself seems to work (doesn't throw an exception or error) but always returns mytitle instead of the actual translation which is defined in the language file (I checked - the language files work in the view).

How can I get the translate function to work in the Bootstrap.php file?

Horen
  • 11,184
  • 11
  • 71
  • 113
  • Try doing this in a plugin instead of the bootstrap. – shiva8 Sep 07 '12 at 15:10
  • How are you passing params? check in the array. I can see the error already! I am tempted to answer but, you are JUST THERE......... REACH OUT! – Keval Domadia Sep 07 '12 at 15:12
  • @KarmicDice I don't see a problem with the parameters of the `Zend_Controller_Router_Route`. It works fine except for the translation... – Horen Sep 07 '12 at 15:19
  • @DylanSumiskum Can you explore that idea a little more, please? – Horen Sep 07 '12 at 15:20
  • http://stackoverflow.com/questions/12196330/how-to-add-variable-at-the-start-of-the-url-in-zend-framework/12197379#12197379 got the logic? – Keval Domadia Sep 07 '12 at 16:14

1 Answers1

0

Remember that you needs to load translations before you use it. Load routing translations like:

$router->setDefaultTranslator($yourTranslator);

Best how to use routing translations is adding '@' before a word you want to translate f.e.:

$router->addRoute(
  'myroute',
  new Zend_Controller_Router_Route(':lang/@mytitle/',
    array(
      'module' => 'default',
      'controller' => 'index',
      'action' => 'statistics'
    )
  )
);
Michael
  • 1,067
  • 8
  • 13