Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JS Simple i18n key => value
// Array with translations
var translations = {
'first': 'Hello, {{name}}!'
function t(key, values) {
var str = translations[key];
if (!values) {
return str;
for (var value in values) {
str = str.replace(RegExp("\\{{" + value + "\\}}", "gi"), values[value]);
return str;
// Usage
t('first', {name:"test"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment