Re:Element: SetHTML() Method on MDN
by jitl on Thursday October 23, 2025 @07:50AM
(#45680770)
You can make your tagged template literal return an array of tokens, so the developer gets to write naturally and no one has to deal with parsing. Just use the json stringified token array as the key in your translation map.
Here's how the tagged template literal maps to tokens:
t`Where is the ${t.thing()}` ->
["Where is the ", ["thing"]] // ["variable name"]
Example rendering a translated string directly:
t`Where is the ${t.thing(user_data)}?`.toString()
Its internet forum so I made it as short as possible over all other style factors. Untested - just trying to express the idea.
Here's how the tagged template literal maps to tokens:
Example rendering a translated string directly: Its internet forum so I made it as short as possible over all other style factors. Untested - just trying to express the idea.