To mark the content of a node, e.g. <span>…text…</span>, as replaceable, we specify a resource id (here: 5), and replace the text node in question with a dummy character (here: ".") to avoid redundancy: <span data-_=5>.</span>
To mark the title (tooltip) text of <button>…</button>
as replaceable, we specify a resource id (here: 12) with a leading "t" (for title): <button data-_=t12>…</button>
We could also mark both the text content and the title of <button>…text…</button> as replaceable: <button data-_=13t14>.</button>
In the top area of the page, we place a drop-down box with an id (here: 'sL' for 'select Language') to make it accessible for handling its onchange event:
Via (La.s.onchange=La.set)() the module’s set-function is called when a user selects another language. An IIFE (immediately invoked function expression) is used to execute an initial update on pageload.
Function set() does basically the following:
Get current language id from switch element by La.l=+La.s.value
Collect all tagged nodes by document.querySelectorAll('*[data-_]')
For each of the nodes in the collection:
Read resource id info by res_id=node.dataset._
Get resource string from database by res_str=d[res_id][La.l]
Update text node by text.data=res_str, or tooltip by node.title=res_str