Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Multilingual site in ZF3 #55

Open
willemserik opened this issue Apr 9, 2019 · 2 comments
Open

Multilingual site in ZF3 #55

willemserik opened this issue Apr 9, 2019 · 2 comments

Comments

@willemserik
Copy link

willemserik commented Apr 9, 2019

When i set the locale parameter to another value than the default value that has been defined in
module.config.php, the routing does not take this into account and uses the default value of locale instead.

Code to reproduce the issue

route definition of module.config.php:

'router' => [
        'router_class' => TranslatorAwareTreeRouteStack::class,
        'routes' => [
            'home' => [
                'type' => Segment::class,
                'options' => [
                    'route'    => '/',
                    'constraints' => [
                        'amp' => 'amp'
                    ],
                    'defaults' => [
                        'locale' => 'nl',
                        'controller' => WebsiteController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'website' => [
                'type' => Segment::class,
                'options' => [
                    'route'    => '/:locale/{home}[/:amp]',
                    'constraints' => [
                        'amp' => 'amp'
                    ],
                    'defaults' => [
                        'locale' => 'nl',
                        'controller' => WebsiteController::class,
                        'action'     => 'index',
                    ],
                ],
            ],

            'faq' => [
                'type' => Segment::class,
                'options' => [
                    'route'    => '/:locale/{faq}[/:amp]',
                    'constraints' => [
                        'amp' => 'amp'
                    ],
                    'defaults' => [
                        'locale' => 'nl',
                        'controller' => WebsiteController::class,
                        'action'     => 'faq',
                    ],
                ],
            ],

layout in which you can choose another language: website.phml I have hard coded the value to 'en':

<li>
<a href="<?= $this->url('home', ['locale' => 'en']); ?>"<?= ($this->plugin('translate')->getTranslator()->getLocale() == 'en') ? ' class="active"' : null; ?>>
<img src="<?= $this->basepath($language['data'][11]); ?>" alt="<?= $language['data'][3]; ?>" width="54" height="37" />
</a>
</li>

Expected results

I should expect that ZF knows that locale should be set to 'en' without having to send the 'locale' parameter with every link you create on the website.
When I go to the faq, i would expect that te site goes to http://mydomain.com/**en**/faq

Actual results

When I switch to en, the routing uses the default value 'nl' instead
So when I go to the faq now, the site goes to http://mydomain.com/**nl**/faq , when I have switched the language to en.

@kokspflanze
Copy link
Contributor

@willemserik check https://github.com/basz/SlmLocale develop, maybe this help you

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-router; a new issue has been opened at laminas/laminas-router#2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants