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 bygetLanguages()
.
This explains my findings.
Question:
- Could someone perhaps shed a light on the use cases for two different “default” languages?
- What is
theme_config
?