Module: AlchemyCrm::I18nHelpers

Included in:
Admin::BaseController, Admin::TagsController, BaseController, SubscriptionsController
Defined in:
lib/alchemy_crm/i18n_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



4
5
6
# File 'lib/alchemy_crm/i18n_helpers.rb', line 4

def self.included(controller)
  controller.send(:helper_method, [:i18n_t, :translate_model_attribute, :alchemy_crm_t])
end

Instance Method Details

#alchemy_crm_t(key, options = {}) ⇒ Object

This is a proxy to the ::I18n.t method with an alchem_crm scope.

We can’t use t in views, because Alchemy overrides it and scopes everything into the alchemy namespace.

NOTE:

The keys are scoped into alchemy_crm namespace. Even if you pass a scope this is scoped under alchemy_crm.



17
18
19
20
# File 'lib/alchemy_crm/i18n_helpers.rb', line 17

def alchemy_crm_t(key, options={})
  scope = options[:scope].blank? ? 'alchemy_crm' : "alchemy_crm.#{options.delete(:scope)}"
  ::I18n.t(key, {:scope => scope, :default => key.to_s.humanize}.merge(options))
end

#i18n_t(key, options = {}) ⇒ Object

This is a proxy to the ::I18n.t method without any scope.

We can’t use t in views, because Alchemy overrides it and scopes everything into the alchemy namespace.



26
27
28
# File 'lib/alchemy_crm/i18n_helpers.rb', line 26

def i18n_t(key, options={})
  ::I18n.t(key, options.merge(:default => key.to_s.humanize))
end

#translate_model_attribute(model, key) ⇒ Object



30
31
32
# File 'lib/alchemy_crm/i18n_helpers.rb', line 30

def translate_model_attribute(model, key)
  "alchemy_crm/#{model.to_s.underscore}".classify.constantize.human_attribute_name(key)
end