Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created October 22, 2017 15:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save WebReflection/dd54114a17dfc1270f0fd14d6e7f47da to your computer and use it in GitHub Desktop.
Save WebReflection/dd54114a17dfc1270f0fd14d6e7f47da to your computer and use it in GitHub Desktop.
i18n in 10 lines of code
function i18n(template) {
for (var
info = i18n.db[i18n.locale][template.join('\x01')],
out = [info.t[0]],
i = 1, length = info.t.length; i < length; i++
) out[i] = arguments[1 + info.v[i - 1]] + info.t[i];
return out.join('');
}
i18n.locale = 'en';
i18n.db = {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment