reuixiy / hugo-theme-meme

😝 You can’t spell awesome without MemE!
https://io-oi.me/hugo-theme-meme
MIT License
1.01k stars 279 forks source link

How to make multilingual Websites? #89

Open Syralist opened 4 years ago

Syralist commented 4 years ago

How do I need to organize my posts for multilanguage websites? I dont want to use subdirectories but suffixes on the files. From the Hugo documentation this should be possible.

reuixiy commented 4 years ago

Assume de is your default content language:

  1. change defaultContentLanguage to de

  2. add [languages] params to the bottom of config.toml, e.g.

    ##########################################
    # Configure Multilingual Mode
    
    # de
    [languages.de]
        languageName = "Deutsch"
        weight = 1
        languageCode = "de-DE"
    
    # en
    [languages.en]
        languageName = "English"
        weight = 2
        languageCode = "en-US"
  3. add a de post, e.g. hello-world.de.md

  4. set enableLangToggle to true

  5. hugo server

Syralist commented 4 years ago

I tried that and got this error:

$ hugo server Building sites … Built in 147 ms Error: Error building site: failed to render pages: render of "section" failed: execute of template failed: template: section/categories.html:2:7: executing "main" at <partial "pages/tree-sections.html" .>: error calling partial: execute of template failed: template: partials/pages/tree-sections.html:8:19: executing "partials/pages/tree-sections.html" at <partial "utils/tree-sections.html" .>: error calling partial: "E:\Hugo\sites\github\themes\meme\layouts\partials\utils\tree-sections.html:10:15": execute of template failed: template: partials/utils/tree-sections.html:10:15: executing "treeSections" at <readDir $path>: error calling readDir: failed to read directory "./%!s()": open E:\Hugo\sites\github\%!s(): Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.

My content directory looks like this: E:\HUGO\SITES\GITHUB\CONTENT ├───about ├───categories └───posts ...........├───allgemein ...........├───programmieren ...........└───smarthome

with subdirectories under posts for my categories. my guess is that is part of the issue. in each directory is an _index.md file and in the categories folders there is at least one post. I tried adding translated posts in each category but that didnt help.

reuixiy commented 4 years ago

I see, it's a problem of tree-sections partial, try this:

##########################################
# Configure Multilingual Mode

# de
[languages.de]
    languageName = "Deutsch"
    weight = 1
    languageCode = "de-DE"
+   contentDir = "content"

# en
[languages.en]
    languageName = "English"
    weight = 2
    languageCode = "en-US"
+   contentDir = "content"
Syralist commented 4 years ago

That works! Thank you very much!

Syralist commented 10 months ago

Hello! today I upgraded my Hugo and pulled the newest version of the theme and the same problem came back.

After tinkering around a bit I found a solution for my specific usecase. Apparently Hugo changed something around the contentDir and does not fill the variable $.Site.Params.contentDir when I use "translation by filename" instead of "translation by content directory".

My fix was a change in tree-sections.html in line 4: from

{{- $contentDir := $.Site.Params.contentDir -}}

to

{{- $contentDir := `content` -}}

Now it works but it's a hack rather than a solution. ;)

reuixiy commented 10 months ago

This might be helpful https://github.com/reuixiy/hugo-theme-meme/issues/432#issuecomment-1600817573.