hn • r/hackernews
Comment on: Element: setHTML() method
js can't use a string as a template.my example: a table to lookup translated templates. most translation engines require you to use placeholder strings. this lets you use the template directly as the optional lookup key.simplified with some liberties taken as this can't be done with template literals.
Easy enough to fake with some regexes and loops. but I was a bit surprised that the built in js templates are limited in this manner. const translate_table = {
'where is the ${thing}':'${thing} はどこですか' ,
}
function t(template, args) {
if (translate_table[template] == undefin