Sorry in advance if this questions was already answered, I used the search but did not find anything about my question.
I have a multilanguage website, the default language is english, and I also have some pages in french.
In my index page I want to show the 5 latest blog articles in english & the 5 latest articles in french.
For now my index template is like that :
{{ if isset .Site.Params "latestpostcount" }}
<div class="posts">
{{ $nbPosts := len (where .Data.Pages "Section" "blog") }}
{{ if gt $nbPosts 0 }}
<div class="page-heading">Latest posts</div>
<ul>
{{ range (first .Site.Params.latestpostcount (where .Pages "Section" "blog")).GroupByDate "Jan, 2006" "desc" }}
<li class="groupby">{{ .Key }}</li>
{{ range sort .Pages "Date" "desc" }}
{{ partial "li.html" . }}
{{ end }}
{{ end }}
</ul>
{{ if gt $nbPosts .Site.Params.latestpostcount }}
<a href="./blog/" class="see-more">See more ...</a>
{{ end }}
{{ end }}
</div>
{{ end }}
when I access this url : http://<mysite>/ I see the latest english posts, if I go to http://<mysite>/fr/, I see the latest french posts. I want to show in each index pages the latest posts in english & french.
As I understand .Pages "Section" "blog" will automatically give me the list of posts in the current language, is it possible to force another language ?
I forgot to report about the other expression you proposed :
.AllTranslations : same results as .Site.Home.AllTranslations for both pages.
.Translations :
http://<mysite>/ shows no english and just the string fr with not french blog posts. So Not OK
http://<mysite>/fr/ correctly show en and the 10 latest english posts and fr and the 10 latest french posts. So better but it should have shown only other translations so only english ?
Edit :
Replacing DefaultContentLanguage by defaultContentLanguage in the toml changed the result for .Translations :
.Translations :
http://<mysite>/ shows no english at all and just the string fr with not french blog posts. So Not OK
http://<mysite>/fr/ correctly show en and the 10 latest english posts and no fr at all. So all good it seems.
Make sure to use the hugo branch. For now in that branch there is not any blog item that is marked as french but you can rename anything under content/blog to .fr.md as everything is written in french.
I finally took a well know theme (Ananke) and changed the config to add multiple language and tweaked index.html template to add latests posts for all language and it works.
So it’s definitely a theme bug. I have not found for now but I’ll find it
It seems I’m the only one interested in this but for completeness I’ll share what I found :
In my theme I was using :
.Data.Pages
That produce the bugs reported in this thread. The Ananke theme was using
.Site.RegularPages
And no more problems with multilanguage. I don’t know if that’s a bug / a feature (I’ve not read the doc about those two variables) at least it now works.