Store language choice until the user changes the language

Can the selected language be permanent? It reverts once the browser is closed. I want the user selected language to remain until the user changes it again.

Sure. But that is between you and the maker of your theme. Hugo does nothing on the user’s side. You will need to add a Javascript that when the language selector changes (there is an event for that in javascript) sets a cookie that is read each time the user loads the page. Depending on that they are sent to the proper language once they end up on an other language. But you probably want to raise that issue with the developer of your theme.

I use my own layouts/design. Hence why I asked the question here. But I know very basic JS to make this change.

{{- if $.IsTranslated -}}
        {{ range $.Translations }}
        <span class="sr-only">{{ i18n "translate" }}</span>
        <a class="text-sm pl-6 flex justify-center items-center hover:scale-125" href="{{ .Permalink }}" aria-label="{{ $.Language.LanguageName }}">
          <svg class="site-icon" {{ $aria }} width="1em" height="1em">
            <use xlink:href="#language-icon"></use>
        <span class="pl-1 uppercase pt-1">{{ $.Language.Lang }}</span>
        {{- end }}
        {{- end }}


This is not a Hugo question, but is about general web design, and should asked in a general web design forum. It might help to post the (prettified) output HTML that Hugo puts in public instead of the Hugo source though, so as not to confuse the issue (though mentioning it is auto generated would probably also be a good idea).

I have tried every website I can think of but no one has a clue. I just put converted the language toggle to a button before the header on every page to make it prominent. I will mark this as solved, but it it is really unsolved.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.