Sha256: 9a5059c3b1224e5774c00ed698cc1079fccb3f8d97fe05adb93752a1a8768f38

Contents?: true

Size: 865 Bytes

Versions: 5

Compression:

Stored size: 865 Bytes

Contents

require "i18n/js/formatters/base"

module I18n
  module JS
    module Formatters
      class JS < Base
        def format(translations)
          contents = header
          translations.each do |locale, translations_for_locale|
            contents << line(locale, format_json(translations_for_locale))
          end
          contents
        end

        protected

        def header
          text = @prefix || ''
          text + %(#{@namespace}.translations || (#{@namespace}.translations = {});\n)
        end

        def line(locale, translations)
          if @js_extend
            %(#{@namespace}.translations["#{locale}"] = I18n.extend((#{@namespace}.translations["#{locale}"] || {}), #{translations});\n)
          else
            %(#{@namespace}.translations["#{locale}"] = #{translations};\n)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
i18n-js-3.5.1 lib/i18n/js/formatters/js.rb
i18n-js-3.5.0 lib/i18n/js/formatters/js.rb
i18n-js-3.4.2 lib/i18n/js/formatters/js.rb
i18n-js-3.4.1 lib/i18n/js/formatters/js.rb
i18n-js-3.4.0 lib/i18n/js/formatters/js.rb