My favorites | Sign in
Project Logo
                
New issue | Search
for
| Advanced search | Search tips
Issue 12: Allow model attribute to be translated in error view with FieldWithErrors working
5 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----
Type-Defect
Priority-Medium


Sign in to add a comment
 
Reported by seb.augereau, Dec 07, 2007
What steps will reproduce the problem?
1. For now, globalite do not help when we want to translate the error field, it only translate the 
error itself
2. A method to Handle model error localization is present but commented. Commented out, it 
translate the error field but rails do not wrap the error field with a FieldWithErrors div, ie the red 
border doesnt appear

The one-line patch split the error msg to symbolize the first word and translate it.

Dont forget the translation otherwise you'll get a Localization missing error :)

cd myapp/vendor/plugins/globalite/lib/rails
patch localized_action_view.rb localized_action_view.rb.patch
restart your mongrel and translate
 
localized_action_view.rb.patch
298 bytes   Download
Comment 1 by fannar, Feb 28, 2008
What do you translate? Say I have in my Users model field named login, email. Where should I translate them ? 
Also is there no way to translate failed_object ?
Thanks for the patch.
Comment 2 by mattAimonetti, Feb 28, 2008
Seb's patch allows you to define the field name in your yaml file.

I didn't include the patch yet since I want to make sure it would work for all. (and
because I'm crazy busy)


Comment 3 by fannar, Feb 28, 2008
Ok. In my lang/is.yml file ?  I have a text_field named login. So in my is.yml I should to login: translated_text ?

Comment 4 by mattAimonetti, Feb 28, 2008
@fannar exactly, that's if Seb's patch works fine. (don't forget that you need to
apply the patch yourself)
Comment 5 by fannar, Feb 28, 2008
Ok. I have patched it and translated the the field name in my lang/lang.yml file but just get __localization_missing__
Comment 6 by fannar, Feb 28, 2008
I works. I had to capitalize, humanize the string in my lang file. So it needs to be Login: Notandanafn but not 
login: notandanafn. Also I would say that the split is not working for me. Because now the error says: 
Notandanafn: Login ...... <-- Should remove the first word in the msg string.
Comment 7 by bjarkigud, May 28, 2008
I made minor modifications to seb's patch. His version was showing both the untranslated and translated version 
of the class attribute. I also changed it so you don't have to supply an uppercase version of the key in the 
lang.yml file. I tested this with Rails 2.1 RC1

cheers :)
localized_action_view.rb.patch
308 bytes   Download
Comment 8 by bjarkigud, May 28, 2008
I made some improvements to my previous patch. Now multi word keys are translated correctly e.g. 
password_confirmation attribute is mapped correctly. Also the code is a bit cleaner and more readable.
localized_action_view.rb.patch
296 bytes   Download
Comment 9 by mail2reis, Jun 11, 2008
Patch works fine, but ive found an error using add_to_base method.

> def validate
>   errors.add_to_base("bla-bla-bla") if some_field.blank?
> end

and we got:

* __localization_missing__ bla-bla-bla!

Any ideas?
Sign in to add a comment

Hosted by Google Code