Crossdomain Multilanguage not working

#1

Hey there,

first of all. You have a great product.

I’m developing a site for a customer and he has a domain example.de and example.info.

I have set the urls in the language files to them.
exampleinfo shall link to english language.
examplede to german.

Auto detect language is disabled.

Switching to english or opening the example.info domain always redirects to the example.de and language does not change.

Thanks in advance

0 Likes

#2

Hey @Relhek, welcome to our forum!

Are you using the latest Kirby release 3.1.1?

0 Likes

#3

It seems that this bug from January https://github.com/getkirby/kirby/issues/1382 is still also available in 3.1.1 … I have tried out the last version under MAMP and could reproduce the bug again… We are looking for a fix since January here.

0 Likes

#4

@7pdf thanks for the issue link, that was what I was looking for when I got distracted…

0 Likes

#5

I just tested locally if the issue could probably be worked around until a more solid solution is found and came up with this route:

    'routes' => [
        [
            'pattern' => '(:all)',
            'action' => function($uri) {
                $host = Url::host();
                
                $page = page($uri);
                if(!$page && $uri == '') $page = page('home');
                if(!$page) $page = page('error');

                if($host === 'de.test') {
                    return site()->visit($page, 'de');
                } else {
                    return site()->visit($page, 'en');
                }
            }
        ]
    ]

which works at least in my Mamp environment.

English language setup:

<?php

return array (
  'code' => 'en',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'en',
  'name' => 'English',
  'url' => 'http://en.test'
);

German language setup:

<?php

return array (
  'code' => 'de',
  'default' => false,
  'direction' => 'ltr',
  'locale' => 'de_DE',
  'name' => 'Deutsch',
  'url' => 'http://de.test'
);

Might have side effects, though, especially when setting up other routes.

@7pdf Looks like you made it work on your website?

First downside of this approach: doesn’t work - at least not like above - when using slugs for non-default pages.

0 Likes

#6

Still on the last kirby 2 version. You’re idea seems to be working but not in any case so it can be only a workaround. We’re having the hope that Bastian will fix this issue in the next release 3.1.2 … After that we will test all to hopefully can switch finally to version 3…

0 Likes

#7

Yep, as I said, I’m not trying to sell that as a solution, it’s just a workaround for anyone who needs a quick fix.

Here is a revised version that works with language specific slugs:

    'routes' => [
        [
            'pattern' => '(:all)',
            'action' => function($uri) {
                $host = Url::host();
          

                if($host == 'de.test') {
                    site()->visit(page('home'), 'de');
                    $lang = 'de';
                } else {
                    site()->visit(page('home'), 'en');
                    $lang = 'en';     
                }
                $page = page($uri);
                if(!$page && $uri == '') $page = page('home');
                if(!$page) $page = page('error');
                return site()->visit($page, $lang);
            }
        ]
    ]
0 Likes

#8

Closing this because duplicate of Using different domains for each language does not work

0 Likes