How to translate only a subset of the pages?


#1

My project has the following content structure:

project/
└── content/
    ├── subpage/
    │   ├── _index.fr.md
    │   └── _index.md
    └── _index.md

And these are my language settings in the .config.yml:

languageCode: "en-us"
defaultContentLanguage: "en"
languages:
  en:
    languageName: "English"
    weight: 1
  fr:
    languageName: "Français"
    weight: 2

Now, when I check for {{ .IsTranslated }} in the template where the home page is rendered, it is set to true, even though a content/_index.fr.md file doesn’t exist.

Since a translation of the content/_index.md has not been defined, why is Hugo creating an empty page for the French translation, in my particular case, the French home page?

Thanks!

Hugo Static Site Generator v0.48 darwin/amd64 BuildDate: 2018-08-29T06:33:08Z
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.11"

EDIT: I found this (closed) issue, but the solution is not applicable since I already do it as the user mentioned in the solution.

EDIT 2: Here is a GitHub project to reproduce the issue: https://github.com/nop33/hugo-minimal-setup


#2

I moved this to #support. Please read Requesting Help and share your code to get more folks helping you. :slight_smile:


#3

@maiki thank you!
I read the help section and I managed to reproduce the problem in a very minimal Hugo setup: https://github.com/nop33/hugo-minimal-setup


#4

I have to admin, I am quite disappointed with the feedback here :disappointed: https://github.com/gohugoio/hugo/issues/5195


#5

It seems that your only option would be to use 301 redirects for the unwanted public/fr/index.html
Unless you choose to have the root /index.html translated as well.

Your issue is also relevant to the Override section url topic.

But you shouldn’t really feel disappointed, you got a definite reply.

Anyway there are many intricacies with Go and the way Hugo is built. There has been quite a bit of refactoring during the past year. What you’re asking may be a breaking change.

In any case, if the maintainer feels that current behavior will remain as is, there is not much left to be said, except for this:

If you know Go and you feel that this should change, then you could submit a PR to Hugo source (for review) along with proper tests (so that existing Hugo projects don’t break).


#6

I dealt with this by checking the word count of the first translation before rendering the translation menu.

{{ if .IsTranslated }}

  {{ if gt (index .Translations 0).WordCount 0 }}
    <nav class="LangNav">
    {{ range .Translations }}
      <a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a>
    {{ end}}
    </nav>
  {{ end }}

{{ end }}