Module: Rich::I18n::Core::String::Internationalization::InstanceMethods

Defined in:
lib/rich/i18n/core/string/internationalization.rb

Instance Method Summary collapse

Instance Method Details

#t(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rich/i18n/core/string/internationalization.rb', line 23

def t(options = {})
  self.split(" ").inject([]) do |array, string|
    key              = string.include?(".") ? string.dup : "word.#{string}"
    default          = key.split(".").last
    translating_word = key.starts_with?("word.")

    key.downcase! unless string.match(/^(label|seatholder)\./)

    options[:pluralize]            = "".respond_to?(:pl) && (options[:pluralize].nil? || options[:pluralize])
    options[:translate_callback] ||= LOGGER_PROC if Rails.env.development?

    if options.include? :default
      options[:default] = [options[:default]].flatten << default.humanize
      s = i18n_t key, options
      s = s[:_base] if s.is_a?(Hash)
      value = s.dup
    else
      s = i18n_t key, options.merge({:default => translating_word ? "" : default.humanize})
      value = s.dup

      if translating_word
        unless (translated = !s.empty?) or !"".respond_to?(:pl)
          key.singularize!
          s = i18n_t key, options.merge({:default => ""})
          value = s.dup
        end

        if s.empty?
          s = default.humanize
          value = s.dup
        else
          s = s.pl(options[:count]) unless !options[:pluralize] or (options[:count].nil? and default.dup.pluralize!)
        end
      end
    end

    unless s.gsub!(/^=\s+/, "") || options[:as].to_s == "html"
      s.cp_case! options[:capitalize] ? default.capitalize : default
    end

    array << " " unless array.empty?
    array << EnrichedString.new(s, options.reject{|k, v| !RICH_CMS_OPTIONS.include? k.to_s}.merge({:key => key, :value => value, :locale => I18n.locale, :derivative_key => string}))

  end.join
end