Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

human_attribute_name scopes translations differently for nested classes since rails 3.0.2 #760

Closed
lighthouse-import opened this issue May 16, 2011 · 7 comments

Comments

@lighthouse-import
Copy link

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6034
Created by Robert Pankowecki - 2011-02-22 08:32:34 UTC

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.

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by Dalibor Filus - 2010-12-01 12:05:44 UTC

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

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by Boguś Tarnowski - 2010-12-01 13:44:31 UTC

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'

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by Robert Pankowecki - 2010-12-01 14:03:25 UTC

My temporary workaround is :

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

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by Boguś Tarnowski - 2010-12-01 14:17:28 UTC

nice work ;)
i`ve 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 :(

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by Robert Pankowecki - 2010-12-01 23:08:05 UTC

autotranslate :name ??

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by Aditya Sanghi - 2010-12-02 08:42:18 UTC

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

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by Boguś Tarnowski - 2010-12-02 09:35:05 UTC

@robert

i had tried to do labels with I18n from http://blog.plataformatec.com.br/2010/02/rails-3-i18n-changes/
but this way doesn`t 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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant