Multi-language pages rounting

Hi, I am new to the forum and Grav itself, but I liked so much the project that I decided to start renewing my website with it.
I looked into the documentation as well as the Cookbook and some issues tracking regarding Multi Language topic, but I would need the guide of an expert user to correctly set it up.

What I want to achieve: I have a blog in Italian and I would like to translate only some pages in English (meaning not all pages will have a translation into English).

Where I am so far:

  • Site domain is unique (.com)
  • I use latest version of Grav and Multi-Language plugin
  • I created a child theme for Clean Blog theme to be able to override some settings without compromising the original code during updates.
  • In config.system.yaml I set up the languages supported “it” and “en” (ordered as Italian is my preferred language)
  • In the same config.system.yaml file the home alias is /home and is set to true the hide_in_urls parameter
  • my current folder structure is as per the original theme
01.home
  /classifica-avulsa
    item.it.md (slug: cla ssifica-avulsa-con-excel) or should I use simply item.md
    item.en.md (slug: tie-breaker-with-excel)

I placed a notice paragraph at the top of each page with a link to switch language

The code in the item.it.md is:

!! read this article in [**English**](../en/tie-breaker-with-excel "Leggi in inglese")

Should I not put the “…/” the link will redirect to .com/classifica-avulsa-con-excel/en/tie-breaker-with-excel
With the above works fine

The code in the item.en.md is:

!! Leggi questo articolo in [**Italiano**](.com/classifica-avulsa-con-excel "Read in Italian")

I cannot get it to work with slug or routing. The current workaround I don’t like is to put the Italian url version directly as the link

Can someone point me in the right direction what is the best practice to use in this case and where am I making a mistake?

Thank you very much!
Jack

Best thing is to use the Langswitcher plugin https://github.com/getgrav/grav-plugin-langswitcher , and eventually adding the Twig it uses into your own theme, in the place you want.

Thank you Flavio, I will make some tests with this plugin and report here the result. Hopefully it will help some one with the same “issue”.

Jack

Hi Flavio, I did some test and it seems to be working except for some routing issues:

Could you please take a look at this page.
At the top there is the new langswitcher plugin function inserted.

Problem #1
from the Italian page, if you hover the English link, it will redirect you to the right page but with “en/home/italian-page-slug”. If you click again it will change to the correct “en/english-page-slug” hiding /home as well.

Same thing when you are in the English page and try to go the Italian one. First click will redirect you to “/home/italian-page-slug”. Second click will take away the /home as it should be.

Problem #2
I have not tested it as I don’t have another article, but do you know if the plugin html output is showing only when a translation is found and hiding itself if there’s no translation available? (Basically adding the switcher only if the article has a translation).

Any comment would be appreciated.

Thanks
Jack

have you set your default language in config?

Have a look in Configuration > Site > default language, and set it to “it”.

This should mean you have URL’s like http://www.thejackhome.com/it/classifica-avulsa-con-exceland http://www.thejackhome.com/en/classifica-avulsa-con-excel

If no english page exists then it will default to the Italian version.

Hi alr3id.
It is already set so. The output of my /user/config/site.yaml

default_lang: it

It seemed like a problem of cache after enabling the “redirect default route”.
Now, although the link hovering is wrong, landing page is the correct one, with the correct slug.
Only thing I don’t like is that, from your explanations, I understood I will not be able to avoid showing the language switcher if a page is in Italian only (why should you have the option to change language if the page is in one language only anyway). But I believe this is not easy to implement.

If you don’t want it to show, then i am sure you could have a flag to hide it if there is only one language.

I was only going by what i could see looking at your site. I am dealing with multiple languages (en, fr, de, it, es) and each one has a page under the /{country} so my about looks like this…

domain.com/en/about
domain.com/fr/about
domain.com/de/about
domain.com/it/about

And i only have 1 page, I have been simply saving the pages as their relevant language. Not sure if that helps, but it seems Grav has done most of the work itself saving me a whole shed load of time :smiley:

Thanks alr3id for sharing.

I will study a way to flag and hide it if there is only one language using this nice plugin.

For now and for my needs, I found a way to correctly show it by adding in the item.it.md the directory relative link “…/”:

!! read this article in [**English**](../en/tie-breaker-with-excel "Leggi in inglese")

On the item.en.md I used the absolute link “/…/”:

!! Leggi questo articolo in [**Italiano**](/../classifica-avulsa-con-excel "Read in Italian")

This way I achieve the expected results without any /home or /en/home or wrong links when hovering or getting to the page, even though I am bound (1) to remember go back and change link URLs if structure/slugs names are changed and (2) add it manually for every page I want to.