This project is archived and is in readonly mode.

#6034 new
Robert Pankowecki

human_attribute_name scopes translations differently for nested classes since rails 3.0.2

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

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.

Comments and changes to this ticket

  • Dalibor Filus

    Dalibor Filus December 1st, 2010 @ 12:05 PM

    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"?
    :(

  • Boguś Tarnowski

    Boguś Tarnowski December 1st, 2010 @ 01:44 PM

    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'
    
  • Robert Pankowecki

    Robert Pankowecki December 1st, 2010 @ 02:03 PM

    My temporary workaround is :

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

    Boguś Tarnowski December 1st, 2010 @ 02:17 PM

    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 :(

  • Robert Pankowecki
  • Aditya Sanghi

    Aditya Sanghi December 2nd, 2010 @ 08:42 AM

    • 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.

  • Boguś Tarnowski

    Boguś Tarnowski December 2nd, 2010 @ 09:35 AM

    @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 ?

  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages