Allthough page title can be translated in multi language setting, the languageCode can’t be given to function $page->title(). So only default language title is returned. This could be fixed like this:
public function title(string $languageCode = null)
{
return $this->content($languageCode)->get('title')->or($this->slug());
}
Futhermore $page->uri($languageCode) doesn’t prefix the languageCode to the page-uri.
Yes, and that is intended, because the language code is not part of the URI.
Why do you need to pass the language code to the title method? If you need that, you can get the language specific version of the title by passing the language code to content()
as done in the code inside your title method.
The title behaves just as any other field here, you can’t pass the language code to $page->text()
etc. either, you always have to go through the content object.
URI: OK, I misunderstood “except that it will be translated in multi-language setups” here https://getkirby.com/docs/reference/objects/page/uri. The language is prefixed like de/home
by the router and I expected this to be the “translation”.
Title: I think if $page->title()
exists, it should to be symmetrically to $page->content()->title()
.
That means that if page slug is translated, the URI returns the translated slugs.
I don’t quite agree with you on this one, because of what I wrote above (that the title would then work differently from the other fields), but please feel free to create an issue in the ideas repo. Apart from that, you can create a custom page method or a page model to achieve what you want.
The title is automatically translated if a translated title exists (provided you are visiting the current language). What is your use case? Is that in a SPA context?
You can translate the contents e.g. of the title field, if you want or need in a multilanguage installation of Kirby.
And you can translate the slug…
But you need what @texnixe wrote, you need ONE different “url” for every language in the language files.