I’ve been trying to add a second language to my site. Seems simple enough; add a languages section in config:
weight = 1
weight = 2
Then simply translate documents as needed. For instance,
/content/page.fr.md will be automatically linked.
When navigating to
localhost:1313/page/, I see the original English page, no problem. However, when navigating to
localhost:1313/fr/page/, all that’s served is “404 not found”.
Is there some sort of gotcha not written in the docs?
Things I tried:
- requiring the default language to also have a subfolder /en
- printing the link to the translated document (didn’t show up)
- looked at the console, both languages appear when generating the site
- deleted the generated files and re-served
- updated Hugo to the latest version
- tried finding people with the same problem
- started the multilingual modifications over from scratch
- simplified the config changes and tried capitalizing [Languages] because of a reference found online
- searched through the forum, nobody seems to be experiencing this problem, I must be doing something stupid
Please post the front matter of content/page.fr.md
If your pages are set to draft your local server might not load them if you don’t tell it to publish drafts. If you have other files in the content directory they might override the contents somehow. If you have more language settings (like
disableLanguages set they might influence the results. All that requires a bit more than a short config copy-paste
There actually is a gotcha here: the order of
[Languages] section was defined, followed by
publishDir. Maybe because
[Languages.en] was defined first, it did not go to the publish directory, but to a default
/public folder. Building the site then looked like this:
docs/fr – sub-folder with French content, into the defined
public – english content
When serving, Hugo grabbed content from the
public folder, so URLs like
.../fr/ were pointing to
public/fr/ instead of
publishDir first, followed by the
[Languages] array. For example:
publishDir = "docs"
weight = 1
weight = 2
Could this be a bug with Hugo? Seems like an odd and rather unhelpful feature.
No. This behavior is defined in the TOML specification for tables:
The top-level table, also called the root table, starts at the beginning of the document and ends just before the first table header (or EOF). Unlike other tables, it is nameless and cannot be relocated.
publishDir = "docs" key/value pair is part of the top level table, so it must appear before any of the other tables.
Well that would explain a few problems, wouldn’t it.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.