Module: Telegram::Bot::UpdatesController::Translation

Extended by:
ActiveSupport::Concern
Included in:
Telegram::Bot::UpdatesController
Defined in:
lib/telegram/bot/updates_controller/translation.rb

Overview

Provides helpers similar to AbstractController::Translation but by default uses ‘action_name_i18n_key` in lazy translation keys which strips `!` from action names by default. This makes translating strings for commands more convenient.

To disable this behaviour use ‘alias_method :action_name_i18n_key, :action_name`.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#action_name_i18n_keyObject

Strips trailing ‘!` from action_name.



36
37
38
# File 'lib/telegram/bot/updates_controller/translation.rb', line 36

def action_name_i18n_key
  action_name.chomp('!')
end

#localize(*args) ⇒ Object Also known as: l



40
41
42
# File 'lib/telegram/bot/updates_controller/translation.rb', line 40

def localize(*args)
  I18n.localize(*args)
end

#translate(key, **options) ⇒ Object Also known as: t

See toplevel description.



23
24
25
26
27
28
29
30
31
32
# File 'lib/telegram/bot/updates_controller/translation.rb', line 23

def translate(key, **options)
  if key.to_s.start_with?('.')
    path = controller_path.tr('/', '.')
    defaults = [:"#{path}#{key}"]
    defaults << options[:default] if options[:default]
    options[:default] = defaults.flatten
    key = "#{path}.#{action_name_i18n_key}#{key}"
  end
  I18n.translate(key, **options)
end