Issues

ZF-10640: Route does not translate correctly

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.


 $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".


===================================================================
--- 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

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).

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.