sly31
October 29, 2019, 5:02pm
1
Hi,
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 ?
Thanks
sly31
October 29, 2019, 5:22pm
2
Correction : it’s always the last segment of url who is not translated.
Exemple :
mysite.com/tranlated/not-translated
mysite.com/tranlated/tranlated/not-translated
sly31
October 29, 2019, 7:25pm
5
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.
sly31
October 29, 2019, 7:30pm
7
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.
sly31
October 29, 2019, 7:39pm
9
<?php foreach ($page->children() as $post) : ?>
<?php if($post->hasChildren()) : ?>
<article class="post">
<a href="<?= $post->urlForLanguage($kirby->languageCode()); ?>">
<div class="post-title">
<h2><?= $post->title(); ?></h2>
</div>
</a>
</article>
<?php endif; ?>
<?php endforeach; ?>
texnixe
October 29, 2019, 7:41pm
10
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?
sly31
October 29, 2019, 7:47pm
11
$post->url() doesn’t translate last segment slug.
$post->urlForLanguage() does.
I can’t understand how it is possible because url() function uses urlForLanguage() with the sames args in kirby/src/Cms/Page.php
texnixe
October 29, 2019, 7:48pm
12
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?
sly31
October 29, 2019, 7:59pm
13
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.
texnixe
October 29, 2019, 8:03pm
14
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:
opened 08:01PM - 29 Oct 19 UTC
Describe the bug
Already done in the title
To Reproduce
Steps to reproduce the behavior:
Create a multi-language Starterkit with two languages
Change the slug of...
sly31
October 29, 2019, 8:04pm
15
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 ?
texnixe
October 29, 2019, 8:17pm
16
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.
texnixe
October 29, 2019, 9:06pm
17
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.