Skip to content

Instantly share code, notes, and snippets.

@dfkaye
Forked from WebReflection/i18n.js
Last active February 20, 2019 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfkaye/8c07507b16c94451b5ecf2b7b2f2a2b9 to your computer and use it in GitHub Desktop.
Save dfkaye/8c07507b16c94451b5ecf2b7b2f2a2b9 to your computer and use it in GitHub Desktop.
i18n in 10 lines of code
// @webreflection's i18n.js
// More at https://medium.com/@WebReflection/easy-i18n-in-10-lines-of-javascript-poc-eb9e5444d71e
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