views:

483

answers:

1

Hello there,

I'm having some difficulties with the combination of Zend_Navigation, Zend_Translate and the routing needed.

My site navigation is done through Zend_Navigation based on and XML file. I've now added translation to the site based on Zend_Translate and added to following change of routing to the bootstrap:

protected function _initRoutes()

    $config = new Zend_Config($this->getOptions());
    $languages = array_keys($config->languages->toArray());
    $zl = new Zend_Locale();
    $lang = in_array($zl->getLanguage(), $languages)
                  ? $zl->getLanguage() : 'en';

    $zfc = Zend_Controller_Front::getInstance();


    // add language to default route
    $route = new Zend_Controller_Router_Route(
            ':lang/:module/:controller/:action/*',
      array('controller'=>'index',
                'action' => 'index',
                'module'=>'default',
                'lang'=>$lang));

    $router = $zfc->getRouter();
    $router->addRoute('default', $route);
    $zfc->setRouter($router);

I've then created a View_Helper with a preDispatc method:

    $language = $request->getParam('lang','');

 if ($language !== 'en' && $language !== 'da')
     $request->setParam('lang','en');

 $language = $request->getParam('lang');
 if ($language == 'en')
     $locale = 'en_EN';
 else
     $locale = 'da_DK';

 $zl = new Zend_Locale();
 $zl->setLocale($locale);
 Zend_Registry::set('Zend_Locale', $zl);

 $translate = new Zend_Translate('csv', APPLICATION_PATH . '/configs/language/'. $language . '.csv' , $language);
 Zend_Registry::set('Zend_Translate', $translate);

Now when I go to: "site/en/module/controller/action" it works fine.

When I go to: "site/da/module/controller/action" the translation works fine, but my links from Zend_Navigation is pointing to the default 'en' language link "site/en/module2/controller2/"

I cant figure out to know that your at /da/ language. Any help would be appriciated.

Kind regards,

Morten

A: 

Did you ever get an answer to this? I'm stuck in the exact same sort of situation lol!

Ryan
You should add this as a comment.
sims