HUGO

Multilingual Subdirectory Layouts

Hello,
in my content/ folder i have files in my various subfolders/categories that look like this:
– accessories
— cat_1
---- article_1
----- index.en.md
----- index.en.md
---- article_2
----- index.en.md
----- index.en.md
— cat_2
---- article_1
----- index.en.md
----- index.en.md

and my folder structure (public/) should later look like this:
– zubehoer
— kategorie_1
---- artikel_1
----- index.html
---- artikel_2
----- index.html
— kategorie_2
---- artikel_1
----- index.html
– en
— category_1
---- article_1
----- index.html
etc…

Is this possible? How can i achive this?

No. That’s not possible. What is possible is the following:

de
|-kategorien
  |-subkategorie1
  |-...
en
|-categories
  |-subcategory1
  |-...

Then you set your default content language (german) and set that it is NOT in a subfolder in the resulting site:

defaultContentLanguage: de
defaultContentLanguageInSubdir: false

Note: I assume your german language is called de. If you call it deutsch you need to set that title there.

1 Like

By the way @Daniel_Lassak: I just realised that you might run into troubles this way in regards to “connecting” your content languages. With your old way, the filename-path-thingy makes it clear to Hugo, that your English about file (about.en.md) is connected to the German one (about.de.md). To have it working in this new by-language-directory-version you need to look after some things:

  • name content/de/about.md and content/en/about.md identical, don’t change the filename by language. same location and same name for every connected item
  • add a slug parameter to your frontmatter if you wish to have a different URL (slug: ueber-uns in the german version for the content/de/about.md file)

There is a way to add a frontmatter parameter that links these files, but I couldn’t find the name of the parameter this fast. You probably want to give the following link a thorough read (again):

1 Like

I ended now in this config.

defaultContentLanguage = "de"
defaultContentLanguageInSubdir = true
relativeURLs = true
[languages] 
  [languages.de]
    weight = 1
    languageName = "Deutsch"
    contentDir = "content/de"
    languageNameShort = "de"
    languageCode = "de_DE"
  [languages.en]
    weight = 2
    languageName = "English"
    contentDir = "content/en"
    languageNameShort = "en"
    languageCode = "en_US"

and that worked for me.
if i set

defaultContentLanguageInSubdir = false

i dont get a redirect to /de from my root-folder.

I never had a setup where I would put the default language into a subdirectory. If you are hosting on Netlify or another service that offers redirection and headers this could be solved by some language headers:

1 Like

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