Support for I18n #14

Closed
qrush opened this Issue Jun 5, 2009 · 30 comments

Projects

None yet
@qrush
Contributor
qrush commented Jun 5, 2009

Reported by Peter Suschlik

I've added I18n support for error messages:
http://github.com/splattael/paperclip/tree/translate_error_message

Now you can define translations for the errors messages in e.g. your YAML locale file:

en:
  paperclip:
    errors:
      attachment:
        size: "Invalid file size"
        content_type: "Unsupported content type"
        presence: "Cant' be blank"

I fear my tests are a bit messy... I'm new to shoulda :/

Nevertheless, I hope you like the patch :)

@joshk
joshk commented Jul 19, 2009

I agree with this change, but take a look at my patch at http://github.com/joshk/paperclip which uses the proper namespacing for the errors. Currently it only supports I18n, but I will add in backward compatibility shortly.

@joshk
joshk commented Jul 20, 2009

Ok, I have added backwards compatibility and checked to make sure all tests pass. I have also added two extra error message types for the attachment size validation. Any and all comments on my fork would be appreciated.

@cpytel
Member
cpytel commented Jul 22, 2009

Hi,

joshk, can you add i8n specific tests to your fork (something like what is in Peter's fork)?

We can pull your fork in once it has those tests.

@joshk
joshk commented Jul 22, 2009

Hi cpytel,

Thanks for the message, I will get this working asap. Its a bit more complicated to test as I am using the active record errors.add which then uses generate_message to create a very detailed I18n.translate call.

Will let you know when i am finished.

Thanks

@dmitry
Contributor
dmitry commented Oct 19, 2009

Any news?

@joshk
joshk commented Oct 19, 2009

Hi dmitry,

Although I created a patch for Paperclip, I need to start from scratch as I have found a bug or two which causes issues with valid? and errors. I hope to have this finished this week as work is a bit quieter now.

Sorry for the wait

Josh

@dmitry
Contributor
dmitry commented Oct 19, 2009

Thank you, Josh!

@joshk
joshk commented Oct 20, 2009

Hi dmitry,

I have removed my old fork and started from scratch as my old enhancements did not seem clear and concise.

I have pushed a version which uses i18n for error messages, comes with a locale file, includes two extra message types for the size validations, and tests that i18n is being used. All tests pass and no functionality has been removed.

I still have to add backwards compatibility but I would love any and all feedback.

You can take a look at my fork here : http://github.com/joshk/paperclip
Thanks

Josh

@dmitry
Contributor
dmitry commented Oct 21, 2009

Hi Josh,

I've wrote some review comments. If you will need any more help, tell me.

Thanks,
Dmitry

@joshk
joshk commented Oct 21, 2009

Hi Dmitry,

Thanks for the comments, I have commented on your comments and await further comment :)

Thanks

Josh

@rurounijones

Josh's account appears to be dead, is anyone working on this?

@laurynas

I had problem when dynamically changing locale validator messages haven't changed. My solution to this is to use translation key symbol instead of text and let Rails pick translation according to current locale, like this:

validates_attachment_size :data, :less_than => Setting.max_upload_size, :message => :invalid_attachment_size

Add translation to I18n file:

en:
  activerecord:
    errors:
      messages:
        invalid_attachment_size: is over the limit. Please choose a different file.

This works with validates_attachment_presence, validates_attachment_content_type. Current Paperclip throws an exception if you pass a symbol to validates_attachment_size. That's because size validator does some string replacement to inform user about min/max sizes.

I created a tiny patch to fix it, hopefully it will get merged into Paperclip:
http://github.com/laurynas/paperclip/commit/82120eb009573b121568ecb2dc0a948486d3104e

@MarioRicalde

What''s the status on this? did it merge?

@laurynas

I think it didn't merge. I also got one tip by email from Maciej M. regarding to this that could be useful for the others:


however some coders (such as me) use smhtg like that:

lambda{I18n.t('activerecord.errors.messages.paperclip.size', {:min => 20, :max => "#{MAX_SIZE} KB"})}

To make paperclip work with different languages.

Your solution does not allow passing parameters to messages, "wrong size" is not the best msg ;)

"wrong size (up to 200kb)" looks better.

Fix is simple. Before your patch, you need to add:

message = message.call if message.is_a?(Proc)

And then you can use syntax with "lambda"

@danielvlopes

Any update on this? Why it's not merged yet?

For me the solution can use the default Rails behavior to interpolate value in yml. Like:

en:
  paperclip:
    errors:
      attachment:
        size: "must be between %{min} and %{max} bytes."
        content_type: "Unsupported content type"
        presence: "Cant' be blank"

I would like to work on this problem but I need to know what the authors of the gem think about.

@on-d-mand

I Totally agree Daniel, why isn't this merged yet? Loads of good solutions starting from 2009. I love paperclip, but it's a real issue for me that i18n isn't supported properly (like almost any other gem does).

@on-d-mand

I Totally agree Daniel, why isn't this merged yet? Loads of good solutions starting from 2009. I love paperclip, but it's a real issue for me that i18n isn't supported properly (like almost any other gem does).

@alexandrebini

Any update?

@rurounijones

"Still waiting for I18n support" is really rather rude don't you think?

While I usually don't usually this kind of reply I think it is merited here:

This is an open-source project for which you have paid nothing, while the owners of FOSS projects usually do their best to keep things updated they are not beholden to you to do it.

If you need I18n THAT badly and cannot wait for it to be merged then you can always use a fork which has the functionality you need or make your own fork and apply the functionality.

@danielvlopes

Sorry @rurounijones but this was what I said in my comment. I already fixed in my own projects but I would like to help the paperclip and make the solution more elegant.

But I need to know why the core of the project don't want to merge the code. I'll not waste time to create a fork and start to have another gem.

@rurounijones

My apologies @danielvlopes (Just learned about the @!) my comment was not directed at you but at @maxx11 . I should have been clearer

@ghost
ghost commented Mar 27, 2011

Just wanted to agree with @danielvlopes, sorry for any inconvenience.

@cpytel
Member
cpytel commented Jun 15, 2011

Hi everyone, unfortunately @joshk's fork is no longer available. @joshk, any chance you should have this so I can merge it in? I'm sorry for the delay everyone, we'd definitely like to merge this in if we can get it.

@mdi
mdi commented Oct 14, 2011

Any update on this?

@runar
runar commented Oct 20, 2011

Must be faster to rewrite it than to wait for @joshk.

@joshk
joshk commented Oct 20, 2011

Hey Guys,

I am sorry for my lack of reply on this matter.

A lot has changed in paperclip since my fork, but I do believe I still have it floating around on my comp.

I think it would be best to rewrite then to take my changes as I was unable to test my changes against a pre-i18n ActiveRecord (since PC is now tested on Travis against different Gemfile configs, this is no longer the case).

I would volunteer to help with adding this, but I am too swamped with Travis-CI work at the moment, sorry.

Let me know if there is anything else I can help with,

J

@brunomac

:(

@jyurek
Member
jyurek commented Jan 20, 2012

Since this is such an old ticket, I'm going to close it. @joshk is still swamped with work and so can't redo his work. If someone else wants to code this up so that it can be merged into master and submit a pull request, I'd really appreciate it.

@jyurek jyurek closed this Jan 20, 2012
@Backoo
Backoo commented Aug 15, 2012

@danielvlopes, @brunomac: "I Totally agree". As a simple utilizer of the Paperclip gem I really would like to have full support for the I18n gem, but I am not so expert and encouraged to solve the problem (that is, to fork the gem) my self.

I would appreciate if the Official Paperclip gem will support the I18n gem.

See also: http://stackoverflow.com/questions/11963146/how-to-properly-translate-paperclip-error-messages

@yordis
yordis commented Nov 28, 2015

@jyurek @joshk is this support? I only see support for :blank and :spoofed_media_type 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment