Relhek
March 29, 2019, 10:30am
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
Hey @Relhek , welcome to our forum!
Are you using the latest Kirby release 3.1.1?
7pdf
March 29, 2019, 2:18pm
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.
@7pdf thanks for the issue link, that was what I was looking for when I got distracted…
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.
7pdf
March 29, 2019, 4:17pm
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…
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);
}
]
]