JSFiddle - React, Tailwind, and code Playground

by Brynner

HTML

<div id="result">...</div>

JavaScript

function getPropertyValue(obj, desc) {
  var arr = desc.split('.');
  while (arr.length && (obj = obj[arr.shift()]));
  return obj;
}

function text(name, params = {}) {
    var i18n = 
    {
    		"about": "About",
        "account": {
        		"welcome": "Welcome "+params.username,
            "info": "Something here."
        }
    };
    return getPropertyValue(i18n, name);
}

var result = text('account.welcome', {username: 'Brynner'});

document.querySelector('#result').innerHTML = result;