TLDR:
What is the cleanest or most (performant|elegant|ubiquitous|comprehensible) way to, from within a partial / template, arrive at a boolean answer for:
??? Am I either a monolingual deployment, or currently operating within the context of the default language for a multi-lingual site ???
This comes up because while trying to tease apart some unrelated … lets call them “problems of my own making” … in my codebase, I’ve encountered an odd question.
in this specific manifestation, I’m attempting to generate a site webmanifest. This only should run once. against whatever is configured as the default language, since the asset must reside in a known consistent location relative to webroot, and I’ve not seen a pattern of them being generated for other languages…
(while I concede that were the site leveraging hostname/fqdn related isolation for multi-lang it would be possible… I’m trying NOT to tangent )
My site.webmanifest
template is generated as a output format of home
… which means that, for this case, this works:
{{- if or ( not hugo.IsMultilingual ) ( and hugo.IsMultilingual (eq . .Sites.Default.Home )) -}}
to conditionally activate the template when a site is NOT multi-lingual OR, if it IS, then only for the default language.
This works.
I’m fine keeping it as is.
However, it feels like there’s likely a more ubiquitous and elegant way of assessing if the current context matches ‘default lang’ regardless of a site’s language diversity… and it felt worth asking… There’s a lot of useful attributes in these functions/methods,
hugo.isMultilingual
hugo.isMultihost
.Site.Languages
.Site.Language.Lang
but none of them seem to have a path to test for default
(also possible I’m just missing something REALLY obvious)
I’d thought that the page scoped .Language.Lang would work, but I couldn’t find a consistent way to divine “the default language” which didn’t involve its own bag of logic contortions, which didn’t result in a less obtuse/convoluted test at the end.
Assessing .Site.Params.defaultContentLanguage
as inferred here as a consistent parameter wasn’t working for me
(I’m not entirely sure why… Its entirely possible I was jus experiencing a moment of exceptional lysdexia or something, but I wasn’t having much luck regardless of capitalization, and pivoted when I saw that .Sites.Default.Home
was a thing)
WARN Not generating webmanifest. lang: en defaultlangparamval: %!s(<nil>)
WARN Not generating webmanifest. lang: brk defaultlangparamval: %!s(<nil>)
themes/myterriblycodedtheme/config/_default/params.yaml
:
defaultcontentlanguage: en
defaultContentlanguage: en
defaultContentLanguage: en
Hope y’all are having an astounding day.
-W