From dab53a1ef28ecc281d574b50d3433e806db375cd Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 2 Aug 2026 14:31:50 +0200 Subject: Keep the compared translation independent of the interface language --- app/controllers/revisions_controller.rb | 22 +++---- app/helpers/revisions_helper.rb | 17 +++++ app/views/layouts/_nav_controls.html.erb | 3 +- app/views/node_actions/_change_details.html.erb | 4 +- app/views/page_translations/edit.html.erb | 2 +- app/views/page_translations/show.html.erb | 2 +- app/views/revisions/diff.html.erb | 84 ++++++++++++------------- app/views/revisions/index.html.erb | 10 +-- app/views/revisions/show.html.erb | 6 +- 9 files changed, 81 insertions(+), 69 deletions(-) (limited to 'app') diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb index cddb9e72..b8e66218 100644 --- a/app/controllers/revisions_controller.rb +++ b/app/controllers/revisions_controller.rb @@ -8,9 +8,9 @@ class RevisionsController < ApplicationController layout 'admin' def index - @node = Node.find(params[:node_id]) - @pages = @node.pages.all - @locale = resolve_locale(params[:locale]) + @node = Node.find(params[:node_id]) + @pages = @node.pages.all + @translation_locale = resolve_locale(params[:translation_locale]) end def diff @@ -31,21 +31,21 @@ class RevisionsController < ApplicationController redirect_to(node_path(@node)) and return end - @locale_summary = @end.locale_diff_summary(@start) - requested_locale = params[:locale].presence&.to_sym - default_locale = @locale_summary.find { |s| s[:changed] }&.dig(:locale) || I18n.default_locale - @locale = @locale_summary.any? { |s| s[:locale] == requested_locale } ? requested_locale : default_locale + @locale_summary = @end.locale_diff_summary(@start) + requested_locale = params[:translation_locale].presence&.to_sym + default_locale = @locale_summary.find { |s| s[:changed] }&.dig(:locale) || I18n.default_locale + @translation_locale = @locale_summary.any? { |s| s[:locale] == requested_locale } ? requested_locale : default_locale @diff_view = params[:view] == "side_by_side" ? :side_by_side : :inline - @diff = @end.diff_against(@start, view: @diff_view, locale: @locale) + @diff = @end.diff_against(@start, view: @diff_view, locale: @translation_locale) @available_layer_pairs = @node.available_layer_pairs @locked_by_other = @node.locked? && @node.lock_owner != current_user end def show - @node = Node.find(params[:node_id]) - @page = @node.pages.find(params[:id]) - @locale = resolve_locale(params[:locale]) + @node = Node.find(params[:node_id]) + @page = @node.pages.find(params[:id]) + @translation_locale = resolve_locale(params[:translation_locale]) end def restore diff --git a/app/helpers/revisions_helper.rb b/app/helpers/revisions_helper.rb index a6290133..25a2aa38 100644 --- a/app/helpers/revisions_helper.rb +++ b/app/helpers/revisions_helper.rb @@ -4,4 +4,21 @@ module RevisionsHelper def describe_page_reference(ref) %w[head draft autosave].include?(ref.to_s) ? ref.to_s.capitalize : "revision #{ref}" end + + def neighbour_revision_pairs node, start_ref, end_ref + return [nil, nil] unless start_ref.to_s.match?(/\A\d+\z/) && + end_ref.to_s.match?(/\A\d+\z/) + + a, b = start_ref.to_i, end_ref.to_i + return [nil, nil] unless (a - b).abs == 1 + + lo, hi = [a, b].minmax + forward = a < b + earlier = forward ? [lo - 1, lo] : [lo, lo - 1] + later = forward ? [hi, hi + 1] : [hi + 1, hi] + + [earlier, later].map do |pair| + pair if pair.all? { |rev| node.pages.exists?(:revision => rev) } + end + end end diff --git a/app/views/layouts/_nav_controls.html.erb b/app/views/layouts/_nav_controls.html.erb index bae1082b..70d5130c 100644 --- a/app/views/layouts/_nav_controls.html.erb +++ b/app/views/layouts/_nav_controls.html.erb @@ -9,7 +9,8 @@ <% end %> - <%= link_to url_for(locale: (:en unless I18n.locale == :en)), + <% locale_target = request.query_parameters.symbolize_keys.except(:controller, :action, :only_path, :host, :port, :protocol, :anchor, :script_name).merge(:locale => (:en unless I18n.locale == :en)) %> + <%= link_to url_for(locale_target), class: "nav_toggle nav_locale", "aria-label" => t(".switch_locale"), title: t(".switch_locale") do %> <%= I18n.locale == :en ? "DE" : "EN" %> diff --git a/app/views/node_actions/_change_details.html.erb b/app/views/node_actions/_change_details.html.erb index 19e2fe29..2da8bfd5 100644 --- a/app/views/node_actions/_change_details.html.erb +++ b/app/views/node_actions/_change_details.html.erb @@ -25,9 +25,9 @@
<% if action_entry.page && action_entry.node %> <% if (diff_params = action_entry.diff_link_params) %> - <%= link_to t("node_actions.view_diff"), diff_node_revisions_path(action_entry.node, diff_params.merge(:locale => locale)) %> + <%= link_to t("node_actions.view_diff"), diff_node_revisions_path(action_entry.node, diff_params.merge(:translation_locale => locale)) %> <% else %> - <%= link_to t("node_actions.view_revision"), node_revision_path(action_entry.node, action_entry.page, :locale => locale) %> + <%= link_to t("node_actions.view_revision"), node_revision_path(action_entry.node, action_entry.page, :translation_locale => locale) %> <% end %> <% end %> diff --git a/app/views/page_translations/edit.html.erb b/app/views/page_translations/edit.html.erb index f398a544..fb879568 100644 --- a/app/views/page_translations/edit.html.erb +++ b/app/views/page_translations/edit.html.erb @@ -2,7 +2,7 @@ <%= t(".editing_prefix") %> <%= @locale.to_s.upcase %> <%= t(".translation_of") %> <%= title_for_node(@node) %>. -

<%= link_to t("page_translations.revision_history_link"), node_revisions_path(@node, :locale => @locale) %>

+

<%= link_to t("page_translations.revision_history_link"), node_revisions_path(@node, :translation_locale => @locale) %>

<%= t(".metadata_hint_prefix") %> <%= link_to t(".metadata_hint_link"), edit_node_path(@node) %>. diff --git a/app/views/page_translations/show.html.erb b/app/views/page_translations/show.html.erb index 0fbcd0b6..5f94ac38 100644 --- a/app/views/page_translations/show.html.erb +++ b/app/views/page_translations/show.html.erb @@ -1,6 +1,6 @@

<%= t(".title") %> — <%= title_for_node(@node) %>

-

<%= link_to t("page_translations.revision_history_link"), node_revisions_path(@node, :locale => @locale) %>

+

<%= link_to t("page_translations.revision_history_link"), node_revisions_path(@node, :translation_locale => @locale) %>

diff --git a/app/views/revisions/diff.html.erb b/app/views/revisions/diff.html.erb index 1318bd37..ba320365 100644 --- a/app/views/revisions/diff.html.erb +++ b/app/views/revisions/diff.html.erb @@ -4,57 +4,51 @@ <%= link_to t(".revisions_link"), node_revisions_path(@node) %>

-

- <%= t(".comparing") %> <%= describe_page_reference(params[:start_revision]) %> - <%= t(".against") %> <%= describe_page_reference(params[:end_revision]) %> - <%= t(".showing_prefix") %> <%= @locale.to_s.upcase %> <%= t(".translation_suffix") %> -

+<% numeric_comparison = params[:start_revision].to_s =~ /\A\d+\z/ && params[:end_revision].to_s =~ /\A\d+\z/ %> +<% start_control = numeric_comparison ? + select_tag(:start_revision, options_for_select(@node.pages.map(&:revision), params[:start_revision].to_i)) : + content_tag(:strong, describe_page_reference(params[:start_revision])) + hidden_field_tag(:start_revision, params[:start_revision]) %> +<% end_control = numeric_comparison ? + select_tag(:end_revision, options_for_select(@node.pages.map(&:revision), params[:end_revision].to_i)) : + content_tag(:strong, describe_page_reference(params[:end_revision])) + hidden_field_tag(:end_revision, params[:end_revision]) %> +<% locale_control = select_tag(:translation_locale, options_for_select( + @locale_summary.map { |s| [s[:changed] ? t("revisions.locale_changed", :lang => s[:locale].to_s.upcase) : s[:locale].to_s.upcase, s[:locale]] }, + @translation_locale)) %> +<% view_control = select_tag(:view, options_for_select( + [[t("revisions.inline"), "inline"], [t("revisions.side_by_side"), "side_by_side"]], @diff_view.to_s)) %> +<% earlier, later = neighbour_revision_pairs(@node, params[:start_revision], params[:end_revision]) %> -<% if @locale_summary.size > 1 %> -

- <%= t("revisions.locale_label") %> - <% @locale_summary.each_with_index do |s, i| %> - <%= " · ".html_safe if i > 0 %> - <% label = "#{s[:locale].to_s.upcase}#{' *' if s[:changed]}" %> - <% if s[:locale] == @locale %> - <%= label %> - <% else %> - <%= link_to label, diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: @diff_view, locale: s[:locale]) %> - <% end %> +<%= form_tag diff_node_revisions_path(@node), :method => :get, :class => "diff_controls" do %> +

+ <%= t(".comparing_html", :start => start_control, :end => end_control, + :lang => locale_control, :view => view_control) %> +

+

+ <% if earlier %> + <%= link_to t(".pair_link", :from => earlier.first, :to => earlier.last), diff_node_revisions_path(@node, + start_revision: earlier.first, end_revision: earlier.last, + view: @diff_view, translation_locale: @translation_locale) %> + <% else %> + + <% end %> + <%= submit_tag t(".diff_button") %> + <% if later %> + <%= link_to t(".pair_link", :from => later.first, :to => later.last), diff_node_revisions_path(@node, + start_revision: later.first, end_revision: later.last, + view: @diff_view, translation_locale: @translation_locale) %> + <% else %> + <% end %>

-

<%= t(".changed_hint") %>

<% end %> -

- <%= t(".view_label") %> - <% if @diff_view == :inline %> - <%= t("revisions.inline") %> - <% else %> - <%= link_to t("revisions.inline"), diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: 'inline', locale: @locale) %> - <% end %> - · - <% if @diff_view == :side_by_side %> - <%= t("revisions.side_by_side") %> - <% else %> - <%= link_to t("revisions.side_by_side"), diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: 'side_by_side', locale: @locale) %> - <% end %> -

- -<% numeric_comparison = params[:start_revision].to_s =~ /\A\d+\z/ && params[:end_revision].to_s =~ /\A\d+\z/ %> - -<% if numeric_comparison %> - <%= form_tag diff_node_revisions_path do %> - <%= select_tag :start_revision, options_for_select(@node.pages.map{|x| x.revision}, params[:start_revision].to_i) %> - <%= select_tag :end_revision, options_for_select(@node.pages.map{|x| x.revision}, params[:end_revision].to_i) %> - <%= hidden_field_tag :view, @diff_view %> - <%= hidden_field_tag :locale, @locale %> - <%= submit_tag t(".diff_button") %> - <% end %> -<% else %> -

<%= link_to t(".compare_numbered"), node_revisions_path(@node) %>

+<% unless numeric_comparison %> +

+ <%= link_to t(".compare_numbered"), node_revisions_path(@node) %> +

<% end %> + <% if @available_layer_pairs.present? %>
<% @available_layer_pairs.each do |pair| %> @@ -62,7 +56,7 @@ <%= button_to t("nodes.show.diff_layers", :from => t("nodes.show.layer_#{pair.first}"), :to => t("nodes.show.layer_#{pair.last}")), diff_node_revisions_path(@node), method: :get, - params: { start_revision: pair.first, end_revision: pair.last, view: @diff_view, locale: @locale }, + params: { start_revision: pair.first, end_revision: pair.last, view: @diff_view, translation_locale: @translation_locale }, form: { class: 'button_to computation' } %> <% end %> <% if !@locked_by_other && (@node.autosave || @node.draft) %> diff --git a/app/views/revisions/index.html.erb b/app/views/revisions/index.html.erb index 6bcf1820..d118f96a 100644 --- a/app/views/revisions/index.html.erb +++ b/app/views/revisions/index.html.erb @@ -9,10 +9,10 @@ <%= t("revisions.locale_label") %> <% ([I18n.default_locale] + Page.non_default_locales).each_with_index do |locale, i| %> <%= " · ".html_safe if i > 0 %> - <% if locale == @locale %> + <% if locale == @translation_locale %> <%= locale.to_s.upcase %> <% else %> - <%= link_to locale.to_s.upcase, node_revisions_path(@node, :locale => locale) %> + <%= link_to locale.to_s.upcase, node_revisions_path(@node, :translation_locale => locale) %> <% end %> <% end %>

@@ -34,7 +34,7 @@ <%= button_to t(".diff_revisions"), diff_node_revisions_path(@node), method: :post, - params: { locale: @locale }, + params: { translation_locale: @translation_locale }, form: { id: 'diff_form', class: 'button_to computation' }, disabled: true %> " data-selected="<%= t(".selected_word") %>"> @@ -50,10 +50,10 @@ <%= radio_button_tag :start_revision, page.revision, index == 1 %> <%= radio_button_tag :end_revision, page.revision, index == 0 %> <%= page.revision %> - <%= page.translations.find_by(:locale => @locale)&.title || "—" %> + <%= page.translations.find_by(:locale => @translation_locale)&.title || "—" %> <%= page.editor.try(:login) %> <%= page.updated_at %> - <%= link_to t(".show_link"), node_revision_path(@node, page, :locale => @locale) %> + <%= link_to t(".show_link"), node_revision_path(@node, page, :translation_locale => @translation_locale) %> <%= button_to t(".restore_link"), restore_node_revision_path(@node, page), method: :put, diff --git a/app/views/revisions/show.html.erb b/app/views/revisions/show.html.erb index a39071c6..addcfa1a 100644 --- a/app/views/revisions/show.html.erb +++ b/app/views/revisions/show.html.erb @@ -1,13 +1,13 @@ -<% translation = @page.translations.find_by(:locale => @locale) %> +<% translation = @page.translations.find_by(:locale => @translation_locale) %>
-

<%= t(".title", :rev => @page.revision) %>: <%= translation&.title %> (<%= @locale.to_s.upcase %>)

+

<%= t(".title", :rev => @page.revision) %>: <%= translation&.title %> (<%= @translation_locale.to_s.upcase %>)

<%= t("admin.columns.actions") %>
- <%= link_to t(".show_all"), node_revisions_path(@node, :locale => @locale) %> + <%= link_to t(".show_all"), node_revisions_path(@node, :translation_locale => @translation_locale) %>
-- cgit v1.3