HUGO

Is languagePrefix read-only or can it be defined in site config?

I am trying to change how are shown my URL in a multilanguage website, while keeping all the content files using the language iso code.

I would like to have
domain.com/english/mypage/
domain.com/greek/mypage/

while keeping

mypage.md
mypage.gr.md

Here is the config that I have tried so far. Yet, defining languagePrefix in config.yaml does not appear to change the URL which stays with ‘en’ and ‘gr’. The {{ .Site.LanguagePrefix }} markup also does not change.

languages:
  en:
    title: My New Hugo i18n Site
    languageCode: en
    languagePrefix: english
    weight: 1
  gr:
    title: My New Hugo i18n Site Greek Edition
    languageCode: gr
    languagePrefix: greek
    weight: 2

Found the reply looking at site.go on github. Look like it is a ready only variable :frowning:

	languagePrefix := ""
	if s.multilingualEnabled() && (defaultContentInSubDir || lang.Lang != defaultContentLanguage) {
		languagePrefix = "/" + lang.Lang
	}

I am not sure I get your question… in your sample config it states languagePrefix: greek - isn’t that what you want to know? Change it into “blarg” and the url will start with “blarg”?

You will have to post a link to a minimal demo repository so we can see what the issue is. I have the feeling you have another issue if the links don’t come out as expected.

My question is “can this variable be defined in the config, or is it a read-only variable defined by Hugo?”

The sample config is fine by me. The problem is that when I define this parameter in the config like in the example, it is not taken into consideration by Hugo while writing the URL.

First of all: I assumed you showed a config that is not “thought up” by yourself :wink: So languagePrefix is not a configuration parameter of Hugo? Then no, it won’t work.

From the code you posted it appears that Hugo is taking the “en” or “gr” as languagePrefix. I read in the docs (can’t find it now, sorry) that you can name your languages any way you want. So try renaming the gr in your sample config into blarg. I would expect it to show up as URL-slug.

If not - this is something I would think of as a nice-to-have feature. Maybe consider opening a feature request in Hugo’s Github repo.