October 29, 2019, 5:02pm
I’m trying to make a 2 languages website.
I have two issues with localized slugs:
$page->url() gives me a working url but the slug is always the default language slug. $page->uri() gives me the right slug.
Localized pages (not default language) are accessible via default slug AND localized slug, which will be a SEO problem.
Does someone have an idea of the problem ?
October 29, 2019, 5:22pm
Correction : it’s always the last segment of url who is not translated.
October 29, 2019, 7:25pm
So it works with the urlForLanguage() function.
But I don’t understand why $page->urlForLanguage(‘en’) works and $page->url(‘en’) doesn’t.
I would need more context where you are using this. Normal links using
$page->url() (for example in the navigation) are correctly created within the content of the language site.
October 29, 2019, 7:30pm
In the navigation it works.
It doesn’t work when I make a foreach loop on to find subpages of current page.
And do you know why the translated page is accessible via both slugs ?
Thank you for your reactivity !
Could you please post your code example?
No, as far as I know that didn’t happen in the past, wonder if that has to do with recent changes.
October 29, 2019, 7:39pm
<?php foreach ($page->children() as $post) : ?>
<?php if($post->hasChildren()) : ?>
<a href="<?= $post->urlForLanguage($kirby->languageCode()); ?>">
<h2><?= $post->title(); ?></h2>
<?php endif; ?>
<?php endforeach; ?>
October 29, 2019, 7:41pm
Why don’t you use
$post->url() instead of making it super complicated? Or are you trying to achieve something else that I’m missing here?
October 29, 2019, 7:47pm
$post->url() doesn’t translate last segment slug.
I can’t understand how it is possible because url() function uses urlForLanguage() with the sames args in kirby/src/Cms/Page.php
October 29, 2019, 7:48pm
I just realized my version is still on 3.2.5, where the slug works alright. Let me just test with 3.3.0 rc-3
Ok, I tested with the Starterkit and 3.3.0-rc.3.
$page->url() rightly returns the correct URL.
However, the non-default language is accessible using the default language slug as well, which should not be the case. So I regard that as a bug.
Question remains, why it the URL is correctly rendered in the Starterkit but not in your context. Are you using any routes? Plugins? Models?
October 29, 2019, 7:59pm
I was, but I deleted all routes to have a cleaner code to debug.
What is crazy is that first segment url is always good, but if I have two segments, the last one is false (default language), if 3 segments, the 1st and 2nd are exact but the last one is false again.
I use some plugins, but no models.
October 29, 2019, 8:03pm
Hm, ok, I need to test this with parent pages and translated slugs
As regards the issue with the two URLs, I’ve created an issue:
08:01PM - 29 Oct 19 UTC
Describe the bug
Already done in the title
Steps to reproduce the behavior:
Create a multi-language Starterkit with two languages
Change the slug of...
October 29, 2019, 8:04pm
OK I had an old model, I deleted it and now it works lie a charm !
Do you have any idea what files should I look at to patch the second bug ?
Is it at routing level ?
October 29, 2019, 8:17pm
I’m not sure, I have a feeling it might have to do with how the new language routes for 2.5 were implemented. First I’d look into which version was the last where it worked correctly and what changes were made after that.
October 29, 2019, 9:06pm
Hm, it seems Kirby 3 never behaved differently with regard to delivering a non-default language version also under the URL of the default language.