How to correctly set a default language?

I have define default lang with another codet than en, but the main language continues to be set as <html lang="en"> in the code source.

Therefore, I suppose that we can deduct that default lang does not populate the grav.language.getLanguage variable.

In this case, where is the right way to set specifically grav.language.getLanguage?

I found different threads about this variable (such as: Set <html lang="de"> or Get current language issue or How would I get the current language?, but none of them seems to answer about this (basics) question (or maybe I have missed something that you will point me out).

How are you setting the default lang cause the easiest way is with the language switcher plugin? That should just work out of the box…

For just a one-off setup you can set the default in user/config/site.yaml
default_lang: en

The plugin that you have indicated seems to be made for switching more specifically between multiple languages, but I aim to set an unique language (which is not the default en codet).

I have already changed the configuration in the user/config/site.yaml file as you wrote, but this parameter seems to not been used as expected: the main language continues to be displayed as <html lang="en"> in the code source.

As the theme (Mediator) that I am currently trying to set up is using the same the same variable as the Antimatter default theme (i.e. <html lang="{{ grav.language.getLanguage ?: 'en' }}"> in the file named base.html.twig), I have some difficulties to see if this problem is originated from the theme, from my settings or from the main installation of Grav.

Hi @gizmecano,

did you try to set the default language in your user/config/system.yaml like this (example) ?:

    - fr

Yes, I did. But this option adds the supported language codet in the URL (i.e.: as described in Active Language via URL in the documentation.

It is not the behaviour that I expect: I simply want all the content of my site uses only another default language than en.

Ok, I tried it with one of my local installations with this configuration:

    - fr
  include_default_lang: false

This works fine for me:

  • No language code in the URL
  • This starting html tag: <html lang="fr">

As far as i understand the documention that you mentioned above it is possible to choose a language manually by adding the language code to the URL if you have more than one language.

1 Like

Well done, this is the correct setting combination I was looking for. Thanks.