Skip to content

Instantly share code, notes, and snippets.

@hakanai
Created December 22, 2016 02:53
Show Gist options
  • Select an option

  • Save hakanai/90ebac256396317fec41c5f10245c8dd to your computer and use it in GitHub Desktop.

Select an option

Save hakanai/90ebac256396317fec41c5f10245c8dd to your computer and use it in GitHub Desktop.
Doing it wrong (i.e., typical JavaScript developer skill level)
function translate(key) {
try {
var value = null;
value = eval('Translations.' + key);
_(arguments).chain().tail().each(function (arg, i) {
value = value.replace(new RegExp('\\{' + i + '\\}', 'g'), arg);
});
return value;
}
catch (e) {
console.error('Error translating ' + key, e);
return key;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment