Skip to content

Instantly share code, notes, and snippets.

@shesek
Forked from madrobby/i18n.coffee
Created November 14, 2011 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shesek/1365442 to your computer and use it in GitHub Desktop.
Save shesek/1365442 to your computer and use it in GitHub Desktop.
i18n with CoffeeScript
# 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