Project

General

Profile

Actions

Feature #22383

closed

Support of default Active Record (I18n) transliteration paths

Added by Ivan Zabrovskiy over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Category:
I18n
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

For now, in 10-patches.rb we have a redefinition of method human_attribute_name. But default (plain without hierarchy) Redmine style of transliterations are not convinient for some reasons, especially in big projects. So, my proposal is follows: enable ActiveRecord behaviour for finding transliterations path and add in list of search paths custom one from Redmine. Here is a worked snippet of code:

def self.human_attribute_name(attr, options = {})
  prepared_attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '')

  redmine_default =
      [
          :"field_#{name.underscore.gsub('/', '_')}_#{prepared_attr}",
          :"field_#{prepared_attr}" 
      ]

  if options[:default].present?
    options[:default] = [options[:default]] unless options[:default].is_a? Array
    options[:default].unshift redmine_default
  else
    options[:default] = redmine_default
  end

  super
end

In this case we obtain follows chain of search paths:
  1. default AR paths (for example: activerecord.attributes.model_name.field_name)
  2. default Redmine paths (for example: field_content)
  3. user specified paths (specified in :default key from options attribute)
  4. attribute.humanize (from default human_attribute_name from ActiveModel)

Related issues

Related to Redmine - Feature #26618: Support of default ActiveRecord I18n scopes in LabelledFormBuilderClosedGo MAEDA

Actions
Actions

Also available in: Atom PDF