google-code-export / globalite

Automatically exported from code.google.com/p/globalite
1 stars 0 forks source link

Allow model attribute to be translated in error view with FieldWithErrors working #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by seb.auge...@gmail.com on 7 Dec 2007 at 9:31

Attachments:

GoogleCodeExporter commented 9 years ago
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.

Original comment by fannar on 28 Feb 2008 at 10:06

GoogleCodeExporter commented 9 years ago
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)

Original comment by mattAimo...@gmail.com on 28 Feb 2008 at 10:31

GoogleCodeExporter commented 9 years ago
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 ?

Original comment by fannar on 29 Feb 2008 at 1:33

GoogleCodeExporter commented 9 years ago
@fannar exactly, that's if Seb's patch works fine. (don't forget that you need 
to
apply the patch yourself)

Original comment by mattAimo...@gmail.com on 29 Feb 2008 at 1:39

GoogleCodeExporter commented 9 years ago
Ok. I have patched it and translated the the field name in my lang/lang.yml 
file but just get __localization_missing__

Original comment by fannar on 29 Feb 2008 at 1:44

GoogleCodeExporter commented 9 years ago
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.

Original comment by fannar on 29 Feb 2008 at 2:22

GoogleCodeExporter commented 9 years ago
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 :)

Original comment by bjarkigud@gmail.com on 28 May 2008 at 10:06

Attachments:

GoogleCodeExporter commented 9 years ago
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.

Original comment by bjarkigud@gmail.com on 28 May 2008 at 10:58

Attachments:

GoogleCodeExporter commented 9 years ago
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?

Original comment by mail2r...@gmail.com on 11 Jun 2008 at 11:11