I have a “Downloads” page on my site that is translated with variables loaded from i18n.
How can I get hugo to render /content/download/_index.md for every language without creating a /content/download/_index.de.md file?
I have a “Downloads” page on my site that is translated with variables loaded from i18n.
How can I get hugo to render /content/download/_index.md for every language without creating a /content/download/_index.de.md file?
lang
. See Configure modulesI don’t know if that is a valid approach, may lead to strange behavior later or is complex working nonsense — but a multilanguage content adapter looks promising…
detected possible problems:
download
is not a section but a page
: not listed in site.Sections
site.RegularPages
, so a where filter is needed (see layout below)@bep if this all is practical maybe adding support for section pages with an adapter might be an option. Did I just miss how to do that?
The adapter content/_content.gotmpl
if the download section also contains pages, you will need to adjust template lookup.
{{ .EnableAllLanguages }}
{{ with resources.Get "download.md" }}
{{ $pageVars := site.Data.download }}
{{ $content := dict "mediaType" "text/markdown" "value" .Content }}
{{ $page := dict
"content" $content
"kind" "section"
"path" "download"
"title" $pageVars.title
"params" $pageVars.params
}}
{{ $.AddPage $page }}
{{ end }}
create a markdown file /assets/download.md
## My download page
Is this translated used a shortcode? **{{< T true >}}**
I tried to extract the frontmatter from markdown resource and create a param dict but failed (findREsubmatch, remarshal, resources.FromString …) so a externalised frontmatter to a data file
create page params in data/download.toml
title: download <-- passed as title to the adapter (and translated in template)
params: <-- passed as frontmatter to the page
- key1: one
- key2: two
create i18n files
# de.toml
download = 'runterladen (de)'
true = 'Ja'
# en.toml
download = 'download (en)'
true = 'Yes'
# fr.toml
download = 'tèlècharger (fr)'
true = 'Qui'
a layout download/page.html
{{ define "main" }}
<h1>Translated title: {{ T .Title }}</h1>
{{ .Content }}
{{ site.Sections }}
<h2>{{ .Params.key1 }}</h2>
<h3>{{ .Params.key2 }}</h2>
<ul>
{{ range where site.RegularPages "File.IsContentAdapter" "ne" true }}
<li>{{ highlight (. | jsonify (dict "indent" " ")) "JSON" }}</li>
{{ end }}
</ul>
{{ end }}
p.s. the shortcode uses is as simple as {{ i18n (.Get 0) }}
I haven’t read your entire post, but you can create all kind
s of pages with a content adapter (including sections), and you’re right about this being a way to create multiple language versions easily.
Edit in: You’re right, currently it’s not possible to create the home page from a content adapter, but I’m not sure why that is, sounds like a restriction we could/should remove.
so it looks like I`m missing something:
changing the kind to section, or using type did not create any pages
This works great (content/_content.gotmpl):
{{ .EnableAllLanguages }}
{{ $content := dict
"mediaType" "text/markdown"
"value" "This is the downloads page."
}}
{{ $page := dict
"content" $content
"kind" "section"
"path" "download"
"title" (printf "Downloads (%s)" site.Language.Lang)
"weight" 1
}}
{{ .AddPage $page }}
Try it:
git clone --single-branch -b hugo-forum-topic-55022 https://github.com/jmooring/hugo-testing hugo-forum-topic-55022
cd hugo-forum-topic-55022
hugo server
indeed, works like a charm…
I used your repo and applied the resource, data file, i18n and the shortcode and all is fine…
played that back to mine and - boom -
So in this case my conclusion is the problem is in front of my computer… there must be something terrible broken with my stuff…
I won’t tell how log it took to find it, but
disableKinds = ['rss', 'section', 'taxonomy', 'term']
Wow, you guys are awesome… looks like it was fun to figure out.
I’ll try this tomorrow in the repo and see if I can get it to work in my context…
Been there, done that.