URLs in multilingual sites?

Hiya,

I am currently setting up a multilingual site. The default language is English, and the other languages are German, Dutch and French.
When I add a page in the panel, I can choose the language and I can define the URL. This creates the folder in the content part of the site and within this folder I have the files depending on the number of languages. So far so good.

My problem is that when I add a German translation of this page, the URL remains in English.
Example: I created an English page “Hardy Krueger died” and added a translation in German, but the URL remains the same - it’s only the language identifier that is changing:

  • /en/blog/hardy-krueger-died
  • /de/blog/hardy-krueger-died
    But I would like to see something like
  • /en/blog/hardy-krueger-died
  • /de/blog/hardy-krueger-gestorben

Should I use $page->urlForLanguage()? If so, could someone tell me how? Do I have to define 2 URLs in the template/blueprint? Or should I write a routine that converts the page title into a URL?

Thanks in advance for any help!

All the best,
Stephan

In the page settings in the Panel you find an option Change URL which you can use to localize the page slug. If you use this option in the default language, the actual folder name is changed. For non-default languages, a slug prop is added to the content file.

Thanks for the prompt reply.

This works very well!

The only issue I have is that if I create an article only in German (second language). How could I make sure to exclude the English version (which has been created by the system, but is empty) from being listed on the site? Should I filter by $page->text() being empty?

All the best,
Stephan

1 Like

Wonderful! I will give this a try.

Thanks a mill,
Stephan

Oops, since the default language translation always exists, you probably need another condition for filtering, i.e. if the translation file is empty.

That’s why I was wondering about the filter along those lines

$page->text() is empty

(I have to check the syntax as I am not a programmer.). This should work, right?

All the best,
Stephan

You can check if a given field is empty with

$page->fieldname()->isEmpty()

You’re a star!

Thanks a million,
Stephan