Issues

ZF-10640: Route does not translate correctly

Issue Type: Bug Created: 2010-11-03T16:54:30.000+0000 Last Updated: 2012-11-21T14:08:17.000+0000 Status: Open Fix version(s): Reporter: Thomas Rothe (burnred) Assignee: None Tags: - Zend_Controller_Router

Related issues: Attachments:

Description

If there are mutiple Messages that have the same translation, the routers array_search method will only match with the first message in the translation array. I fixed it by checking that both strings are equal message and translation.

<pre class="highlight">
 $translation = array
        (
            'Log out' => 'Abmelden',
            'Logout' => 'Abmelden', 
        );
$logoutRoute = new Zend_Controller_Router_Route
        (
            '@'._('User').'/@'._('Logout'),
            array
            (
                'module' => 'User',
                'controller' => 'Login',
                'action' => 'logout'
            )
        );

Example will allways use the default route because of matching route as "User/Log out" instead of "User/Logout".

<pre class="highlight">
===================================================================
--- Route.php   (Revision 23291)
+++ Route.php   (Arbeitskopie)
@@ -255,8 +255,11 @@
                         $part = substr($part, 1);
                     }
 
-                    if (($originalPathPart = array_search($pathPart, $translateMessages)) !== false) {
-                        $pathPart = $originalPathPart;
+                    foreach($translateMessages as $originalPathPart => $translated) {
+                        if($translated == $pathPart && $originalPathPart == $part ) {
+                            $pathPart = $originalPathPart;
+                            break;
+                        }
                     }
                 }

Comments

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-11-03T16:58:06.000+0000

Thank you for reporting this issue.

Given that you fixed it already, could you please provide a patch containing the fix? It also really helps if you provide the relevant unittests (subtle hint).

Posted by Ben Scholzen (dasprid) on 2012-11-21T14:08:17.000+0000

I'm wondering, why do you have "logout" twice in your translation file? It seems like you didn't follow the suggested way in the manual to use a separate translator for the router.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts