class I18n::JS::Formatters::JS
Constants
- JSON_ESCAPE_MAP
Public Instance Methods
format(translations)
click to toggle source
# File lib/i18n/js/formatters/js.rb, line 13 def format(translations) contents = header translations.each do |locale, translations_for_locale| contents << line(locale, format_json(translations_for_locale)) end contents << (@suffix || '') end
Protected Instance Methods
header()
click to toggle source
# File lib/i18n/js/formatters/js.rb, line 23 def header text = @prefix || '' text + %(#{@namespace}.translations || (#{@namespace}.translations = {});\n) end
line(locale, translations)
click to toggle source
# File lib/i18n/js/formatters/js.rb, line 28 def line(locale, translations) json_literal = @pretty_print ? translations : %(JSON.parse('#{translations.gsub(/#{Regexp.union(JSON_ESCAPE_MAP.keys)}/){|match| JSON_ESCAPE_MAP.fetch(match) }}')) if @js_extend %(#{@namespace}.translations["#{locale}"] = I18n.extend((#{@namespace}.translations["#{locale}"] || {}), #{json_literal});\n) else %(#{@namespace}.translations["#{locale}"] = #{json_literal};\n) end end