src/i18n.js
/* One way to do 'static' HTML page translations is with client-side code that scans for a data attribute.
     This is an alternative to performing the translations on the back end.
  */
One way to do 'static' HTML page translations is with client-side code that scans for a data attribute.
This is an alternative to performing the translations on the back end.
One way to do ' static ' HTML page translations is with client - side code that scans for a data attribute . This is an alternative to performing the translations on the back end .
translatePage() {
    const elements = Array.from(document.querySelectorAll('[data-i18n]'))
    elements.forEach(element => {
      const i18nKey = element.dataset.i18n
      element.textContent = this._translator(i18nKey)
      this._ensureDirAttribute(element)
    })
    const elementsUnsafe = Array.from(document.querySelectorAll('[data-i18n-unsafe]'))
    elementsUnsafe.forEach(element => {
      const i18nKey = element.dataset.i18nUnsafe
      element.innerHTML = this._translator(i18nKey)
      this._ensureDirAttribute(element)
    })
    this._attributeMap.forEach(def => this.translateAttribute(def))
    this.translateDates().translateNumbers().translateDecorators()
  }
translatePage ( ) { const elements = Array . from ( document . querySelectorAll ( '[data-i18n]' ) ) elements . forEach ( element => { const i18nKey = element . dataset . i18n element . textContent = this . _translator ( i18nKey ) this . _ensureDirAttribute ( element ) } ) const elementsUnsafe = Array . from ( document . querySelectorAll ( '[data-i18n-unsafe]' ) ) elementsUnsafe . forEach ( element => { const i18nKey = element . dataset . i18nUnsafe element . innerHTML = this . _translator ( i18nKey ) this . _ensureDirAttribute ( element ) } ) this . _attributeMap . forEach ( def => this . translateAttribute ( def ) ) this . translateDates ( ) . translateNumbers ( ) . translateDecorators ( ) }
One way to do 'static' HTML page translations is with client-side code that scans for a data attribute.
One way to do ' static ' HTML page translations is with client - side code that scans for a data attribute .