-
-
Save dfkaye/8c07507b16c94451b5ecf2b7b2f2a2b9 to your computer and use it in GitHub Desktop.
i18n in 10 lines of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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