Sha256: 940e638e95e3db953f1030cd41b5869f334259dd2955500b541d811e016a0438

Contents?: true

Size: 1.56 KB

Versions: 20

Compression:

Stored size: 1.56 KB

Contents

module Zafu
  module I18n
    def r_load
      if dict = @params[:dictionary]
        dict_content, absolute_url, doc = self.class.get_template_text(dict, @options[:helper], @options[:current_dir])
        return parser_error("dictionary #{dict.inspect} not found") unless doc
        @context[:dict] ||= {}
        begin
          definitions = YAML::load(dict_content)
          definitions['translations'].each do |elem|
            @context[:dict][elem[0]] = elem[1]
          end
        rescue
          return parser_error("invalid dictionary content #{dict.inspect}")
        end
      else
        return parser_error("missing 'dictionary'")
      end
      expand_with
    end

    def _(text)
      if @context[:dict]
        @context[:dict][text] || helper.send(:_,text)
      else
        helper.send(:_,text)
      end
    end

    def r_trans
      static = true
      if @params[:text]
        text = @params[:text]
      elsif @params[:attr]
        text = "#{node_attribute(@params[:attr])}"
        static = false
      else
        res  = []
        text = ""
        @blocks.each do |b|
          if b.kind_of?(String)
            res  << b.inspect
            text << b
          elsif ['show', 'current_date'].include?(b.method)
            res << expand_block(b, :trans=>true)
            static = false
          else
            # ignore
          end
        end
        unless static
          text = res.join(' + ')
        end
      end
      if static
        _(text)
      else
        "<%= _(#{text}) %>"
      end
    end

    alias r_t r_trans
  end # I18n
end # Zafu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
zena-1.2.8 old_zafu/i18n.rb
zena-1.2.7 old_zafu/i18n.rb
zena-1.2.6 old_zafu/i18n.rb
zena-1.2.5 old_zafu/i18n.rb
zena-1.2.4 old_zafu/i18n.rb
zena-1.2.3 old_zafu/i18n.rb
zena-1.2.2 old_zafu/i18n.rb
zena-1.2.1 old_zafu/i18n.rb
zena-1.2.0 old_zafu/i18n.rb
zena-1.1.3 old_zafu/i18n.rb
zena-1.1.2 old_zafu/i18n.rb
zena-1.1.1 old_zafu/i18n.rb
zena-1.1.0 old_zafu/i18n.rb
zena-1.0.0 old_zafu/i18n.rb
zena-1.0.0.rc3 old_zafu/i18n.rb
zena-1.0.0.rc2 old_zafu/i18n.rb
zena-1.0.0.rc1 old_zafu/i18n.rb
zena-1.0.0.beta3 old_zafu/i18n.rb
zena-1.0.0.beta2 old_zafu/i18n.rb
zena-1.0.0.beta1 old_zafu/i18n.rb