Why do html_lang and Language\getDefault() have different values?

TLDR: Why do html_lang and Language\getDefault() have different values?

According the docs:

  • html_lang: This will return the current active language if provided, else use the site.default_lang configured option, else fall back to en.
  • getDefault(): Returns the default (first) language.
    (Note: ‘first’ means first language listed in system.yaml/languages:supported)

What are the use cases for two different “default” languages on the same page?

The long read:

I expanded a bit on some tests I ran yesterday to check if a translation exists and added getDefault() to the mix. I expected it to return the value from site.yaml/default_language. When making some changes to configs I noticed however that the order of supported languages in system.yaml/languages:supported made a difference. I couldn’t wrap my fingers around it and did some more tests and reading.

The following is based on https://learn.getgrav.org.

Chapter: themes/theme-tutorial:

  • From snippet from example code of base.html.twig:
    <html lang="{{ grav.language.getActive ?: theme_config.default_lang }}">
  • A bit further on:
    The <html lang=... item is set based on Grav's active language if enabled, else it uses the default_lang as set in the theme_config

Notes/questions:

  • What is theme_config?
  • When using {{ dump(theme_config) }} null is returned.
  • This definition is also in contradiction to the variable html_lang which uses site.yaml/default_language.
  • Leftover from outdated docs perhaps?

Chapter: themes/theme-vars:

html_lang variable
This will return the current active language if provided, else use the site.default_lang configured option, else fall back to en.

Notes: See notes above

Chapter: content/multi-language:

  • getLanguages() - Returns an array of all supported languages
  • getLanguage() - Returns current active, else returns default language
  • getActive() - Returns current active language
  • getDefault() - Returns the default (first) language

Notes/question:

  • The default (first) language seems to point to the first language listed in system.yaml/languages:supported, which is returned by getLanguages().
    This explains my findings.

Question:

  • Could someone perhaps shed a light on the use cases for two different “default” languages?
  • What is theme_config?

Not much time now (even to read all this!), but I can answer that theme_config is commonly defined at the top of base.thml.twig for many themes:

{% set theme_config = attribute(config.themes, config.system.pages.theme) %}

So it’s config.themes.<yourtheme>.

@hughbris Thanks for your clarification.

theme_config (or config.themes.<yourtheme>) does not seem to have the property default_lang defined in a fresh Grav 1.4.5 install with Quark theme (anymore?).

Only config.site.default_lang seems to provide that property (now?).