-
-
Save shesek/1365442 to your computer and use it in GitHub Desktop.
i18n with CoffeeScript
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
# Works with `global` instead of `window` when available (nodejs environment), no Backbone dependency, | |
# no ev[ai]l for rendering variables and a shorter `{...}` syntax. | |
(global or window).t = (id, vars = {}) -> | |
(i18n[__locale][id] or i18n.en[id] or "(?) #{id}") | |
.replace /\{(\w+)\}/g, (a, k) -> vars[k] or "?#{k}" | |
### | |
i18n= | |
de: | |
'foo, {bar}': '{bar} qux!' | |
__locale = 'de' | |
alert t 'foo, {bar}', bar: 123 | |
### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment