Module: I18nLink::Helper

Includes:
ActionView::Helpers::UrlHelper, ERB::Util
Defined in:
lib/i18n_link/helper.rb

Instance Method Summary collapse

Instance Method Details



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/i18n_link/helper.rb', line 8

def t_link(translation, options = {})
  options.symbolize_keys!
  string = h(t(translation)).gsub(/%\{[^}]+\}/) do |tl|
    if tl.include?(":")
      token, label = tl[2..-2].split(":", 2)
      addr = options.delete(token.to_sym)
      if addr.nil?
        tl
      else
        link_options = options.delete("#{token}_options".to_sym)
        link_to(label, addr, link_options)
      end
    else
      tl
    end
  end
  raw(string % options)
end