Results 1 to 4 of 4

Thread: Make Navigation XML-file work with Language param

  1. #1
    Skatan is offline Junior Member
    Join Date
    Dec 2009
    Posts
    17

    Default Make Navigation XML-file work with Language param

    Hey!

    I found several disucssion on the topic @Google - but no real good solution.

    I developing a multi-language site:
    Ex. www.domain.com/se/nyheter
    www.domain.com/no/nyheter
    www.domain.com/en/news

    The route: /:lang/:@controller/:action/

    I'm translating the controllers by extern XML-file - and here comes the problem.
    I don't get the :lang into the XML to built the URI.
    The link is rendering without the language, ex: www.domain.com/news

    I tryed:
    <uri>:lang/news</uri>
    and
    <controller>news</controller> (the translation is workning, but lang is still empty)
    <lang>:lang</lang>
    and
    <params>
    <lang>:lang</lang>
    </params>

    Is their any good way to solve this - for a multi language site this should be basic stuff.

  2. #2
    szjani is offline Junior Member
    Join Date
    Feb 2011
    Location
    Hungary
    Posts
    22

    Default

    You don't have to put lang parameter into navigation. If the current route defined by you (request contains lang parameter) then you can simple use url view helper or directly the router's assemble method. I have created a controller plugin whick automatically adds chained routes to the router so if I create a new route (whick doesn't contain lang param) in bootstrap then later (if lang param is in url) the generated urls will contain the lang parameter. You can find it here: https://github.com/szjani/equcms/blo...n/Language.php

    To use localized parameters in url depends on language parameter is not easy. You have to put locale information into translate object in the routing process. I think you should extends the Zend_Controller_Router_Route class and in match($request) method after locale is defined put it into the router's translate object. I used it with hostname route (url doesn't contain lang param, language depends on hostname):

    class Szj_Controller_Router_HostnameRoute extends Zend_Controller_Router_Route_Hostname {

    public static function getInstance(Zend_Config $config) {
    $reqs = ($config->reqs instanceof Zend_Config) ? $config->reqs->toArray() : array();
    $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
    $scheme = (isset($config->scheme)) ? $config->scheme : null;
    return new self($config->route, $defs, $reqs, $scheme);
    }

    public function match($request) {
    $res = parent::match($request);
    if ($res) {
    $locale = new Zend_Locale($this->getDefault('lang'));
    Zend_Registry::set('Zend_Locale', $locale);
    Zend_Registry::get('Zend_Translate')->setLocale($locale);
    Zend_Registry::get('Zend_Translate_Url')->setLocale($locale);
    Zend_Controller_Router_Route::setDefaultLocale($lo cale);
    }
    return $res;
    }

    }
    Last edited by szjani; 03-15-2011 at 08:48 AM.

  3. #3
    Skatan is offline Junior Member
    Join Date
    Dec 2009
    Posts
    17

    Default

    Thx for your reply szjani!
    I posted this at 3 forums, you are to only one replying

    So where to you implement the Language.php, as a plugin in the Bootstrap file before/after the standard routes..?

  4. #4
    szjani is offline Junior Member
    Join Date
    Feb 2011
    Location
    Hungary
    Posts
    22

    Default

    You can put your routes into router anywhere and anytime in the bootstrap process because the Language plugin will work after it. The plugin also adds the default routes into router. The plugin registration is here: https://github.com/szjani/equcms/blo.../Bootstrap.php at line 36. I think you should change line 15 in the Language.php to instantiate your own route and move the language define part from routeShutdown() to your router's match() method.
    Probably I will try to implement this feature on next week because I had operation a few days ago. Sorry for my bad english.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •