Hi again,

with this little test script I just figured out that the
TranslatorAwareTreeRouteStack is not working as I expected. It really
seems only to work when I want to translate literal segments in a route
and it cannot translate a placeholder.

I need to find another solution to solve my problems with international
routes...

----------------------------------------------------------------------
use Zend\Debug\Debug;
use Zend\Http\Request;
use Zend\Mvc\I18n\Translator;
use Zend\Mvc\Router\Http\Literal;
use Zend\Mvc\Router\Http\Part;
use Zend\Mvc\Router\Http\Segment;
use Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack;
use Zend\Mvc\Router\RoutePluginManager;

$translate = new Translator();
$translate->addTranslationFile(
    'PhpArray',
    APPLICATION_ROOT . '/module/User/language/router.de.php'
);

Debug::dump($translate->translate('registrieren'));
Debug::dump($translate->translate('action'));

$routeBase = Literal::factory(array(
    'route' => '/user',
    'defaults' => array(
        'controller' => 'user',
        'action'     => 'index'
    ),
));

$routeChild = Segment::factory(array(
    'route' => '/{action}',
    'constraints' => array(
        'action'     => '[a-zA-Z][a-zA-Z0-9_-]+',
    ),
    'defaults' => array(
        'action'     => 'index',
    ),
));

$routePart = Part::factory(array(
    'route'         => $routeBase,
    'route_plugins' => new RoutePluginManager(),
    'may_terminate' => true,
    'child_routes'  => array(
        'segment-route' => $routeChild,
    ),
));

$routeStack = new TranslatorAwareTreeRouteStack();
$routeStack->setTranslator($translate);
$routeStack->addRoute('user', $routePart);

$urlList = array(
    'http://www.luigis-pizza.de/user',
    'http://www.luigis-pizza.de/user/registrieren',
    'http://www.luigis-pizza.de/user/register',
    'http://www.luigis-pizza.de/user/aktion',
    'http://www.luigis-pizza.de/user/action',
);

$request = new Request();

foreach ($urlList as $url) {
    $request->setUri($url);

    $match = $routeStack->match($request);

    if ($match === null) {
        echo 'URL ' . $url . ' is valid<hr />';
    } else {
        echo 'URL ' . $url . ' is valid<br />';
        echo 'Match route "' . $match->getMatchedRouteName() . '"<br>';
        foreach($match->getParams() as $key => $value) {
            echo $key . ' => ' . $value . '<br />';
        }
        echo '<hr />';
    }
}
----------------------------------------------------------------------
// APPLICATION_ROOT . '/module/User/language/router.de.php'

return array(
    'registrieren'  => 'register',
    'action'        => 'aktion',
);

----------------------------------------------------------------------

Thanks and best regards,

Ralf

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to