translateHTML()
Prepare the HTML
Add the data-twomi18n
attribute to the elements that need to be translated in the HTML. The value of the attribute is the translation key.
The translateHTML
method is the method that will translate all the elements with the data-twomi18n
attribute.
It takes one argument:
lang
: The language to translate to from thetranslation object
.
Translate HTML attributes
The translateHTML
method can also translate HTML attributes. Add the attribute name after the translation key between brackets to specify the attribute to translate.
You can translate multiple attributes by separating them with a space.
Note: When the attribute is not specified, the innerText
attribute is used.
Example
See more examples here.
See
Fallbacks
.