0

I'm trying to i18n the image_uid attribute in my model so I can have different images with different languages. I'm using globalize3 and dragonfly.

The problem is that is not working at all. It usually uploads the spanish image (which is the default locale in my app), but it doesn't work with other locales. I don't get any error or trace, it just doesn't work.

The model is quite simple:

image_accessor :image  
translates :image_uid

Any idea?

c69
  • 19,951
  • 7
  • 52
  • 82
Víctor
  • 637
  • 2
  • 7
  • 14

1 Answers1

0

:image_uid is the uniqe id to identify the image and therefore not suitable for translation. But if a :image_name attribute is present Dragonfly uses that as filename.

If you want to have a different image for every language because you e.g insert text, you have to watch out that the name or more precisely the url is always different, e.g. you could append the locale to the url: ?locale=en, or name your files translation.en.jpg. To assign the name you can use the helper methods @model.image.name, .basename, and .ext.

If you want only the filename to change and always have the same image served you need a url rewrite engine and remove the filename before your cache. Otherwise unneeded copies of the same image would be created and waste your disk space and processing power.

Using the rack-rewrite and rack-cache gems it would look something like that:

require 'dragonfly/rails/images'

Rails.application.middleware.insert_before(Rack::Cache, Rack::Rewrite) do
  rewrite %r{/media/([^/]+)/[^?]*(.*)}, '/media/$1$2'
end
Kaworu
  • 2,116
  • 1
  • 14
  • 8