Sha256: 917ed0b779ac17ecbb3a35b119f9ba9305e978659ef844388718f92ff6446d19
Contents?: true
Size: 1.16 KB
Versions: 4
Compression:
Stored size: 1.16 KB
Contents
require 'paperclip/globalize3/version' require 'paperclip/globalize3/attachment' require 'globalize' require 'paperclip' # Paperclip locale interpolation: if locale fallbacks are used, we need to determine & use the fallback locale Paperclip.interpolates(:locale) do |attachment, _style_name| record = attachment.instance file_name_attr = "#{attachment.name}_file_name" attachment_locale = if record.respond_to?(:translation) && record.translated?(file_name_attr) # determine via metadata if activated (I18n::Backend::Simple.include(I18n::Backend::Metadata)) if record.send(file_name_attr).respond_to?(:translation_metadata) record.send(file_name_attr).translation_metadata[:locale] else # determine via globalize fallback configuration (record.globalize_fallbacks(Globalize.locale) & record.translated_locales).first # (nil if record is new) end else Rails.logger.warn( "WARN You have used :locale in a paperclip url/path for an untranslated model (in #{record.class})." ) nil end (attachment_locale || Globalize.locale).to_s end Paperclip::Attachment.send(:prepend, Paperclip::Globalize3::Attachment)
Version data entries
4 entries across 4 versions & 1 rubygems