Change default language of a folder

Hello,

The default language of my website is English. I have a folder content/foo and I want this folder to have another default language, say French. It’s a particular case of multi language where the website is multi language, but every page is actually available in one and only one language (but it might be a different one).

Is it possible? For example, is it possible to add in the front matter something like Language = "fr"? Or is there another option?

I know I can use the multi language feature by renaming my files such as content/foo/bar.fr.md. This would work but:

  • The associated url now contains “fr” (mysite.com/fr/foo)
  • French becomes an available language even where it should not be: a menu appears to switch language (maybe this is template specific?)

Thanks a lot!

Edit: what is the “default language”? As in, what does that do, technically?

I’ve never used the multilingual feature in Hugo, but I imagine it works by setting templates for the different languages so they load the correct language code or soemthing, ne?

What I mean is, if you don’t need associated, overlapping pages, just write in the language you need for a given page. Any small adjustments you need to make you can do so in the appropriate template, for that section. That’s how I’d proceed. :slight_smile:

You can set contentDir per language, which then will be the default language for that content dir.

Thanks both of you.

In the Config file, we can define a DefaultContentLanguage

I agree that I can do that, but I wanted to know if I can use the template functionnalities without having to “hack” them.

I tried but failed: should i define a contentDir for every language? And lastly, is it possible to set multiple contendDir for one language?

  1. You can, if you want.
  2. No.

I’am using this way to handle multi-languages.
archetypes/default.md

YAML
---
title: "{{ replace .TranslationBaseName "-" " " | title }}"
date: "{{ .Date }}"
Lang: ""
---

layouts/_default/baseof.html

<!DOCTYPE html>
<html lang='{{ if eq .Params.Lang "" }}en{{else}}{{ .Params.Lang }}{{end}}'>
<head>...</head>
<body>...</body>
<html>
2 Likes

What I meant, what does it mean to you? I know what it means for Hugo, but you aren’t looking for that particular solution. @okabrionz’s does what I was thinking of:

<html lang='{{ if eq .Params.Lang "" }}en{{else}}{{ .Params.Lang }}{{end}}'>

Sorry for being unclear. I want to use i18n implemented in Hugo, which, if I’m getting right, is base on a “current” language. So yes, I don’t really want to change the “default language” of a folder rather than the “current language”.

Thanks for the tips! I however need to use the i18n functionnality, but I don’t know on which parameters it’s based on (I tried to hard change <html lang="fr"> in the template but i18n doesn’t care :frowning:)

Thanks!