Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

human_attribute_name scopes translations differently for nested classes since rails 3.0.2

#6034

Calling

Mss::Units::Absence::Search.human_attribute_name(:x)

seeks for translation key:

activemodel.attributes.mss/units/absence/search.x

on Rails 3.0.1

but for

activemodel.attributes.mss.units.absence.search.x
on Rails 3.0.2 and 3.0.3

This is due to changes in :
GEM_HOME/gems/activemodel-3.0.2/lib/active_model/translation.rb

The changelog states that:

Rails 3.0.2 (November 15, 2010)

  • No changes




so i believe that it was not intentional.

Reported by Robert Pankowecki · November 22nd, 2010 @ 02:53 PM

State: new
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Dalibor Filus
    Dalibor Filus

    I was just searching for this bug too and you gave me the answer.
    I'm running Rails 3.0.3.

    Problem is.. what happens now if i corrent my locales to this new design, then it will be considered a bug and "fixed"?
    :(

    December 1st, 2010 @ 12:05 PM

  2. Boguś Tarnowski
    Boguś Tarnowski

    to fix this bug try redesign locale files to
    structure for namespaced models

    Example

    class Hotels::Period
    config/locales/pl/models/hotels/period.yml

    pl:
      activerecord:
        models:
          hotels:
            period: 'okres'
        attributes:
          hotels:
            period:
              name:                  'nazwa'
              start_date:            'początek'
              end_date:              'koniec'
              days:                  'dni'
              discount:              'zniżka'
    

    December 1st, 2010 @ 01:44 PM

  3. Robert Pankowecki
    Robert Pankowecki

    My temporary workaround is :

    ActiveModel::Name.class_eval do
     def i18n_key
      @fixed_i18n_key ||= ActiveSupport::Inflector.underscore(self).to_sym
     end
    end
    

    December 1st, 2010 @ 02:03 PM

  4. Boguś Tarnowski
    Boguś Tarnowski

    nice work ;)
    ive another interesting problem with i18n on forms helpers

      = form_for(@period, :url => period_path(@period), :html => { :multipart => true, :method => :put }) do |f|
        = f.label :name, :class => 'form-label size-60 fl-space2'
    

    autotranslate :name doesn't work with namespaced models :(

    December 1st, 2010 @ 02:17 PM

  5. Robert Pankowecki
  6. Aditya Sanghi
    Aditya Sanghi
    • Importance changed from to Low

    @robert, as i understand, the fix is correct, only the CHANGELOG is not. Right? dot notation should be the correct way.

    December 2nd, 2010 @ 08:42 AM

  7. Boguś Tarnowski
    Boguś Tarnowski

    @robert

    i had tried to do labels with I18n from http://blog.plataformatec.com.br/2010/02/rails-3-i18n-changes/
    but this way doesnt work

    i found answer.
    'action_view/helpers/form_helper.rb' lines 890

                p "#{object_name}.#{method_name}" # me puts here
                I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence
    
    
    return "hotels_period.name"
    

    so in locales yml, keys must be like :

    pl:
    helpers:

    label:
      hotels_period:
        name:                  'nazwa'
    

    not

      hotels:
        period:
          name:                  'nazwa'
    

    its just another inconsistence ?

    December 2nd, 2010 @ 09:35 AM

  8. bingbing