#22 ✓resolved
iwakura-taro

Incorrect underscore removal before localization in error_messages_for

Reported by iwakura-taro | January 20th, 2009 @ 05:42 PM

There are model, for example, FamilyRole. For tranlating it name and attributes using various conventions

activerecord: models:

family role: familia     #here

attributes:

family_role:              #and here
  name: Namae

Seems, this is not right.

Comments and changes to this ticket

  • Sven Fuchs

    Sven Fuchs January 22nd, 2009 @ 12:00 AM

    iwakura-taro, I'm not sure I get the question or problem :)

    Could you please try to rephrase it?

    Thanks!

  • iwakura-taro

    iwakura-taro January 22nd, 2009 @ 10:07 AM

    We have model, which name has more than one world. For example FamilyRole. In order to translate application to some language, we make YAML file config/locales/hz.yaml. In that YAML file we must have references to our model, when we describe model itself, we must use its name in lovercase without underscore (in our sample, family role), but when we describe its model attributes, we using other convention in naming some model, in lovercase, without space, with space (in our sample, family_role). Seems, it is not good to have various conventions here.

  • Yves-Eric Martin

    Yves-Eric Martin April 1st, 2009 @ 12:53 AM

    Posting under this ticket as I think the problem I am going to suggest fixing is the one iwakura-taro was referring to.

    For reference, the problem has been already mentioned twice on the mailing list: here and here.

    The problem is in (looking at Rails 2.3.2): vendor/rails/actionpack/lib/action_view/helpers/active_record_helper.rb

    Snippet from that file, in the error_messages_for method:

    
    192:           I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale|
    193:             header_message = if options.include?(:header_message)
    194:               options[:header_message]
    195:             else
    196:               object_name = options[:object_name].to_s.gsub('_', ' ')
    197:               object_name = I18n.t(object_name, :default => object_name, :scope => [:activerecord, :models], :count => 1)
    198:               locale.t :header, :count => count, :model => object_name
    

    On line 196, the underscores are replaced by spaces in the object_name. The result is then used as the key for our localization call. That is why people report having to use "object name" (with spaces) instead of the expected "object_name" (with underscores) in their translation files.

    It's 8AM and I just pulled and allnighter, so forgive me for now writing and testing a proper patch, but I'll wager that a fix would look something like:

    
    196:               object_name = options[:object_name].to_s
    197:               object_name = I18n.t(object_name, :default => object_name.gsub('_', ' '), :scope => [:activerecord, :models], :count => 1)
    
  • Yves-Eric Martin

    Yves-Eric Martin April 1st, 2009 @ 12:55 AM

    • Title changed from “AR model name with probel” to “Incorrect underscore removal before localization in error_messages_for”
  • Yves-Eric Martin

    Yves-Eric Martin April 1st, 2009 @ 12:20 PM

    Jose Valim has submitted a patch on the Rails tracker issue #2390.

    I believe this issue does indeed belongs to the Rails tracker rather than here, as it is a problem with Rails not using properly the I18n framework, and not an issue with the I18n framework itself.

    So, this ticket can probably be closed.

  • Sven Fuchs

    Sven Fuchs April 8th, 2009 @ 01:59 PM

    • State changed from “new” to “resolved”

    Closing this as it seems resolved with #2390 as of http://github.com/rails/rails/co...

    Please reopen if I'm getting things wrong.

  • peyila

    peyila March 14th, 2020 @ 09:37 AM

    Initial You got a awesome blog .I determination be involved in plus uniform minutes. i view you got truly very functional matters , i determination be always checking your blog blesss. 토토사이트

  • peyila

    peyila March 18th, 2020 @ 08:43 PM

    Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written. زيادة متابعين

  • peyila

    peyila March 19th, 2020 @ 03:50 PM

    Normally when I browse the internet I search for web-sites that provide reliable information and so I found this site. Very often when I have been to this web site I've truly really liked the great content listed here. I will be certain to look for your next post.. Thanks for the fantastic post I am going to come back in the future. buy virtual number

  • peyila

    peyila March 21st, 2020 @ 03:01 PM

    In this case you will begin it is important, it again produces a web site a strong significant internet site: 검증사이트

  • peyila

    peyila March 22nd, 2020 @ 09:50 AM

    I should assert barely that its astounding! The blog is informational also always fabricate amazing entitys. 바카라사이트

  • peyila

    peyila March 22nd, 2020 @ 09:54 AM

    I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. 사설토토

  • peyila

    peyila March 23rd, 2020 @ 09:33 AM

    I use basically superior fabrics : you will discover these products by: мебели софия

  • peyila

    peyila March 23rd, 2020 @ 09:45 AM

    This is helpful, nonetheless it can be crucial so that you can check out the following website: мебели варна

  • peyila

    peyila March 24th, 2020 @ 10:43 AM

    I use basically superior fabrics : you will discover these products by: linq at beauty world condo

  • peyila

    peyila March 24th, 2020 @ 10:47 AM

    I wrote about a similar issue, I give you the link to my site. penrose showflat

  • peyila

    peyila March 24th, 2020 @ 10:49 AM

    Acknowledges for penmanship such a worthy column, I stumbled beside your blog besides predict a handful advise. I want your tone of manuscript... 19 nassim showflat

  • peyila

    peyila March 24th, 2020 @ 10:52 AM

    It is especially decent, though look into the tips during this home address. parc central ec

  • peyila

    peyila March 24th, 2020 @ 10:55 AM

    Here you will learn what is important, it gives you a link to an interesting web page: clavon condo price

  • peyila

    peyila March 24th, 2020 @ 10:57 AM

    You bear through a awesome vacancy. I sanity definitely quarry it moreover personally suggest to my buddys. I am self-possessed they determination be benefited from this scene. midtown modernprice

  • peyila

    peyila March 24th, 2020 @ 11:00 AM

    This is helpful, nonetheless it can be crucial so that you can check out the following website: clavon condo price

  • peyila

    peyila March 29th, 2020 @ 09:43 AM

    For true fans of this thread I will address is a free online! Project Management Software

  • peyila

    peyila March 29th, 2020 @ 09:45 AM

    I use only high quality materials - you can see them at: Signs Making

  • peyila

    peyila March 29th, 2020 @ 09:48 AM

    It is quite beneficial, although think about the facts when it reaches this target. Nannies

  • peyila

    peyila April 6th, 2020 @ 09:48 PM

    For this web site, you will see our account, remember to go through this info. Satta Matka

  • lookpong

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

Pages