History

Create I18n helper

Jed Fox committed 8 years ago

Commit 3bd91c91 parent d48396d1 file · +17 −0Browse files

Showing the changes to assets/javascripts (1 of 1 file). Show all

Unified · Split

assets/javascripts/lib/i18n.coffee+17−0
@@ -0,0 +1,17 @@
1+class @I18n
2+ constructor: (@data, lang = 'en') ->
3+ @setLanguage lang
4+
5+ setLanguage: (lang) ->
6+ return false unless @data[lang]
7+ @lang = lang
8+ true
9+
10+ _: (key, substitution) ->
11+ str = @data[@lang][key]
12+ return unless str?
13+
14+ if substitution?
15+ for key in Object.keys(substitution)
16+ str = str.replace("{#{key}}", substitution[key])
17+ str