Sha256: 314c5d1f55b54221f104b15bd5913554421f1504eceb426f03752e946f273b1f

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module I18nViz
  module ViewHelpers
    def translate(key, options = {}) # TODO: alias
      if display_i18n_viz? && options[:i18n_viz] != false
        # TODO: ActionController::Base.perform_caching = false  if ActionController::Base.perform_caching == true
        if !options[:scope].blank?
          "#{super(key, options)}--#{options[:scope]}.#{scope_key_by_partial(key)}--"
        else
          "#{super(key, options)}--#{scope_key_by_partial(key)}--"
        end
      else
        super(key, options)
      end
    end
    alias t translate

    def i18n_viz_include_tag # TODO: doesn't work yet
      return unless display_i18n_viz?

      stylesheet_link_tag 'i18n_viz'
      javascript_include_tag 'i18n_viz'
    end

    def display_i18n_viz?
      check_params
    rescue
      false # rescue workaround, because params is weirdly defined in e.g. ActionMailer
    end

    private

    def check_params
      return true if params && params[:i18n_viz]
      return true if cookies && cookies[:i18n_viz]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n_viz-1.2.0 lib/i18n_viz/view_helpers.rb
i18n_viz-1.1.0 lib/i18n_viz/view_helpers.rb