Giter Site home page Giter Site logo

Support for I18n about paperclip HOT 30 CLOSED

thoughtbot avatar thoughtbot commented on July 28, 2024 2
Support for I18n

from paperclip.

Comments (30)

joshk avatar joshk commented on July 28, 2024

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.

from paperclip.

joshk avatar joshk commented on July 28, 2024

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.

from paperclip.

cpytel avatar cpytel commented on July 28, 2024

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.

from paperclip.

joshk avatar joshk commented on July 28, 2024

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

from paperclip.

dmitry avatar dmitry commented on July 28, 2024

Any news?

from paperclip.

joshk avatar joshk commented on July 28, 2024

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

from paperclip.

dmitry avatar dmitry commented on July 28, 2024

Thank you, Josh!

from paperclip.

joshk avatar joshk commented on July 28, 2024

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

from paperclip.

dmitry avatar dmitry commented on July 28, 2024

Hi Josh,

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

Thanks,
Dmitry

from paperclip.

joshk avatar joshk commented on July 28, 2024

Hi Dmitry,

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

Thanks

Josh

from paperclip.

rurounijones avatar rurounijones commented on July 28, 2024

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

from paperclip.

laurynas avatar laurynas commented on July 28, 2024

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

from paperclip.

MarioRicalde avatar MarioRicalde commented on July 28, 2024

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

from paperclip.

laurynas avatar laurynas commented on July 28, 2024

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"

from paperclip.

danielvlopes avatar danielvlopes commented on July 28, 2024

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.

from paperclip.

on-d-mand avatar on-d-mand commented on July 28, 2024

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).

from paperclip.

on-d-mand avatar on-d-mand commented on July 28, 2024

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).

from paperclip.

alexandrebini avatar alexandrebini commented on July 28, 2024

Any update?

from paperclip.

rurounijones avatar rurounijones commented on July 28, 2024

"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.

from paperclip.

danielvlopes avatar danielvlopes commented on July 28, 2024

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.

from paperclip.

rurounijones avatar rurounijones commented on July 28, 2024

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

from paperclip.

 avatar commented on July 28, 2024

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

from paperclip.

cpytel avatar cpytel commented on July 28, 2024

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.

from paperclip.

mdi avatar mdi commented on July 28, 2024

Any update on this?

from paperclip.

runar avatar runar commented on July 28, 2024

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

from paperclip.

joshk avatar joshk commented on July 28, 2024

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

from paperclip.

brunomac avatar brunomac commented on July 28, 2024

:(

from paperclip.

jyurek avatar jyurek commented on July 28, 2024

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.

from paperclip.

Backoo avatar Backoo commented on July 28, 2024

@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

from paperclip.

yordis avatar yordis commented on July 28, 2024

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

from paperclip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.