Skip to content

Commit

Permalink
Add ability to translate image_title and image_alt fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Brice Sanchez committed May 1, 2015
1 parent e34b462 commit 180446e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Limited the jquery-ui assets loaded in the backend to the ones we use in the core. [#2735](https://github.com/refinery/refinerycms/pull/2735). [Philip Arndt](https://github.com/parndt)
* Moved the tabs to the left hand side of the screen. [#2734](https://github.com/refinery/refinerycms/pull/2734). [Isaac Freeman](https://github.com/isaacfreeman) & [Philip Arndt](https://github.com/parndt) & [Brice Sanchez](https://github.com/bricesanchez)
* Add extra fields partial in Admin Pages form advanced options [#2943](https://github.com/refinery/refinerycms/pull/2943). [Brice Sanchez](https://github.com/bricesanchez)
* Added ability to translate images title and alt attributes. [#2965](https://github.com/refinery/refinerycms/pull/2965). [Brice Sanchez](https://github.com/bricesanchez)

* [See full list](https://github.com/refinery/refinerycms/compare/2-1-stable...master)

Expand Down
6 changes: 6 additions & 0 deletions images/app/helpers/refinery/admin/images_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def thumbnail_urls(image)

thumbnail_urls
end

# We show the title from the next available locale
# if there is no title for the current locale
def image_title_with_translations(image)
image.title.presence || image.translations.detect { |t| t.title.present?}.title
end
end
end
end
2 changes: 2 additions & 0 deletions images/app/models/refinery/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Refinery
class Image < Refinery::Core::BaseModel
translates :image_title, :image_alt

dragonfly_accessor :image, :app => :refinery_images

include Images::Validators
Expand Down
5 changes: 4 additions & 1 deletion images/app/views/refinery/admin/images/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
object: @image,
include_object_name: false %>
<%= render '/refinery/admin/locale_picker', :current_locale => Globalize.locale if @image.persisted? %>

<div class="field">
<% if action_name =~ /(edit)|(update)/ %>
<p>
Expand Down Expand Up @@ -45,7 +47,8 @@
continue_editing: false,
hide_cancel: (@app_dialog or action_name == 'insert' or from_dialog?),
delete_title: t('delete', scope: 'refinery.admin.images'),
delete_confirmation: t('message', scope: 'refinery.admin.delete', title: @image.image_name) -%>
delete_confirmation: t('message', scope: 'refinery.admin.delete', title: @image.image_name),
cancel_url: refinery.admin_images_path -%>
<% if @app_dialog %>
<input type="hidden" name="app_dialog" value="<%= @app_dialog %>" />
Expand Down
23 changes: 18 additions & 5 deletions images/app/views/refinery/admin/images/_list_view_image.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
<li id="sortable_<%= list_view_image.id %>" class="clearfix record <%= cycle('on', 'on-hover') %>">
<span class="title">
<%= list_view_image.title %>
</span>
<span class='alt'>
<%= action_icon :info, '#', "Title: #{list_view_image.title} Alt text: #{list_view_image.alt}" %>
<%= image_title_with_translations list_view_image %>
</span>

<span class="preview">&nbsp;</span>
<% if Refinery::I18n.frontend_locales.many? %>
<span class='locales'>
<% list_view_image.translations.sort_by{ |t| Refinery::I18n.frontend_locales.index(t.locale)}.each do |translation| %>
<% if translation.image_title.present? %>
<%= link_to refinery.edit_admin_image_path(list_view_image, switch_locale: translation.locale),
class: 'locale', title: translation.locale.upcase do %>

<div class="<%=translation.locale %> locale_marker">
<%= locale_text_icon(translation.locale.upcase) %>
</div>
<% end %>
<% end %>
<% end %>
</span>
<% end %>

<span class="preview"><%= list_view_image.image_name %></span>
<span class="actions">

<%= action_icon :preview, list_view_image.url, t('view_live_html', scope: 'refinery.admin.images') %>
Expand Down
4 changes: 4 additions & 0 deletions images/config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ fr:
replace_image: " la remplacer par celle-ci..."
current_image: Image actuelle
maximum_image_size: "La taille de l'image ne doit pas excéder %{bytes}."
image_title: Titre
image_title_help: Information complémentaire sur l'image
image_alt: Alt
image_alt_help: Texte utilise si l'image ne peut pas être affichée.
actions:
create_new_image: Ajouter une image
records:
Expand Down
14 changes: 14 additions & 0 deletions images/db/migrate/20150430171341_translate_refinery_images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class TranslateRefineryImages < ActiveRecord::Migration
def self.up
Refinery::Image.create_translation_table!({
image_alt: :string,
image_title: :string
}, {
:migrate_data => true
})
end

def self.down
Refinery::Image.drop_translation_table! migrate_data: true
end
end
4 changes: 4 additions & 0 deletions images/lib/refinery/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ def factory_paths
end
end
end

ActiveSupport.on_load(:active_record) do
require 'globalize'
end
1 change: 1 addition & 0 deletions images/refinerycms-images.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- spec/*`.split("\n")

s.add_dependency 'dragonfly', '~> 1.0.0'
s.add_dependency 'globalize', ['>= 4.0.0', '< 5.2']
s.add_dependency 'refinerycms-core', version

s.required_ruby_version = Refinery::Version.required_ruby_version
Expand Down
12 changes: 6 additions & 6 deletions images/spec/support/shared contexts/admin_images_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
let(:dialog_frame_id) {'dialog_iframe'}
let(:initial_path) { refinery.admin_images_path(view: %w(grid list).sample) }

let(:index_item_selector) {'#records li'}
let(:gridview_img_selector) {' > img'}
let(:gridview_title_selector) {'[tooltip]'}
let(:gridview_alt_selector) {'[alt]'}
let(:listview_title_selector) {' > span.title'}
let(:listview_alt_selector) {' > span.alt'}
let(:index_item_selector) {'#records li'}
let(:gridview_img_selector) {' > img'}
let(:gridview_title_selector) {'[tooltip]'}
let(:gridview_alt_selector) {'[alt]'}
let(:listview_title_selector) {' > span.title'}
let(:listview_filename_selector) {' > span.preview'}

end
4 changes: 2 additions & 2 deletions images/spec/support/shared examples/image_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
expect(page).to have_selector(index_item_selector << listview_title_selector, count: image_count)
end

it 'makes the alt attribute of each image available' do
expect(page).to have_selector(index_item_selector << listview_alt_selector, count: image_count)
it 'makes the filename of each image available' do
expect(page).to have_selector(index_item_selector << listview_filename_selector, count: image_count)
end

it 'has an option to switch to grid view' do
Expand Down

0 comments on commit 180446e

Please sign in to comment.