Language issue with localized slugs

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

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

Which Kirby version?

The las RC (3.3.0 Rc3)

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.

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.

<?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; ?>

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?

$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

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?

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.

Hm, ok, I need to test this with parent pages and translated slugs :walking_woman:

As regards the issue with the two URLs, I’ve created an issue:

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 ?

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.

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.