Disable/hide language selector for some pages or folders?

Hi, my website contains multiple products’ documents in sub-folders, and some of them have both English and Chinese version, some have only English version.
For those documents that have only English version, I’d like to hide/disable the language selector.
I have no idea where to start. Would you shed some light?

If the above requirement is hard to implement, is there a way to “fall back” to default (English) version when a page doesn’t have Chinese version?

I would start with using Page.isTranslated in your language selector rendering code

1 Like

Thank you @irkode , I’ll try to add some code with my language selector rendering code.

After reading Docsy’s implementation of language selector, I still don’t know how to do it.

{{/* Link directly to documentation etc., if possible. */ -}}
{{ $langPage := cond (gt (len .Translations) 0) . .Site.Home -}}
<div class="dropdown">
  <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    {{- $langPage.Language.LanguageName -}}
  </a>
  <ul class="dropdown-menu">
    {{ range $langPage.Translations -}}
    <li><a class="dropdown-item" href="{{ .RelPermalink }}">{{ .Language.LanguageName }}</a></li>
    {{ end -}}
  </ul>
</div>

I think the first thing to do is the automatic “fall back” mechanism, because without falling back to the default English page, a user may navigate to a non-existing Chinese page by clicking links in current page.
It woud be nice if Hugo provided this fall back feature. I have no idea how to implement it.

IMHO theres No OOTB here. remember, If there’s no translation, you have no page where you can get something like a link, title and all these can be localized.

you have

  • Page.Language
    language of current page
  • Page.AllTranslations
    which contains all translated Pages available for a current page (incl the current page)
  • Page.Translations
    same as above but without current page
  • site.Languages
    contains all languages that are defined.

so the difference of AllTranslations.Language and site.Languages are the ones not translated.
the pages in Translations are the one where a translation exists.

There are some topics in the forum that handle that topic incl. code - try to search for that “missing translation fallback …”

hope that helps

1 Like

@irkode , Thank you again for providing more information. Much appreciated!

Just felt over that one. Also a nic approach and definitely from guys that know hiw hugo works.

1 Like

@irkode Thank you so much for more information.
When I started this thread, I’ve also post my question on Docsy’s discussion board, and I got an answer from there. It seems working. At least I didn’t see a problem with that approach.
For details, here is the link to that discussion:

Thanks again!