Module: Localizer::Helper

Defined in:
lib/localizer/helper.rb

Instance Method Summary collapse

Instance Method Details



35
36
37
38
39
# File 'lib/localizer/helper.rb', line 35

def link_to_locale locale, name
  active = (I18n.locale.to_s == locale.to_s)
  link_to image_tag("flags/#{locale}.png", :title => name), 
          send( controller.action_name+'_path', locale ), :class => (active ? 'active' : '')
end

#localeObject



3
4
5
# File 'lib/localizer/helper.rb', line 3

def locale
  params[:locale] || 'it'
end

#locales(options = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/localizer/helper.rb', line 27

def locales options = {}
  locales = Localizer.config.locales
  if options[:exclude]
    locales - [ options[:exclude] ]
  end
  locales
end

#localized_current_path(locale) ⇒ Object



41
42
43
# File 'lib/localizer/helper.rb', line 41

def localized_current_path locale
  url_for(:action => nil, :locale => locale)
end

#localized_rootObject



7
8
9
# File 'lib/localizer/helper.rb', line 7

def localized_root
  locale == 'it' ? root_path : local_root_path(locale)
end

#when_locale(locale) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/localizer/helper.rb', line 19

def when_locale locale
  locale_backup = I18n.locale
  I18n.locale = locale
  result = yield locale
  I18n.locale = locale_backup
  return result
end

#with_locale(locale) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/localizer/helper.rb', line 11

def with_locale locale
  locale_backup = I18n.locale
  I18n.locale = locale
  result = yield locale
  I18n.locale = locale_backup
  return result
end