gohugoio / hugo

The world’s fastest framework for building websites.

Home Page:https://gohugo.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crosspost a post on multiple languages on multilingual sites

gntech opened this issue · comments

I propose that there should be a convenient way to crosspost a post in multiple languages.

An example use case

On my personal site I currently write articles in English first and then I create a translated version of that in Swedish.

But I am thinking about focusing more on writing only in English. But I still want my visitors that go to the swedish site to be able to see the new content even though it is only available in English. I want my visitors to be aware that there are new content on the site.

Those posts/articles that do have a Swedish translation should of course show that translation on the Swedish site but for posts/articles that is available only in English I want to be able to crosspost them so they also show up on the swedish site.

How to do this

Currently we have .Pages (pages in current language) and .AllPages (all languages). One possiblity is adding an optional parameter in the frontmatter of the post.

crosspost: true

This post would then be added to the .Pages list for all languages disregarding which language it was originally written in.

Another solution is to make a clever query between .Pages and .AllPages and looking for .Params.crosspost to list the "cross posts". This could be achieved without doing any changes to Hugo itself.

@bep I have tried to devise a solution with using a clever query. I can quite easily extract the english crossposts but I am stuck trying to insert them in the right place chronologically in my list of swedish posts.
Is it somehow possible to merge .Site.Pages and $crossposts into a new variable $postsandcrossposts and have the result sorted chronologically?

I currently have the following quite ugly hack on www.gntech.se to show a crosspost.

{{ $lang := .Site.Language.Lang }}
{{ range first 40 .Site.AllPages }}
  {{ if (eq .Lang $lang) }}
    {{ .Render "listitem" }}
  {{ else if isset .Params "crosspost" }}
    {{ .Render "listitem" }}
  {{ end }}
{{ end }}

We are currently investigating migrating our Typo3 installation to Hugo. For that we definitely need this feature to generate a page from the default-language also for other languages, when the page is not translated for that language.

@gntech could you explain how and where exactly you did add the workaround? Maybe that could work for us as well until the feature is available in Hugo.

Thanks!

@kahoona77 The workaround is very crude and only work for showing crossposts in the index.

Looks like making symbolic links works well

ln -s somepage.en.md somepage.it.md

@IRus Thank you for this! 👍 That is a really nice solution/workaround!

@IRus / @gntech How do you define canonical urls with this workaround?

@natedalliard I don't do this, but I can imagine canonical if front matter, that later processed with care by your theme.

Isnt this also related with this issue?
#5612

I am wondering why this feature is still not available, the whole translation seems useless for me then...

I'm quite interested in having such a feature too.

This was addressed in v0.96.0. See https://discourse.gohugo.io/t/37225/12.

Try it:

git clone --single-branch -b hugo-forum-topic-37225 https://github.com/jmooring/hugo-testing hugo-forum-topic-37225
cd hugo-forum-topic-37225
hugo server

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.