Module: R18n::Rails::Helpers

Included in:
Controller
Defined in:
lib/r18n-rails/helpers.rb

Instance Method Summary collapse

Instance Method Details

#l(obj, *params) ⇒ Object Also known as: localize

Extend l helper to use also R18n syntax.

l Time.now                    # Rails I18n default format
l Time.now, :format => :short # Rails I18n style
l Time.now, :human            # R18n style


52
53
54
55
56
57
58
# File 'lib/r18n-rails/helpers.rb', line 52

def l(obj, *params)
  if params.empty? or params.first.is_a? Hash
    super(obj, *params)
  else
    r18n.l(obj, *params)
  end
end

#r18nObject

Return current R18n I18n object, to use R18n API:

  • r18n.available_locales – available application translations.

  • r18n.locales – List of user locales

  • r18n.reload! – Reload R18n translations

You can get translations by r18n.user.name, but t helper is more beautiful, short and also support R18n syntax.



30
31
32
# File 'lib/r18n-rails/helpers.rb', line 30

def r18n
  R18n.get
end

#t(*params) ⇒ Object Also known as: translate

Extend t helper to use also R18n syntax.

t 'user.name' # Rails I18n style
t.user.name   # R18n style


38
39
40
41
42
43
44
# File 'lib/r18n-rails/helpers.rb', line 38

def t(*params)
  if params.empty?
    r18n.t
  else
    super(*params)
  end
end