Skip to content

Conversation

@coolmic
Copy link
Contributor

@coolmic coolmic commented Oct 24, 2013

I have translated part in url :

/fr/contacter-nous
/en/contact-us

Config :

'contact' => array(
    'type' => 'Segment',
    'options' => array(
        'route' => '/{contact}',
        'defaults' => array(
            'controller' => 'App\Controller\Contact',
            'action' => 'index',
        ),
    ),
),

If I want to generate the url, I have to use do :

// I am currently in /fr/contacter-nous

$this->localeUrl('en'); // return /en/contacter-nous

$this->localeUrl('en', null, array(), array('locale' => 'en')); // return /en/contact-us

Why don't auto set 'locale' to 'en' ?
Like this, event LocaleMenu is usable.

@juriansluiman
Copy link
Collaborator

I haven't used translated routes, but it's a fair point to set to locale for assembling as well. We can keep this issue here until we've a PR for it.

Can you make the PR or not? Otherwise one of use has to find time to implement the feature and test it.

@coolmic
Copy link
Contributor Author

coolmic commented Oct 24, 2013

Yes I can.

@coolmic
Copy link
Contributor Author

coolmic commented Oct 24, 2013

There is still no phpunit test for LocaleUrl.

If you want to test it, this is how I configured :

// in router config
array(
    'router' => array(
        'router_class' => 'Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack',
        'routes' => array(
            'contact' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/{contact}',
                    'defaults' => array(
                        'controller' => 'App\Controller\Contact',
                        'action' => 'index',
                    ),
                ),
            ),
        ),
    )
);


// in Module
    public function getServiceConfig()
    {
        return array(
            'initializers' => array(
                function ($instance, ServiceLocatorInterface $serviceLocator) {
                    if ($instance instanceof TranslatorAwareTreeRouteStack) {
                        $translator = $serviceLocator->get('MvcTranslator'); 
                        $instance->setTranslator($translator);
                        $instance->setTranslatorTextDomain('router');
                    }
                }
            )
        );
    }

    public function onBootstrap(EventInterface $e)
    {
        if (!($e instanceof MvcEvent)) {
            return;
        }

        $serviceLocator = $e->getApplication()->getServiceManager();

        $translator = $serviceLocator->get('MvcTranslator');
        $translator->setLocale(\Locale::getDefault());


    }

@juriansluiman
Copy link
Collaborator

Looks cool. I know there are no tests yet for this part of the ,odule... However, patch looks sane :)

juriansluiman pushed a commit that referenced this pull request Oct 24, 2013
…e-url

Auto-specify locale options in View/Helper/LocaleUrl
@juriansluiman juriansluiman merged commit f7b5af2 into basz:master Oct 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants