i18next / i18nextify

enables localization of any page with zero effort.
MIT License
61 stars 21 forks source link

Text Node Not Wrapped Inside a HTML Tag Does Not Get Translated #90

Closed suhailgupta03 closed 3 years ago

suhailgupta03 commented 3 years ago

If a text is not wrapped around an HTML tag, it does not get translated. Consider the following HTML snippet

<span>brian silas</span>
brian silas
<p>hello</p>

Here the key brian silas inside span tag gets translated, key hello inside p tag gets translated. But the key brian silas which is not wrapped around any HTML tag does not get translated. Although brian silas is not wrapped around any HTML tag, it is still a text node and must be translated by the library.

Here is also the linked sandbox: https://codesandbox.io/s/billowing-frog-y6hvs?file=/index.html

Screenshot 2020-12-25 at 8 23 05 PM

Note the orphan brian silas marked in red. Although it is not wrapped inside a HTML tag, it is still a valid HTML Text Node.

jamuhl commented 3 years ago

The vdom renderers and mutation observers get appended to root elements -> "to make the magic happen"

As text nodes are limited in not providing those you will need to wrap your content in an outer element.

  <div>
    <p i18next-key="this is a test string">
      this is a test page.
    </p>

    <p>
      this is a test string
    </p>

    <h1>Yeh dhoop kinara</h1>
    <span>Brian Silas</span>
    <span>brian silas</span>
    <br />
    brian silas
    <br />
    <br />
    <button id="btn">Hindi</button>
    <button id="btn-2">Punjabi</button>
  </div>