yii2-localeurls icon indicating copy to clipboard operation
yii2-localeurls copied to clipboard

fix to handle different url rules in different languages for the same action

Open albertborsos opened this issue 6 years ago • 3 comments

related to #129

I have tried to use different urls in different languages which are points to a static controller/action route.

With this modification and the following url rules it is working well. Order of the language related url rules is matter. Default language comes first then the rules for other languages.

    ...
    'urlManager' => [
        'class' => '\codemix\localeurls\UrlManager',
        'languages' => ['en', 'hu'],
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '/'           => 'frontend/default/landing',
            [
                'pattern' => '/jatek',
                'route' => 'frontend/default/game',
                'defaults' => ['language' => 'hu'],
            ],
            [
                'pattern' => '/feliratkozas',
                'route' => 'frontend/default/subscribe',
                'defaults' => ['language' => 'hu'],
            ],
            [
                'pattern' => '/game',
                'route' => 'frontend/default/game',
                'defaults' => ['language' => 'en'],
            ],
            [
                'pattern' => '/subscribe',
                'route' => 'frontend/default/subscribe',
                'defaults' => ['language' => 'en'],
            ],
        ],
    ],
    ...

I cannot manage to run tests locally, I will check this in travis.

albertborsos avatar May 31 '18 12:05 albertborsos

I currently don't have time to take a closer look here. But I'm quite surprised that there are still problems with URL rules. If you check the current set of tests you'll see, that they are quite extensive and already try to check each and every aspect. It's crucial that you get those running locally first. Your change now seems to break things.

mikehaertl avatar May 31 '18 13:05 mikehaertl

Ok, I also have no time to figure it out, why this change breaks the build. I would have written tests, but there is no dependencies for the dev environment in the composer.json. But I will check soon how Travis runs the tests.

albertborsos avatar May 31 '18 16:05 albertborsos

All you need should be phpunit. I'm using version 6 here via the global .phar file:

https://phpunit.de/getting-started/phpunit-6.html

mikehaertl avatar Jun 01 '18 06:06 mikehaertl