Hi, I want to pass the i18n stuff to JS, so that I don’t need to store the i18n messages in somewhere else again.
Use case:
Currently, I render the template via partial/template.
<div class="my-modal">
{{ i18n "modal_title" }}
</div>
It works fine, but the modal will be a part of the every single HTML page, so I want to use JS to render that my-modal
. This approach only increases the JS file size.
// pseudo-code
import { default as params } from '@params';
const lang = document.documentElement.getAttribute('lang')
const modalTitle = params.i18n.lang.modal_title
const myModal = `<div class="my-modal">${modalTitle}</div>`
document.body.appendChild(myModal)
But I don’t know if it’s possible to pass the i18n in all translations.
{{ $i18n := newScratch }}
{{ range .Sites }}
{{ $i18n.SetInMap .Lang "modal_title" (i18n "modal_title" .Lang) }}
{{ end }}