diff --git a/Gemfile b/Gemfile index 709b4785b0..4ae7be828d 100644 --- a/Gemfile +++ b/Gemfile @@ -9,9 +9,7 @@ path "./" do gem "refinerycms-resources" end -# routing-filter needs a newer release than version 0.6.3 gem 'refinerycms-i18n', github: 'refinery/refinerycms-i18n', branch: 'master' -gem 'routing-filter', github: 'svenfuchs/routing-filter', branch: 'master' # Add support for refinerycms-acts-as-indexed gem 'refinerycms-acts-as-indexed', ['~> 3.0', '>= 3.0.0'] diff --git a/core/app/helpers/refinery/translation_helper.rb b/core/app/helpers/refinery/translation_helper.rb index f3d36f3cbb..058d11fa41 100644 --- a/core/app/helpers/refinery/translation_helper.rb +++ b/core/app/helpers/refinery/translation_helper.rb @@ -1,6 +1,5 @@ module Refinery module TranslationHelper - # Overrides Rails' core I18n.t() function to produce a more helpful error message. # The default one wreaks havoc with CSS and makes it hard to understand the problem. def t(key, options = {}) @@ -14,5 +13,40 @@ def t(key, options = {}) def translated_field(record, field) Refinery::TranslatedFieldPresenter.new(record).call(field) end + + # Markup for the translation links on index pages + def switch_locale(object, edit_path, field = :title) + return unless Refinery::I18n.frontend_locales.many? + + path_minus_locale = remove_locale_from_path(edit_path) + + object.translations + .sort_by { |t| Refinery::I18n.frontend_locales.index(t.locale) } + .select { |t| t.send(field).present? } + .map { |t| locale_markup(path_minus_locale, t.locale) } + .join(' ') + end + + private + + def locale_markup(path, locale) + link_to locale_marker(locale.upcase), locale_edit_path(path, locale), class: [:locale, :edit], title: locale.upcase + end + + # just adding back the switch-locale with the new locale + def locale_edit_path(path, locale) + "#{path}?switch_locale=#{locale}" + end + + def locale_marker(locale) + tag.span locale_text_icon(locale), class: [locale, :locale_marker] + end + + def remove_locale_from_path(edit_path) + uri = URI.parse(edit_path) + queries = URI.decode_www_form(uri.query || '').to_h + uri.query = queries.except('switch-locale').presence + uri.to_s + end end end diff --git a/images/app/views/refinery/admin/images/_grid_view.html.erb b/images/app/views/refinery/admin/images/_grid_view.html.erb index eaf40f540b..5d52c97c15 100644 --- a/images/app/views/refinery/admin/images/_grid_view.html.erb +++ b/images/app/views/refinery/admin/images/_grid_view.html.erb @@ -1,13 +1,20 @@