Created
December 22, 2016 02:53
-
-
Save hakanai/90ebac256396317fec41c5f10245c8dd to your computer and use it in GitHub Desktop.
Doing it wrong (i.e., typical JavaScript developer skill level)
This file contains hidden or 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
| 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