module AlchemyCrm::I18nHelpers

Public Class Methods

included(controller) click to toggle source
# 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

Public Instance Methods

alchemy_crm_t(key, options={}) click to toggle source

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.

# 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={}) click to toggle source

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.

# 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) click to toggle source
# 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