Method: I18n::Inflector::Interpolate#interpolate

Defined in:
lib/i18n-inflector/interpolate.rb

#interpolate(string, locale, options = {}) ⇒ String

Interpolates inflection values in the given string using kinds given in options and a matching tokens.

ComplexPatternMalformed.new

Options Hash (options):

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/i18n-inflector/interpolate.rb', line 46

def interpolate(string, locale, options = {})
  @inflector_opt_cache = nil

  case string

  when String

    if (locale.nil? || !inflected_locale?(locale))
      string.gsub(PATTERN_REGEXP) { Escapes::PATTERN[$1] ? $& : $1 }
    elsif !string.include?(Markers::PATTERN)
      string
    else
      interpolate_core(string, locale, options)
    end

  when Hash

    options[:inflector_traverses] ?
      string.merge(string) { |k,v| interpolate(v, locale, options) } : string

  when Array

    options[:inflector_traverses] ?
      string.map { |v| interpolate(v, locale, options) } : string

  when Symbol

    if options[:inflector_interpolate_symbols]
      r = interpolate(string.to_s, locale, options)
      r.to_sym rescue :" "
    else
      string
    end

  else

    string

  end

end