.AllTranslations | jsonify

might seem like an odd question, but is it possible somehow to encode all translations from Hugo into a JSON and rendering that within a script tag?

That way I could use them within Alpine js…

{{ .AllTranslations | jsonify }} seems to run out of memory. New to Hugo so not sure if there’s an alternative approach to this.


What, exactly, do you need in the resulting JSON data?

Basically I’d be happy with a json version of the language file for the currently active language (e.g. i18n/en.yaml)

Edit: What I’m not looking for would be a page translation. I just want some easy way to use the same translated strings in both js and hugo generated html.

Thinking about it: Could I set the i18n directory to be a subpath of the data directory? That would probably be the solution to that problem, right?

Not at the Dev machine right now, so can’t try it.

Mount i18n to data.

source = 'data'
target = 'data'
source = 'i18n'
target = 'data'
<pre>{{ jsonify (dict "indent" "  ") site.Data.en }}</pre>