module ConversionsWithI18nLabel
Pour que label prenne en compte les formats localisés
Public Class Methods
included(base)
click to toggle source
Constructeur de module
# File lib/translations_ennder/conversions_with_i18n_label.rb, line 4 def self.included(base) base.instance_eval do # puts "#{base.name}.instance_eval" alias_method_chain :label, :i18n end end
Public Instance Methods
label_with_i18n(object_name, method, text = nil, options = {})
click to toggle source
# File lib/translations_ennder/conversions_with_i18n_label.rb, line 12 def label_with_i18n(object_name, method, text = nil, options = {}) # Rails.logger.debug "DEBUG JBA : #{self.class.name}.label_with_i18n(#{object_name}, #{method}, #{text}, #{options})" if !text.blank? #PAS de changement du comportement si un libellé a été fournir return label_without_i18n(object_name, method, text, options) end begin _label_trans = I18n.t("activerecord.attributes.#{object_name.to_s.tableize.singularize}.#{method}", :raise => true) rescue I18n::MissingTranslationData # Rails.logger.debug "DEBUG JBA : traduction PAS trouvée(activerecord.attributes.#{object_name.to_s.tableize.singularize}.#{method})" #PAS de changement du comportement si aucune traduction trouvée _label_trans = text end # Rails.logger.debug "DEBUG JBA : traduction =[#{_label_trans}]" label_without_i18n(object_name, method, _label_trans, options) end