From 3bd91c93275777006f4f03a7f08756bc1dde4d3f Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Thu, 19 Apr 2018 15:18:26 -0400 Subject: [PATCH] Create I18n helper --- assets/javascripts/lib/i18n.coffee | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 assets/javascripts/lib/i18n.coffee diff --git a/assets/javascripts/lib/i18n.coffee b/assets/javascripts/lib/i18n.coffee new file mode 100644 index 00000000..a675ea3b --- /dev/null +++ b/assets/javascripts/lib/i18n.coffee @@ -0,0 +1,17 @@ +class @I18n + constructor: (@data, lang = 'en') -> + @setLanguage lang + + setLanguage: (lang) -> + return false unless @data[lang] + @lang = lang + true + + _: (key, substitution) -> + str = @data[@lang][key] + return unless str? + + if substitution? + for key in Object.keys(substitution) + str = str.replace("{#{key}}", substitution[key]) + str