Search feature for multilingual site

I created a hugo theme using tailwindcss and provided a search function. I use a customized search layout to generate search pages and JSON data for normal pages.
But I have some problems when dealing with i18n:

  • only the default language is indexed
  • the search site is generated only for the default language (translations remain unused)

Detailed issue description can be found here https://github.com/tomowang/hugo-theme-tailwind/issues/26

The original search feature was commit at https://github.com/tomowang/hugo-theme-tailwind/commit/2f0ecf1c8e0c1524b30c80ab1ef7156dd72aee24#diff-bbd8a001744157aa86886648c0916fa963cd292487e53523b183ab60347bf7f8

The demo site is https://hugo-theme-tailwind.tomo.dev/search/?search=emoji

Any one have any ideas to fix this? Thanks.

.Site.RegularPages represents current language site pages, to index all site’s pages, you could do it with .Site.Sites.

{{ range .Site.Sites }}
  {{- $pages := where .RegularPages "Params.hidden" "!=" true -}}
  {{/* ... */}}
{{ end }}

See also https://gohugo.io/methods/site/allpages/.

1 Like

How about the translation of layout page? Can I use some slug path for multilingual search result pages?

Finally I used a tricky way: add multilangual index.{lang}.md for search layout. Seems to work (maybe there is better solution).
Check this commit if anyone interested: