How to change language slug when changing language?

Let’s say I’m on page

I want to click a link to change site language and be redirected to:
The french example in this case would use slug: bonjour

Is it possible to achieve this somehow?

Normally you use the built-in multi-language features. So your URL would be /en/blog/hello (or /blog/en/hello depending on your folder structure) for English and /fr/blog/hello for French.

it’s complicated … see this

what you can do is to have different folder structure /blog/hello and blog/bonjour and have visible: false published: false setting for documents in the languages that are not available in a particular folder.
It’s painful and at the same time it does not solve the problem to change from one language to another, that has to be set manually.

Perhaps I’m just not understanding the concern, but this is not that complicated. You simply create multiple page files with different language codes. Grav sees the translation is available. It’s trivial to add to the template code that checks for the translation and displays a link to the other language code if it’s available. Things may get slightly more interesting if you really want to localize the URLs as well, but you don’t have to do that.

Hey guys, thanks for your answers. I actually had the same approach as @tidivoit posted above. From what I understand, having properly localised URLs would be better for SEO. But for now it seems Grav isn’t capable of creating that URL based on slug value in frontmatter. So while my setup works fine, the second language has English titled post URLs (because of folder names, afaik). Which makes me wonder - why do we even have that slug setting in the first place. Maybe I still don’t understand something here :confused:

Ok, it seems that slugs are working fine. Problem is only relevant when changing a language while on a single post page. Anyone knows if it’s possible to get a ling to specific language’s slug url for a particular link?

This looks more a problem in how the LangSwitcher plugin builds the page URLs. It should find the correct slug of every folder level (not just the last one, the actual page, but also the parents). In your case, the blog folder.

Btw, the langswitcher uses the ‘raw route’ and not slugs for each language. This is because Grav does not actually know about the other language pages. It only knows about the current language and that there are other languages supported. This is for performance reasons.