#25 new
Lucas de Castro

Fix AR attribute translations

Reported by Lucas de Castro | May 1st, 2009 @ 03:16 AM

ActiveRecord#human_attribute_name aren't working fine.

Open a rails console and run the following code:


require 'test/unit'

include Test::Unit::Assertions

class Person < ActiveRecord::Base; end

I18n.backend.store_translations :pt,
  :activerecord => {
    :models => {
      :person => 'Pessoa',
      :attributes => {
        :person => {:name => 'Nome'}
      }
    }
  }

assert_equal 'Person', Person.human_name
assert_equal 'Name', Person.human_attribute_name('name')

I18n.locale = :pt

assert_equal 'Pessoa', Person.human_name
assert_equal 'Nome', I18n.t('activerecord.models.attributes.person.name')
assert_equal 'Nome', Person.human_attribute_name('name') # fail

Comments and changes to this ticket

  • Ronald de Gunst

    Ronald de Gunst May 8th, 2009 @ 09:33 PM

    Invalid ticket

    :attributes is no attribute of :models, :attributes is a attribute of :activerecord

    With the right translations definition all is ok.

    I18n.backend.store_translations :pt, :activerecord => {

    :models => {:person => 'Pessoa'},
    :attributes => {:person => {:name => 'Nome'}}
    
    

    }

  • Lucas de Castro

    Lucas de Castro May 8th, 2009 @ 10:02 PM

    Ronald de Gunst, you're right.

    I am sorry.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

Repository for collecting Locale data for Ruby on Rails I18n as well as other interesting, Rails related I18n stuff

People watching this ticket

Pages