Module: R18n::Rails::Helpers

Included in:
R18n::Rails::HooksHelper::Common
Defined in:
lib/r18n-rails/helpers.rb

Overview

R18n helpers for Rails.

Instance Method Summary collapse

Instance Method Details

#l(obj, *args, **kwargs) ⇒ 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


51
52
53
54
55
56
57
# 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

#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.



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

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


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

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