Multilingual site configuration: failed to extract shortcode, template for shortcode not found

Hello,

I decided to add another language to my site, but I have trouble understanding how to configure a multilingual site in Hugo. I read Multilingual mode and Configure languages sections of the documentation and would like to use translation by file name instead of translation by content directory, because I prefer to have all language versions for each content item to reside in the same directory, as it feels more manageable.

So, I added a [languages] section to my config.toml file featuring two languages, and I chose the default content language along with the type of translation management:

# (...)
[languages]
	[languages.en]
		disabled = false
		languageCode = 'en-US'
		languageName = 'EN'
		title = 'Test EN'
		weight = 1
	[languages.pl]
		disabled = false
		languageCode = 'pl-PL'
		languageName = 'PL'
		title = 'Test PL'
		weight = 2
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true # Doesn't matter if it's on or off
# (...)

However, if I try to preview or build the site, I immediately get an error regarding shortcodes:

Error: error building site: process: readAndProcessContent: "/path_to_hugo_site/content/some_content/_index.md:8:28": failed to extract shortcode: template for shortcode "shortcode_name" not found

shortcode_name.html, as well as other shortcodes, reside in my theme’s layouts/shortcodes/ directory and they were processed without problems before I added the language specific configuration options that I listed above.

At first, I thought that perhaps I should add a language code to each shortcode, like shortcode_name.en.html and shortcode_name.pl.html, for example, but it didn’t affect the error. Not surprising, because the documentation states that:

If a file has no language code, it will be assigned the default language.

So I assume that if a language code is not found in any of the files, a file without the code will be used. The culprit must lie somewhere else.

Anyway, I’m wondering what am I missing here? Why does Hugo complain about the missing shortcode files? Any advice is welcome.

  • you have to move these settings before the first table in your toml file:

  • with hugo 146+ the folder should be: _shortcodes: New template system in Hugo v0.146.0

  • I would lower case the languageName values: en

  • use lowercase also in content file names language identifyer foo.en.md

maybe there is more … best
to share a replayanle repo

1 Like

Thanks, @irkode. You’ve put me on the right tracks by mentioning parameter order. I had [language] block near the beginning of my config.toml, just below the baseURL. When I moved this block to the bottom of the config file, everything started working again.

1 Like

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