Git Product home page Git Product logo

paperclip-globalize3's Introduction

Paperclip::Globalize3 Tests

Use locale-specific attachments in your Rails app with paperclip and globalize.

You can transparently read and write your attachments in context of the current locale. E.g. my_model.my_attachment returns a different attachment when your current locale is 'en' compared to when your current locale is 'de'.

Note that this implementation patches some methods in the Paperclip::Attachment class, so make sure you are okay with that.

Compatibility

  • paperclip 5.3 - 6.1
  • globalize 5.3/6.0
  • Rails 4.2/5.0/5.1/5.2/6.0/6.1

Rails 5.2 and later are only tested with paperclip 6.1 (see .travis.yml for details).

For support of previous paperclip / globalize / rails versions please refer to the 3.x versions of this gem.

Maintainance State of This Gem

Since paperclip itself has been deprecated and we currently do not use this gem in active projects any more, further development of this gem (e.g. compatibility with Rails 7.0) is unlikely. If anyone wants to submit a PR, we will of course still try to review + merge.

Installation

Add this line to your application's Gemfile:

gem 'paperclip-globalize3'

And then execute:

$ bundle

Or install it yourself as:

$ gem install paperclip-globalize3

Usage

For each of your attachments which should have support for different locales, set up the following:

  1. Migrate the paperclip columns ('xxx_file_name' etc.) of the attachment to the translation table
  2. Declare in the model that it 'translates' the paperclip fields ('xxx_file_name' etc.)
  3. Use the :locale interpolation for the paperclip url

NOTE: Make sure your translates are always defined after the has_attached_file! (Otherwise the files will not be deleted from the filesystem when the model is destroyed.)

Example:

class User < ActiveRecord::Base
  has_attached_file :avatar,
                    :url => "/system/:attachment/:id/:locale/:style-:fingerprint.:extension"
  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
  translates :avatar_file_name, :avatar_file_size, :avatar_created_at, :avatar_updated_at, :avatar_fingerprint
end

Development

Testing

To setup tests, make sure all the ruby versions defined in .travis.yml are installed on your system.

Run tests via:

  • rake wwtd for all combinations of ruby/rails/paperclip versions (NOTE that when using rake wwtd:parallel there might be some flickering test failures - needs to be investigated)
  • rake wwtd:local for all rails/paperclip versions, but only on current ruby
  • rake spec (or e.g. bundle exec rspec spec --format documentation) with main Gemfile and only on current ruby

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

paperclip-globalize3's People

Contributors

marselshiriyazdanov avatar mcrip avatar mherold avatar pauldub avatar swelther avatar vitaliyadamkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

paperclip-globalize3's Issues

Support globalize 5.0.x

The gem has a dependency on globalize (~> 4.0.0), will it be made to support version 5.0.x?

(:integer), should be :string or :text

Following: "Migrate the paperclip columns ('xxx_file_name' etc.) of the attachment to the translation table"

Hi, here's my migration:

Frame::Contribution.add_translation_fields!({exp1_photo_file_name: :string})
Frame::Contribution.add_translation_fields!({exp1_photo_content_type: :string})
Frame::Contribution.add_translation_fields!({exp1_photo_file_size: :integer})
Frame::Contribution.add_translation_fields!({exp1_photo_updated_at: :timestamp})

What am I missing?

What needs to be done for paperclip 3.x integration?

Greetings there,

Can you give me an idea what would be needed for paperclip 3.x integration? I need translated attachments for a system I work on that uses paperclip 3, and I'd consider doing the integration.

Improve how translated attachments are declared

(moving the random ideas from the "Future Plans" section in the README to here:)

  • Make it easier to specify translated attachments, e.g. using one of these options:
    • support translates :attachment_name
    • support :translated option for has_attached_file or use something like has_translated_attached_file instead
    • eliminate the need to specify; automatically set translates as soon as the :locale interpolation is used
  • Don't depend on order of definition for it to work (translates after has_attached_file)

Locale gets lost when assign multiple and save afterwards

Hi,

when I assign multiple files with different languages and save afterwards, the locale gets lost during the save:

I18n.with_locale(:de) do
  model.file = translation[:file]
end

I18n.with_locale(:it) do
  model.file = translation[:file]
end

I18n.with_locale(:fr) do
  model.file = translation[:file]
end

model.save!

The model is saved successfully, but the there is only one file on my filesystem
because the Attachment object is always the same one.
It's the Attachment for the default locale.

Is it possible to assign multiple translated files and simply save once?
If not I could create a pull request if you are fine with the behaviour.

Best regards

Drop support for paperclip < 5.3.0

I'm thinking after #15 is merged we should also drop support for old paperclip versions < 5.3.0. Lower versions will have deprecation warnings in ruby 2.4+.

(In that case, some conditional code in attachment.rb as well as some of the Appraisals/gemfiles could be removed.)

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.