ZF2 Multilanguage Navigation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ZF2 Multilanguage Navigation

Gospodinow
This post was updated on .
Hello to all , this is my fist post.

So , I am creating an app that will support many languages.

The goal is : mysite.com/en/{some route or controller/action}

I have this routes :
        'main' => array(
            'type'    => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route' => '/[:lang]',
                'constraints' => array(
                'lang' => '[a-zA-Z][a-zA-Z0-9_-]+',

                ),
                'defaults' => array(
                //'__NAMESPACE__' => 'Application\Controller',
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                    'lang'=>'en'
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]+',
                                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]+',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
                /**
                 * AUTH
                 */
                    'register' => array(
                        'type' => 'Zend\Mvc\Router\Http\Literal',
                        'options' => array(
                            'route'    => '/register',
                            'defaults' => array(
                                'controller' => 'Auth\Controller\Index',
                                'action'     => 'register',
                            ),
                        ),
                    ),
                    'login' => array(
                        'type' => 'Zend\Mvc\Router\Http\Literal',
                        'options' => array(
                            'route'    => '/login',
                            'defaults' => array(
                                'controller' => 'Auth\Controller\Index',
                                'action'     => 'login',
                            ),
                        ),
                    ),
                    'logout' => array(
                        'type' => 'Zend\Mvc\Router\Http\Literal',
                        'options' => array(
                            'route'    => '/logout',
                            'defaults' => array(
                                'controller' => 'Auth\Controller\Index',
                                'action'     => 'logout',
                            ),
                        ),
                    ),

So far so good. mysite.com/en/register is working as expected.
The problem is the navigation.
First problem : navigation dont get child_routes as routes.
Second problem : How to tell navigation to set parameter :lang to en(for example)

My navigation example:

   'navigation' => array(
        // The DefaultNavigationFactory we configured in (1) uses 'default' as the sitemap key
        'default' => array(
            // And finally, here is where we define our page hierarchy
            'register' => array(
                'label' => 'Register',
                'route' => 'register',
                'resource'=> 'register'
            ),

Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Multilanguage Navigation

Kaiuwe
Am 11.11.2012, 12:50 Uhr, schrieb Gospodinow <[hidden email]>:

> Second problem : How to tell navigation to set parameter :lang to en(for
> example)

Use: 'params' => array('foo' => 'bar'),


More examples in the docs.

http://framework.zend.com/manual/2.0/en/modules/zend.navigation.pages.html#zendnavigationpagemvc

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


Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Multilanguage Navigation

Bas Kamer
have a look at http://github.com/juriansluisman/SlmLocale

I work in progress but i think this is what might help you. locale switching is not related to route definitions

On 13 nov. 2012, at 08:19, Kaiuwe <[hidden email]> wrote:

> Am 11.11.2012, 12:50 Uhr, schrieb Gospodinow <[hidden email]>:
>
>> Second problem : How to tell navigation to set parameter :lang to en(for
>> example)
>
> Use: 'params' => array('foo' => 'bar'),
>
>
> More examples in the docs.
>
> http://framework.zend.com/manual/2.0/en/modules/zend.navigation.pages.html#zendnavigationpagemvc
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>


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


Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Multilanguage Navigation

Mohammad ZeinEddin
In reply to this post by Gospodinow
I am facing the same problems:
for the first problem even when I pass the controller and action I can't get the right URL from the child routes!
Also for the second problem I don't think that setting the :lang parameter in a static way to some language like "en" will solve the problem, there must be some way to set a default parameter for all routes of the application or for a module, may be in the onBootstrap, and setting the :lang value must be dynamic, for example get it from \Locale::getDefault() or from a URL part that represent the :lang
Any help on how to solve these issues will be appreciated.