If your site needs to be translated into various language's, there is a setup with the use of i18next.com.
<script type="module">
import { I18n } from 'https://cdn.jsdelivr.net/npm/@hingejs/services/index.min.js'
(async () => {
I18n.enableDocumentObserver()
})()
</script>
<h1 data-i18n="global:header"></h1>
If you are in a current project and now need to add internationalization please follow the steps below
{
"global:header": "This is the home page",
}
import { I18n } from '@hingejs/services'
I18n.enableDocumentObserver()
<h1 data-i18n="global:header"></h1>
const translate = await I18n.init()
let result = translate('global:header')
// file: components/translate-locale.js
import I18n from '@hingejs/services'
window.customElements.define('translate-locale', class extends HTMLElement {
constructor() {
super()
}
async generateTemplate() {
const translate = await I18n.init()
return translate(this.innerText)
}
async connectedCallback() {
this.innerHTML = await this.generateTemplate()
}
})
in the HTML
<translate-locale>global:header</translate-locale>