In my navigation, I have a language menu. On some pages, the links do not work and lead to Home. Why is this happening?
<ul>
<?php foreach ($kirby->languages() as $language): ?>
<li><a href="<?= $language->url() ?>"><?= $language->name() ?></a></li>
<?php endforeach ?>
</ul>
Do the translations of pages that redirect to home exist? What is the URL that is printed for those links? Is language detection enabled?
Could you show us your language setup (config, language files).
1 Like
Thank you. Yes, the translations do exist. Their language links lead to mywebsite/language
.
My config.php:
<?php
return [
'routes' => [
[
'pattern' => 'sitemap.xml',
'action' => function() {
$pages = site()->pages()->index();
$ignore = kirby()->option('sitemap.ignore', ['error', 'shows']);
$content = snippet('sitemap', compact('pages', 'ignore'), true);
return new Kirby\Cms\Response($content, 'application/xml');
}
],
[
'pattern' => 'sitemap',
'action' => function() {
return go('sitemap.xml', 302);
}
],
[
'pattern' => '/',
'action' => function() {
return page('shows')->children()->listed()->shuffle()->first();
}
]
],
'debug' => true,
'languages' => true
];
My de.php:
<?php
return [
'code' => 'de',
'default' => true,
'direction' => 'ltr',
'locale' => [
'LC_ALL' => 'de_DE'
],
'name' => 'Deutsch',
'translations' => [
],
'url' => NULL
];
My en.php:
<?php
return [
'code' => 'en',
'default' => false,
'direction' => 'ltr',
'locale' => [
'LC_ALL' => 'en_US'
],
'name' => 'English',
'translations' => [
],
'url' => NULL
];
I got it. I changed my template code to:
<ul>
<?php foreach ($kirby->languages() as $language): ?>
<li><a href="<?= $page->url($language->code()) ?>"><?= $language->name() ?></a></li>
<?php endforeach ?>
</ul>
See the link below for further information on it: