Prepare for multilingual site by placing all content in lang-folder?

#1

Hi and thanks for all the good q&a in this forum, I’m rather new to Hugo but have learned a lot in a short time from you guys.

I am working on a site that after launch soon will be multilingual. It’s still just one language (swedish), but en and de will come soon. To prepare for that (and correspond with the former site’s structure) I would like to set baseUrl of the first language to /sv/, and then the following to /en/ and so on.

However, when trying to just set the baseUrl all my styling and some of my links disappear. What am I missing?

In my config.toml-file I have relurls set to true.
I use compilers, eg Webpack.

#2

The baseURL will be the domain.

Then set the following parameters:

defaultContentLanguage (“en”)

Content without language indicator will default to this language.

defaultContentLanguageInSubdir (false)

Render the default content language in subdir, e.g. content/en/ . The site root / will then redirect to /en/ .

ref: https://gohugo.io/getting-started/configuration/#all-configuration-settings

1 Like
#3

Thank you for your answer. I’ve tried this now,

defaultContentLanguage = "sv"
defaultContentLanguageInSubdir = false

but there is no change, content is not rendered in the /sv folder (I tried ‘true’ as well just to be sure)

#4

The above should be set to true for the meta refresh redirect to take place.

So that:

https://example.com ---redirects to---> https://example.com/sv/
1 Like
#5

I have it set to true and nothing changes.
This might be a stupid question, but should I also physically move my md-files within site/content to site/content/sv?

#6

With the above combination of settings whenever you run the command hugo server or hugo from the root of the project the homepage will redirect with a meta refresh to the /sv/ sub-directory, provided that each file under /content/ has the default language code (e.g. filename.sv.md).

You may also move the files if you want under /sv/ but it’s not mandatory provided you do the above.

For more info have a look at:

1 Like
#7

Have a look at my website source code. Maybe you’ll find some answers about how to organize your content.

2 Likes
#8

Thank toy @onedrawingperday and @martignoni !

I’m afraid no meta refresh takes place, not on local build, not on local live preview and not on netlify.

Here is content from my config.toml file:

baseurl = “/”
languageCode = “sv”
languageLang = “sv”
title = “example”
relativeURLs = “false”
enableRobotsTXT = “true”
googleAnalytics = “”
defaultContentLanguage = “sv”
defaultContentLanguageInSubdir = true

Not all md files has ending .sv.md, but if this works those that do should be created in dist/sv locally and reachable online on /sv/, right? This is not the case

#9

It’s difficult to say for sure what is wrong without seeing your code. Have a read about Requesting Help to see how to make it easier for us to help you.

1 Like
#10

I’ve made it public, straight up: https://github.com/martinmodighkarlsson/metry.git

#11

I have made som changes, one key was adding:

to config.yml (yes, I switched to yaml instead of toml)

Meta refresh now works for hompage, “/” leads to “/sv”.

But what do I do for internal linking, seems I’m missing something important in order to make all content be found at “/sv/*”?

#12

I use the same file name (before the extension). Eg. bla.en.md and bla.sv.md for the same content in two languages.

PS. It looks like you don’t want to place your content in lang folders. Time to open another discussion?

#13

All my files are now named .sv.md except from the first shot at english page: :_index.en.md.

The plan is to add translated files with the same file name. I haven’t so far put them in different catalogues (@onedrawingperday suggested it wasn’t necessary to put in physical folders). By folders I meant url folders - my understanding of Hugo so far is that folder structure and url structure don’t need to match?

#14

Indeed not necessary, but your post title says “placing all content in lang folder”, so I thought this was what you want to do.

#15

You are right, not very precise in my original question! My apologies, and thanks for replies.