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:
- 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”
- 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”
- 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.