Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor translation keys #1796

Merged
merged 6 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions app/components/page_list_component/error_summary/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ def self.error_id(number)
"condition_#{number}"
end

def error_object(error_name:, condition_id:, page_index:)
OpenStruct.new(message: I18n.t("page_conditions.errors.error_summary.#{error_name}", page_index:), link: "##{self.class.error_id(condition_id)}")
def error_object(error_name:, condition:, page:)
OpenStruct.new(message: I18n.t("page_conditions.errors.#{error_name}", question_number: page.position), link: "##{self.class.error_id(condition.id)}")
end

def conditions_with_page_indexes
@pages.map { |page| page.routing_conditions.map { |condition| OpenStruct.new(condition:, page_index: page.position) } }
def conditions_with_routing_pages
@pages.map { |page| page.routing_conditions.map { |condition| OpenStruct.new(condition:, routing_page: page) } }
.flatten
end

def errors_for_summary
conditions_with_page_indexes
.map { |condition_with_page_index|
condition_with_page_index.condition.validation_errors.map do |error|
conditions_with_routing_pages
.map { |condition_with_routing_page|
condition_with_routing_page.condition.validation_errors.map do |error|
error_object(
error_name: error.name,
page_index: condition_with_page_index.page_index,
condition_id: condition_with_page_index.condition.id,
page: condition_with_routing_page.routing_page,
condition: condition_with_routing_page.condition,
)
end
}
Expand Down
8 changes: 4 additions & 4 deletions app/components/page_list_component/view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
</dd>
</div>

<% conditions_for_page_with_index(page.id).each do |condition, route_index| %>
<% conditions_for_page_with_index(page.id).each do |condition, _route_index| %>
<div id="<%= PageListComponent::ErrorSummary::View.error_id(condition.id) %>" class="govuk-summary-list__row app-page-list__row <%= class_names( "govuk-form-group--error": condition.has_routing_errors?) %>">
<dt class="govuk-summary-list__key govuk-summary-list__key app-page-list__key">
<%= t("page_conditions.condition_name", page_index: condition_page_position(condition), route_index: route_index) %>
<%= t("page_conditions.condition_name", question_number: condition_page_position(condition)) %>
</dt>

<dd class="govuk-summary-list__value">
<ul class="govuk-list govuk-!-margin-0">
<% condition.validation_errors.each do |error| %>
<li class="app-page_list__route-text--error">
<%= t("page_conditions.errors.page_list.#{error.name}", page_index: page.position) %>
<%= t("page_conditions.errors.#{error.name}", question_number: page.position) %>
</li>
<% end %>
</ul>
Expand All @@ -53,7 +53,7 @@

<dd class="govuk-summary-list__actions govuk-!-padding-bottom-6">
<%= govuk_link_to show_routes_path(form_id: @form_id, page_id: condition.check_page_id) do %>
<%= t("forms.form_overview.edit_with_visually_hidden_text_html", visually_hidden_text: t("page_conditions.condition_name", page_index: page.position, route_index: route_index)) %>
<%= t("forms.form_overview.edit_with_visually_hidden_text_html", visually_hidden_text: t("page_conditions.condition_name", question_number: page.position)) %>
<% end %>
</dd>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/components/page_list_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def page_row_id(record)

def condition_description(condition)
if condition.secondary_skip?
I18n.t("page_conditions.secondary_skip_description", check_page_text: skip_condition_route_page_text(condition), goto_page_text: goto_page_text_for_condition(condition))
I18n.t("page_conditions.secondary_skip_description", check_page_question_text: skip_condition_route_page_text(condition), goto_page_question_text: goto_page_text_for_condition(condition))
else
I18n.t("page_conditions.condition_description", check_page_text: condition_check_page_text(condition), goto_page_text: goto_page_text_for_condition(condition), answer_value: answer_value_text_for_condition(condition))
I18n.t("page_conditions.condition_description", check_page_question_text: condition_check_page_text(condition), goto_page_question_text: goto_page_text_for_condition(condition), answer_value: answer_value_text_for_condition(condition))
end
end

def condition_check_page_text(condition)
check_page = @pages.find { |page| page.id == condition.check_page_id }
I18n.t("page_conditions.condition_check_page_text", check_page_text: check_page.question_text)
I18n.t("page_conditions.condition_check_page_text", check_page_question_text: check_page.question_text)
end

def answer_value_text_for_condition(condition)
Expand All @@ -45,7 +45,7 @@ def answer_value_text_for_condition(condition)
def goto_page_text_for_condition(condition)
if condition.goto_page_id.present?
goto_page = @pages.find { |page| page.id == condition.goto_page_id }
I18n.t("page_conditions.condition_goto_page_text", goto_page_position: goto_page.position, goto_page_text: goto_page.question_text)
I18n.t("page_conditions.condition_goto_page_text", goto_page_question_number: goto_page.position, goto_page_question_text: goto_page.question_text)
elsif condition.skip_to_end
I18n.t("page_conditions.condition_goto_page_check_your_answers")
else
Expand All @@ -72,7 +72,7 @@ def routing_conditions_with_index

def skip_condition_route_page_text(condition)
routing_page = @pages.find { |page| page.id == condition.routing_page_id }
I18n.t("page_conditions.skip_condition_route_page_text", route_page_text: routing_page.question_text, route_page_position: routing_page.position)
I18n.t("page_conditions.skip_condition_route_page_text", route_page_question_text: routing_page.question_text, route_page_question_number: routing_page.position)
end

# Create hash of page_id => [condition, index]
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/pages/conditions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create
condition_input = Pages::ConditionsInput.new(condition_input_params)

if condition_input.submit
redirect_to show_routes_path(form_id: current_form.id, page_id: page.id), success: t("banner.success.route_created", question_position: condition_input.page.position)
redirect_to show_routes_path(form_id: current_form.id, page_id: page.id), success: t("banner.success.route_created", question_number: condition_input.page.position)
else
render template: "pages/conditions/new", locals: { condition_input: }, status: :unprocessable_entity
end
Expand All @@ -51,7 +51,7 @@ def update
condition_input = Pages::ConditionsInput.new(form_params)

if condition_input.update_condition
redirect_to show_routes_path(form_id: current_form.id, page_id: page.id), success: t("banner.success.route_updated", question_position: condition_input.page.position)
redirect_to show_routes_path(form_id: current_form.id, page_id: page.id), success: t("banner.success.route_updated", question_number: condition_input.page.position)
else
render template: "pages/conditions/edit", locals: { condition_input: }, status: :unprocessable_entity
end
Expand All @@ -74,7 +74,7 @@ def destroy

if delete_condition_input.submit
if delete_condition_input.confirmed?
redirect_to form_pages_path(current_form.id, page.id), success: t("banner.success.route_deleted", question_position: delete_condition_input.page.position)
redirect_to form_pages_path(current_form.id, page.id), success: t("banner.success.route_deleted", question_number: delete_condition_input.page.position)
else
redirect_to edit_condition_path(current_form.id, page.id, condition.id)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/pages/routes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def destroy

if @delete_confirmation_input.submit
if @delete_confirmation_input.confirmed?
return redirect_to form_pages_path, success: t("banner.success.page_routes_deleted", question_position: current_form.page_number(page))
return redirect_to form_pages_path, success: t("banner.success.page_routes_deleted", question_number: current_form.page_number(page))
end
else
return render :delete, locals: { current_form:, page:, delete_confirmation_input: @delete_confirmation_input }, status: :unprocessable_entity
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ def delete
if @page.routing_conditions.any? && @page.routing_conditions.first.secondary_skip?
@routing = :start_of_secondary_skip_route

# route owner is condition check page
@route_owner = PageRepository.find(page_id: @page.routing_conditions.first.check_page_id, form_id: current_form.id)
# route page is condition check page
@route_page = PageRepository.find(page_id: @page.routing_conditions.first.check_page_id, form_id: current_form.id)
elsif @page.routing_conditions.any?
@routing = :start_of_route

# route owner is us
@route_owner = @page
# route page is us
@route_page = @page
elsif @page_goto_conditions.any? && @page_goto_conditions.first.secondary_skip?
@routing = :end_of_secondary_skip_route

# route owner is condition check page
@route_owner = PageRepository.find(page_id: @page_goto_conditions.first.check_page_id, form_id: current_form.id)
# route page is condition check page
@route_page = PageRepository.find(page_id: @page_goto_conditions.first.check_page_id, form_id: current_form.id)
elsif @page_goto_conditions.any?
@routing = :end_of_route

# route owner is condition routing page
@route_owner = PageRepository.find(page_id: @page_goto_conditions.first.routing_page_id, form_id: current_form.id)
# route page is condition routing page
@route_page = PageRepository.find(page_id: @page_goto_conditions.first.routing_page_id, form_id: current_form.id)
end

@delete_confirmation_input = Forms::DeleteConfirmationInput.new
Expand Down Expand Up @@ -85,7 +85,7 @@ def move_page
page_to_move.position + 1
end

redirect_to form_pages_path, success: t("banner.success.form.page_moved", question_text: page_to_move.question_text, direction: move_params[:direction], position:)
redirect_to form_pages_path, success: t("banner.success.form.page_moved", question_text: page_to_move.question_text, direction: move_params[:direction], question_number: position)
end

private
Expand Down
10 changes: 5 additions & 5 deletions app/input_objects/pages/secondary_skip_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def routing_page_options
pages_after_current_page(FormRepository.pages(form), page).map { |p| OpenStruct.new(id: p.id, question_text: p.question_with_number) }
end

def page_name(page_id)
def question_name(page_id)
target_page = FormRepository.pages(form).find { |page| page.id == page_id }

page_name = target_page.question_text
page_position = target_page.position
question_text = target_page.question_text
question_number = target_page.position

I18n.t("page_route_card.page_name", page_position:, page_name:)
I18n.t("page_route_card.question_name_long", question_number:, question_text:)
end

def end_page_name
Expand All @@ -73,7 +73,7 @@ def answer_value
end

def continue_to
page.has_next_page? ? page_name(page.next_page) : end_page_name
page.has_next_page? ? question_name(page.next_page) : end_page_name
end

def assign_values
Expand Down
30 changes: 16 additions & 14 deletions app/presenters/route_summary_card_data_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def conditional_route_cards
conditional_routes.map.with_index(1) { |routing_condition, index| conditional_route_card(routing_condition, index) }
end

def conditional_route_card(routing_condition, index)
goto_page_name = routing_condition.skip_to_end ? end_page_name : page_name(routing_condition.goto_page_id)
def conditional_route_card(routing_condition, route_number)
goto_page_name = routing_condition.skip_to_end ? end_page_name : goto_question_name(routing_condition.goto_page_id)

{
card: {
title: I18n.t("page_route_card.route_title", index:),
title: I18n.t("page_route_card.route_title", route_number:),
classes: "app-summary-card",
actions: [
govuk_link_to(I18n.t("page_route_card.edit"), edit_condition_path(form_id: form.id, page_id: page.id, condition_id: routing_condition.id)),
Expand All @@ -57,7 +57,7 @@ def conditional_route_card(routing_condition, index)
end

def secondary_skip_card
continue_to_name = page.has_next_page? ? page_name(page.next_page) : end_page_name
continue_to_name = page.has_next_page? ? question_name(page.next_page) : end_page_name

actions = if FeatureService.new(group: form.group).enabled?(:branch_routing) && secondary_skip
[
Expand Down Expand Up @@ -106,8 +106,8 @@ def secondary_skip_rows
end
end

goto_page_name = secondary_skip.skip_to_end ? end_page_name : page_name(secondary_skip.goto_page_id)
routing_page_name = page_name(secondary_skip.routing_page_id)
goto_page_name = secondary_skip.skip_to_end ? end_page_name : goto_question_name(secondary_skip.goto_page_id)
routing_page_name = question_name(secondary_skip.routing_page_id)

[
{
Expand All @@ -121,17 +121,19 @@ def secondary_skip_rows
]
end

def page_name(page_id)
def question_name(page_id)
target_page = pages.find { |page| page.id == page_id }

if target_page.present?
page_name = target_page.question_text
page_position = target_page.position
return if target_page.blank?

I18n.t("page_route_card.page_name", page_position:, page_name:)
else
I18n.t("page_route_card.page_name_not_exist")
end
question_text = target_page.question_text
question_number = target_page.position

I18n.t("page_route_card.question_name_long", question_number:, question_text:)
end

def goto_question_name(page_id)
question_name(page_id) || I18n.t("page_route_card.goto_page_invalid")
end

def end_page_name
Expand Down
6 changes: 3 additions & 3 deletions app/services/page_options_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def print_route(condition)
I18n.t("page_conditions.condition_compact_html_end_of_form", answer_value:).html_safe
else
goto_question = @pages.find { |page| page.id == condition.goto_page_id }
goto_page_text = ActionController::Base.helpers.sanitize(goto_question.question_text)
goto_page_number = @pages.find_index(goto_question) + 1
goto_page_question_text = ActionController::Base.helpers.sanitize(goto_question.question_text)
goto_page_question_number = @pages.find_index(goto_question) + 1

I18n.t("page_conditions.condition_compact_html", answer_value:, goto_page_number:, goto_page_text:).html_safe
I18n.t("page_conditions.condition_compact_html", answer_value:, goto_page_question_number:, goto_page_question_text:).html_safe
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/pages/conditions/delete.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% set_page_title(title_with_error_prefix(t("page_titles.routing_page_delete", question_position: delete_condition_input.page.position), delete_condition_input.errors&.any?)) %>
<% set_page_title(title_with_error_prefix(t("page_titles.routing_page_delete", question_number: delete_condition_input.page.position), delete_condition_input.errors&.any?)) %>
<% content_for :back_link, govuk_back_link_to(edit_condition_path(delete_condition_input.form.id, delete_condition_input.page.id, delete_condition_input.record.id)) %>

<div class="govuk-grid-row">
Expand All @@ -14,7 +14,7 @@

<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= delete_condition_input.form.name %></span>
<%= t("page_titles.routing_page_delete", question_position: delete_condition_input.page.position) %>
<%= t("page_titles.routing_page_delete", question_number: delete_condition_input.page.position) %>
</h1>

<%= govuk_summary_list(actions: false) do |summary_list|
Expand Down
8 changes: 4 additions & 4 deletions app/views/pages/conditions/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%# TODO: route_position is hardcoded as 1 here because we know there are only two conditions. It will need to change in the future %>
<% set_page_title(title_with_error_prefix(t('page_titles.routing_page_edit', question_position: condition_input.page.position, route_position: 1), condition_input.errors&.any?)) %>
<%# TODO: route_number is hardcoded as 1 here because we know there can be only two conditions. It will need to change in the future %>
<% set_page_title(title_with_error_prefix(t('page_titles.routing_page_edit', question_number: condition_input.page.position, route_number: 1), condition_input.errors&.any?)) %>
<% content_for :back_link, govuk_back_link_to(show_routes_path(condition_input.form.id, page_id: condition_input.page.id), t(".back_link", question_number: condition_input.page.position)) %>

<div class="govuk-grid-row">
Expand All @@ -10,8 +10,8 @@
<% end %>

<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= t("page_titles.routing_page_caption", question_position: condition_input.page.position) %></span>
<%= t("page_titles.routing_page_edit", question_position: condition_input.page.position, route_position: 1) %>
<span class="govuk-caption-l"><%= t("page_titles.routing_page_caption", question_number: condition_input.page.position) %></span>
<%= t("page_titles.routing_page_edit", question_number: condition_input.page.position, route_number: 1) %>
</h1>

<%= govuk_summary_list(actions: false) do |summary_list|
Expand Down
8 changes: 4 additions & 4 deletions app/views/pages/conditions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%# TODO: route_position is hardcoded as 1 here because we know there are only two conditions. It will need to change in the future %>
<% set_page_title(title_with_error_prefix(t('page_titles.routing_page_new', route_position: 1), condition_input.errors&.any?)) %>
<%# TODO: route_number is hardcoded as 1 here because we know there can be only two conditions. It will need to change in the future %>
<% set_page_title(title_with_error_prefix(t('page_titles.routing_page_new', route_number: 1), condition_input.errors&.any?)) %>
<% content_for :back_link, govuk_back_link_to(routing_page_path(condition_input.form.id, routing_page_id: condition_input.page.id)) %>

<div class="govuk-grid-row">
Expand All @@ -10,8 +10,8 @@
<% end %>

<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= t("page_titles.routing_page_caption", question_position: condition_input.page.position) %></span>
<%= t("page_titles.routing_page_new", route_position: 1) %>
<span class="govuk-caption-l"><%= t("page_titles.routing_page_caption", question_number: condition_input.page.position) %></span>
<%= t("page_titles.routing_page_new", route_number: 1) %>
</h1>

<%= govuk_summary_list do |summary_list|
Expand Down
6 changes: 3 additions & 3 deletions app/views/pages/delete.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<% unless @delete_confirmation_input.errors.any? %>
<% if @routing.present? %>
<%= govuk_notification_banner(title_text: "Important") do |banner|
banner.with_heading(text: t(".notification_banner.#{@routing}.heading_text", page_position: @page.position), tag: :h3)
banner.with_heading(text: t(".notification_banner.#{@routing}.heading_text", question_number: @page.position), tag: :h3)

t(
".notification_banner.#{@routing}.html",
route_owner_position: @route_owner.position,
show_routes_href: show_routes_path(current_form.id, @route_owner.id),
route_page_question_number: @route_page.position,
show_routes_href: show_routes_path(current_form.id, @route_page.id),
)
end %>
<% end %>
Expand Down
Loading
Loading