Coder Social home page Coder Social logo

paperclip-globalize3's Introduction

Paperclip::Globalize3

Build Status

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

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

Currently, paperclip 3.x (>= 3.3) and globalize3 0.3 are supported.

For paperclip 2.x support please use the 0.x versions of this gem.

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"
  translates :avatar_file_name, :avatar_file_size, :avatar_created_at, :avatar_updated_at, :avatar_fingerprint
end

Todo / Future Plans

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

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

mherold avatar vala avatar

Watchers

 avatar James Cloos avatar

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.