Is there a way to customise the language URL?

I’ve been trying to find a way to customise the language URL but retaining the correct ISO language code in HTML.

Objective:

  • Keep the lang="" value correct as per ISO, in this case “ko” for Korean
  • The URL should reflect the commonly known two-letter code: in this case “kr” so it should be domain.tld/kr/

So far, I tried the following:

  1. Add a languageCode per language – the URL changed but so did the lang=""
    Example:
[languages.kr]
languageCode = "ko"

Result:

  • domain.tld/kr/
  • html lang=“kr”
  1. Add [languages.ko.permalinks] – did not work
    Example:
[languages.ko]
[languages.ko.permalinks]
	"/" = "/kr/:slug/"
	posts = "/kr/:slug-:year:yearday/"

Result:

  • domain.tld/ko/
  • html lang=“ko”
  1. Add baseURL per language – default language URL stopped working
    Example:
[languages.en]
baseURL = "domain.tld"

[languages.ko]
baseURL = "domain.tld/kr"

Result:

  • The default language is now: domain.tld/en/ when hugo is generating the files. However it works fine as “hugo server”.
  • Korean: domain.tld/kr

Anything I missed?

Other details:

  • Theme tested on: hugo-future-imperfect-slim
    – I haven’t tried testing in another site I’m preparing for multilingual which is using a different theme. I got stuck with this one.

Check your configuration file. Does it (outside of the languages section) define a language somewhere as ko? Then change that one to kr and see if it works. The lang-attribute sometimes takes default language settings as a parameter.

Another way: You might have to change the variable that is printed there to the title of your language and then add a parameter to your language configuration languageName = "ko" and use that instead.

It’s not so much an issue with the setup and more an issue, what your themes developer put into the layouts/_default/baseof.html file. You can override it by copying the themes version into your own repo-root/layouts/_default/baseof.html` (same location, just two folders up the directory tree) and add your changes there.

1 Like

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