Closed jamesmcmurry closed 7 months ago
I have not tested this but idea looks good to me!
I am seeing this bug on my site as well:
I confirm that the PR fixes it, but probably best to polish it following Jimmy's feedback.
Note that #925 is targeting the same section of code, so once either one is merged, the other one needs to be rebased.
I was about to propose a similar pull request 😯 I was also seeing the same widget shown here https://github.com/CaiJimmy/hugo-theme-stack/pull/950#issuecomment-1962230394 even if I don't have any translated content in my whole website.
I did something different by the way (note: I'm using this theme as hugo module):
layouts/partials/sidebar/left.html
and changed that block in this way: {{ if (default false .Site.Params.languageSelector.toggle) }}
{{- $currentLanguageCode := .Language.Lang -}}
{{ with .Site.Home.AllTranslations }}
<li id="i18n-switch">
{{ partial "helper/icon" "language" }}
<select name="language" onchange="window.location.href = this.selectedOptions[0].value">
{{ range . }}
<option value="{{ .Permalink }}" {{ if eq .Language.Lang $currentLanguageCode }}selected{{ end }}>{{ .Language.LanguageName }}</option>
{{ end }}
</select>
</li>
{{ end }}
{{ end }}
basically I added this check {{ if (default false .Site.Params.languageSelector.toggle) }}
at the beginning, so the widget is hidden, unless you explicitly add:
languageSelector:
toggle: true
to your params.
Note: this works, but I would hugely prefer if it was something fixed upstream (like this PR) so I don't have to maintain my own customisation.
I'm going to merge this for now, since this issue will affect all people using the latest Hugo. The type casting can be fixed later.
Hide the left sidebar translations option if only one translation is defined in the site configuration