Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

How to correctly set a default language?

Solved by Peter Fuchs View solution

Started by P. Mergey 9 years ago · 6 replies · 4617 views
9 years ago

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: /forum/archive/set-html-lang-de-t3738 or /forum/archive/get-current-language-issue-t6492 or /forum/archive/how-would-i-get-the-current-language-t504, but none of them seems to answer about this (basics) question (or maybe I have missed something that you will point me out).

9 years ago

Hi
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

9 years ago

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.

9 years ago

Hi @gizmecano,

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

YAML
languages:
  supported:
    - fr
9 years ago

Yes, I did. But this option adds the supported language codet in the URL (i.e.: http://yoursite.com/fr) 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.

9 years ago Solution

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

YAML
languages:
  supported:
    - 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
9 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 197 2 months ago
Themes & Styling · by Ian, 2 months ago
3 92 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 127 3 months ago