title: Zf2 Locale in URL and $this->url
body: <p>I am developing a web app on ZF2 Skeleton App base. I have played with lot of options but failed to get final headway.</p>
  
  <p>I need to route the url as under:</p>
  
  <pre><code>http://myapp/
  http://myapp/en/album
  </code></pre>
  
  <p>to AlbumController/indexAction. Also, links need to work as:</p>
  
  <pre><code>http://myapp/en/album/edit/1
  http://myapp/en/album/delete/1
  </code></pre>
  
  <p><strong>The code generates correct URLs but on clicking returns "404" error</strong></p>
  
  <p>My Application/module.config.php is as under:</p>
  
  <hr>
  
  <pre><code>return array (
          'router' =&gt; array (
                  'routes' =&gt; array (
                          'home' =&gt; array (
                                  'type' =&gt; 'Zend\Mvc\Router\Http\Literal',
                                  'options' =&gt; array (
                                          'route' =&gt; '/',
                                          'defaults' =&gt; array (
                                                  'controller' =&gt; 'Album\Controller\Album',
                                                  'action' =&gt; 'index',
                                                  'lang'     =&gt; 'en',
                                          ) 
                                  ) 
                          ),
                          'application' =&gt; array (
                                  'type' =&gt; 'Literal',
                                  'options' =&gt; array (
                                          'route' =&gt; '/application',
                                          'defaults' =&gt; array (
                                                  '__NAMESPACE__' =&gt; 'Application\Controller',
                                                  'controller' =&gt; 'Index',
                                                  'action' =&gt; 'index' 
                                          ) 
                                  ),
                                  'may_terminate' =&gt; true,
                                  'child_routes' =&gt; array (
                                          'default' =&gt; array (
                                                  'type' =&gt; 'Segment',
                                                  'options' =&gt; array (
                                                          'route' =&gt; '[:lang[/album[/:action[/:id]]]]',
                                                          'constraints' =&gt; array (
                                                                  'lang'     =&gt; '[a-z]{2}',
                                                                  'action' =&gt; '[a-zA-Z][a-zA-Z0-9_-]*',
                                                                  'id' =&gt; '[0-9]+'
                                                          ),
                                                          'defaults' =&gt; array (
                                                                  'controller' =&gt; 'Album\Controller\Album',
                                                                  'action' =&gt; 'index',
                                                                  'lang'     =&gt; 'en',
                                                          )
                                                  ) 
                                          ) 
                                  ) 
                          ) 
                  ) 
          ),
          'service_manager' =&gt; array (
                  'factories' =&gt; array (
                          'translator' =&gt; 'Zend\I18n\Translator\TranslatorServiceFactory' 
                  ) 
          ),
          'translator' =&gt; array (
                  'locale' =&gt; 'en_US',
                  'translation_file_patterns' =&gt; array (
                          array (
                                  'type' =&gt; 'gettext',
                                  'base_dir' =&gt; __DIR__ . '/../language',
                                  'pattern' =&gt; '%s.mo' 
                          ) 
                  ) 
          ),
          'controllers' =&gt; array (
                  'invokables' =&gt; array (
                          'Application\Controller\Index' =&gt; 'Application\Controller\IndexController' 
                  ) 
          ),
          'view_manager' =&gt; array (
                  'display_not_found_reason' =&gt; true,
                  'display_exceptions' =&gt; true,
                  'doctype' =&gt; 'HTML5',
                  'not_found_template' =&gt; 'error/404',
                  'exception_template' =&gt; 'error/index',
                  'template_map' =&gt; array (
                          'layout/layout' =&gt; __DIR__ . '/../view/layout/layout.phtml',
                          'application/index/index' =&gt; __DIR__ . '/../view/application/index/index.phtml',
                          'error/404' =&gt; __DIR__ . '/../view/error/404.phtml',
                          'error/index' =&gt; __DIR__ . '/../view/error/index.phtml' 
                  ),
                  'template_path_stack' =&gt; array (
                          __DIR__ . '/../view' 
                  ) 
          ) 
  );
  </code></pre>
  
  <hr>
  
  <p>My Album/module.config.php has the following router:</p>
  
  <hr>
  
  <pre><code>'router' =&gt; array (
                  'routes' =&gt; array (
                          'album' =&gt; array (
                                  'type' =&gt; 'segment',
                                  'options' =&gt; array (
                                          'route' =&gt; '[:lang[/album[/:action[/:id]]]]',
                                          'constraints' =&gt; array (
                                                  'lang'     =&gt; '[a-z]{2}',
                                                  'action' =&gt; '[a-zA-Z][a-zA-Z0-9_-]*',
                                                  'id' =&gt; '[0-9]+'
                                          ),
                                          'defaults' =&gt; array (
                                                  'controller' =&gt; 'Album\Controller\Album',
                                                  'action' =&gt; 'index', 
                                                  'lang'     =&gt; 'en',
                                          )
                                  ),
                          )
                  )
          ), 
  </code></pre>
  
  <hr>
  
  <p>////////////////////////////////////////////////////////////////////////////////////////
  // Now this works fine.</p>
  
  <p>Also, when I do call the  $this->url('album',array('action'=>'edit', 'id' => $album->id)); in view file (.phtml), it does'nt return proper url as expected:</p>
  
  <p><a href="http://www.myapp.com/en/edit/id/1" rel="nofollow">http://www.myapp.com/en/edit/id/1</a></p>
  
  <p>////////////////////////////////////////////////////////////////////////////////////////
  //Corrected code works for URL
  $this->url('album', array('action'=>'edit', 'id' => $album->id))
  ///////////////////////////////////////////////////////////////////////////////////////</p>
  
  <p>Appreciate your help in advance.</p>