module R18n::Rails::Helpers

R18n helpers for Rails.

Public Instance Methods

l(obj, *args, **kwargs) click to toggle source

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
Calls superclass method
# File lib/r18n-rails/helpers.rb, line 51
def l(obj, *args, **kwargs)
  if args.empty? || kwargs.any?
    super(obj, *args, **kwargs)
  else
    r18n.l(obj, *args, now: Time.zone.now, **kwargs)
  end
end
Also aliased as: localize
localize(obj, *args, **kwargs)
Alias for: l
r18n() click to toggle source

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.

# File lib/r18n-rails/helpers.rb, line 29
def r18n
  R18n.get
end
t(*params) click to toggle source

Extend `t` helper to use also R18n syntax.

t 'user.name' # Rails I18n style
t.user.name   # R18n style
Calls superclass method
# File lib/r18n-rails/helpers.rb, line 37
def t(*params)
  if params.empty?
    r18n.t
  else
    super(*params)
  end
end
Also aliased as: translate
translate(*params)
Alias for: t