gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
73.49k stars 7.37k forks source link

Unclear how i18n (lang.Translate) determines the target language #12591

Closed xlsigned closed 2 weeks ago

xlsigned commented 2 weeks ago

When I use {{ i18n "key" }} in a template, there appears to be no way to change/set the target language. E. g. if $page is a translated page (from $.AllTranslations), neither

{{ with $page }}
   {{ i18n "key" }}
{{ end }}

nor

{{ i18n "key" $page }}

has any effect on the target language, while {{ $page.Content }} clearly shows that I have indeed looked up a translated page.

The documentation should state how (or rather when) the language is determined and what the optional parameter [CONTEXT] actually means and if it is at all possible to change the target language within a template.


The scenario is a Multilingual Site where I want language specific pages that are still incomplete to show the content of the default language (or any other language).

For this I'm using a custom frontmatter value in the incomplete page which triggers the fallback when set, i. e. the template looks up the already completed/translated (default) $page and calls {{ $page.Content }} instead of {{ .Content }}.

jmooring commented 2 weeks ago

Closing as duplicate of https://github.com/gohugoio/hugo/issues/7844.

Please open an issue in the documentation repository regarding suggested changes to the documentation.

xlsigned commented 2 weeks ago

Closing as duplicate of #7844.

Well, I see you tried to create a PR to enable cross-site-language translations some time ago ...

Please open an issue in the documentation repository regarding suggested changes to the documentation.

https://github.com/gohugoio/hugoDocs/issues/2619