Sha256: d4ff594f4cf3058195c1a77d7a5ea7ceee548446f78a73c800c71a24b82e7724
Contents?: true
Size: 1.49 KB
Versions: 9
Compression:
Stored size: 1.49 KB
Contents
ActiveModel::Translation.class_eval do # adds a default pluralization and singularization for english # useful to avoid to set a locale 'en' file and avoid # to pass around pluralize calls for 'en' defaults in hobo def human_attribute_name_with_en_pluralization_default(attribute, options={}) if I18n.locale.to_s.match(/^en/) unless options[:count].blank? # skip default if we don't pass any count default = options[:count] == 1 ? attribute.to_s.singularize.humanize : # singularize possible plural attributes attribute.to_s.pluralize.humanize options.merge! :default => default end end human_attribute_name_without_en_pluralization_default(attribute, options) end alias_method_chain :human_attribute_name, :en_pluralization_default # Similar to human_name_attributes, this method retrieves the localized help string # of an attribute if it is defined as the key "activemodel.attribute_help.<attribute_name>", # otherwise it returns "". def attribute_help(attribute, options = {}) defaults = lookup_ancestors.map do |klass| :"#{self.i18n_scope}.attribute_help.#{klass.model_name.underscore}.#{attribute}" end defaults << :"attribute_help.#{attribute}" defaults << options.delete(:default) if options[:default] defaults << '' options.reverse_merge! :count => 1, :default => defaults I18n.translate(defaults.shift, options) end end
Version data entries
9 entries across 9 versions & 1 rubygems