Using custom Variables in translated files

Tip to get variables from translated files. For example

i18n/en.toml

[desc]
  other = "lorem ipsum {{ .Year }} dola sit amet"

i18n/fr.toml

[desc]
  other = "lorem ipsum {{ .Year }} dola sit amet"

template e.g footer.html

{{ T "desc (dict "Year" now.Year ) }}

will print out

lorem ipsum 2023 dola sit amet

Credit: stack theme.

1 Like

See also:
https://gohugo.io/functions/lang/translate/

With simple translations (no pluralization) you can just do:

desc = "lorem ipsum {{ .Year }} dola sit amet"

Will look into that. This idea was what I was after in this question but I did not understand it at the time.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.