Use labels in controls to add and select languages

The absence of labels in these controls made them hard to use,
particularly for people who use screen readers.

Note we're removing the "Choose language" prompt, since we always
automatically choose a language and not choosing a language doesn't
really make sense. The only scenario where the prompt was used took
place when all languages had been removed but, in that case, the "Choose
language" prompt was misleading because there were no languages to
choose from.
This commit is contained in:
Javi Martín
2024-04-03 23:51:35 +02:00
parent 0f10146273
commit 16fc9998c4
12 changed files with 73 additions and 72 deletions

View File

@@ -6,9 +6,9 @@
<%= selected_languages_description %>
</strong>
</span>
<%= label_tag :select_language, t("shared.translations.current_language") %>
<%= select_tag :select_language,
options_for_select_language,
prompt: t("shared.translations.select_language_prompt"),
class: "js-select-language" %>
<%= select_language_error %>
<div class="margin-bottom">
@@ -24,9 +24,10 @@
</div>
<div class="small-6 large-3 column margin-top end">
<% if manage_languages %>
<%= label_tag :add_language, t("shared.translations.add_language") %>
<%= select_tag :add_language,
options_for_add_language,
prompt: t("shared.translations.add_language"),
prompt: "",
class: "js-add-language" %>
<% end %>
</div>

View File

@@ -742,7 +742,7 @@ en:
see_more: See more recommendations
hide: Hide recommendations
translations:
select_language_prompt: Choose language
current_language: Current language
remove_language: Remove language
add_language: Add language
languages_in_use:

View File

@@ -742,7 +742,7 @@ es:
see_more: Ver más recomendaciones
hide: Ocultar recomendaciones
translations:
select_language_prompt: Seleccionar idioma
current_language: Idioma actual
remove_language: Eliminar idioma
add_language: Añadir idioma
languages_in_use:

View File

@@ -8,13 +8,13 @@ describe Shared::GlobalizeLocalesComponent do
I18n.with_locale(:en) do
render_inline Shared::GlobalizeLocalesComponent.new
expect(page).to have_select options: ["Choose language", "English"]
expect(page).to have_select "Current language", options: ["English"]
end
I18n.with_locale(:es) do
render_inline Shared::GlobalizeLocalesComponent.new
expect(page).to have_select options: ["Seleccionar idioma"]
expect(page).to have_select "Idioma actual", options: []
end
end
end
@@ -43,7 +43,7 @@ describe Shared::GlobalizeLocalesComponent do
render_inline Shared::GlobalizeLocalesComponent.new
expect(page).to have_select options: ["Add language", "English", "Nederlands"]
expect(page).to have_select "Add language", options: ["", "English", "Nederlands"]
end
end
end

View File

@@ -95,7 +95,7 @@ describe "Admin banners magement", :admin do
expect_to_have_language_selected "English"
click_link "Remove language"
select "Français", from: "add_language"
select "Français", from: "Add language"
fill_in "Title", with: "En Français"
fill_in "Description", with: "Link en Français"

View File

@@ -144,7 +144,7 @@ describe "Admin budget groups", :admin do
visit edit_admin_budget_group_path(budget, group)
select "Español", from: :add_language
select "Español", from: "Add language"
fill_in "Group name", with: "Spanish name"
click_button "Save group"
@@ -156,7 +156,7 @@ describe "Admin budget groups", :admin do
visit edit_admin_budget_group_path(budget, group)
select "English", from: :select_language
select "English", from: "Current language"
fill_in "Group name", with: "New English Name"
click_button "Save group"

View File

@@ -181,7 +181,7 @@ describe "Admin budget headings", :admin do
visit edit_admin_budget_group_heading_path(budget, group, heading)
select "Español", from: :add_language
select "Español", from: "Add language"
fill_in "Heading name", with: "Spanish name"
click_button "Save heading"
@@ -193,7 +193,7 @@ describe "Admin budget headings", :admin do
visit edit_admin_budget_group_heading_path(budget, group, heading)
select "English", from: :select_language
select "English", from: "Current language"
fill_in "Heading name", with: "New English Name"
click_button "Save heading"

View File

@@ -315,7 +315,7 @@ describe "Admin budgets", :admin do
visit edit_admin_budget_path(budget)
select "Español", from: :add_language
select "Español", from: "Add language"
fill_in "Name", with: "Spanish name"
click_button "Update Budget"
@@ -327,7 +327,7 @@ describe "Admin budgets", :admin do
visit edit_admin_budget_path(budget)
select "English", from: :select_language
select "English", from: "Current language"
fill_in "Name", with: "New English Name"
click_button "Update Budget"

View File

@@ -149,7 +149,7 @@ describe "Admin legislation questions", :admin do
find("#nested_question_options input").set("Option 1")
select "Español", from: :select_language
select "Español", from: "Current language"
find("#nested_question_options input").set("Opción 1")
@@ -158,7 +158,7 @@ describe "Admin legislation questions", :admin do
expect(page).to have_field(field_en[:id], with: "Option 1")
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field(field_es[:id], with: "Opción 1")
end
@@ -166,13 +166,13 @@ describe "Admin legislation questions", :admin do
scenario "Add new question option after changing active locale" do
visit edit_question_url
select "Español", from: :select_language
select "Español", from: "Current language"
click_link "Add option"
find("#nested_question_options input").set("Opción 1")
select "English", from: :select_language
select "English", from: "Current language"
find("#nested_question_options input").set("Option 1")
@@ -182,7 +182,7 @@ describe "Admin legislation questions", :admin do
expect(page).to have_field(field_en[:id], with: "Option 1")
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field(field_es[:id], with: "Opción 1")
end

View File

@@ -67,7 +67,7 @@ describe "Admin custom information texts", :admin do
visit admin_site_customization_information_texts_path
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in "contents[content_#{key}]values[value_fr]", with: "Aide personalise sur les débats"
click_button "Save"
@@ -75,7 +75,7 @@ describe "Admin custom information texts", :admin do
expect(page).to have_content "Translation updated successfully"
visit admin_site_customization_information_texts_path
select "Français", from: :select_language
select "Français", from: "Current language"
expect(page).to have_content "Aide personalise sur les débats"
expect(page).not_to have_content "Aide sur les débats"
@@ -87,14 +87,14 @@ describe "Admin custom information texts", :admin do
visit admin_site_customization_information_texts_path(tab: "proposals")
select "Français", from: :select_language
select "Français", from: "Current language"
fill_in "contents_content_#{key}values_value_fr", with: "Partager personalise"
click_button "Save"
expect(page).to have_content "Translation updated successfully"
visit admin_site_customization_information_texts_path(tab: "proposals")
select "Français", from: :select_language
select "Français", from: "Current language"
expect(page).to have_content "Partager personalise"
expect(page).not_to have_content "Partager la proposition"
@@ -111,14 +111,14 @@ describe "Admin custom information texts", :admin do
visit admin_site_customization_information_texts_path(tab: "debates")
select "Español", from: :select_language
select "Español", from: "Current language"
click_link "Remove language"
click_button "Save"
expect(page).not_to have_link "Español"
visit admin_site_customization_information_texts_path(tab: "debates")
select "English", from: :select_language
select "English", from: "Current language"
expect(page).to have_content "Start a new debate"
expect(page).to have_content "Custom featured"

View File

@@ -22,7 +22,7 @@ describe "Admin edit translatable records", :admin do
scenario "Maintains existing translations" do
visit path
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in "Heading name", with: "Nom en Français"
click_button "Save heading"
@@ -30,11 +30,11 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_field "Heading name", with: "Heading name in English"
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field "Heading name", with: "Nombre de la partida en español"
select "Français", from: :select_language
select "Français", from: "Current language"
expect(page).to have_field "Heading name", with: "Nom en Français"
end
@@ -47,7 +47,7 @@ describe "Admin edit translatable records", :admin do
scenario "Maintains existing translations" do
visit path
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in "Title", with: "Titre en Français"
fill_in "Subtitle", with: "Sous-titres en Français"
fill_in_ckeditor "Content", with: "Contenu en Français"
@@ -57,11 +57,11 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_ckeditor "Content", with: "Content in English"
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_ckeditor "Content", with: "Contenido en español"
select "Français", from: :select_language
select "Français", from: "Current language"
expect(page).to have_ckeditor "Content", with: "Contenu en Français"
end
@@ -74,7 +74,7 @@ describe "Admin edit translatable records", :admin do
scenario "Maintains existing translations" do
visit path
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in "Version title", with: "Titre en Français"
click_link class: "fullscreen-toggle"
fill_in "Text", with: "Texte en Français"
@@ -87,13 +87,13 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_field "Text", with: "Text in English"
click_link class: "fullscreen-toggle"
select "Español", from: :select_language
select "Español", from: "Current language"
click_link class: "fullscreen-toggle"
expect(page).to have_field "Text", with: "Texto en español"
click_link class: "fullscreen-toggle"
select "Français", from: :select_language
select "Français", from: "Current language"
click_link class: "fullscreen-toggle"
expect(page).to have_field "Text", with: "Texte en Français"
@@ -107,7 +107,7 @@ describe "Admin edit translatable records", :admin do
scenario "Adds a translation for that locale" do
visit path
select "Português brasileiro", from: :add_language
select "Português brasileiro", from: "Add language"
fill_in "Question", with: "Português"
click_button "Save changes"
@@ -128,13 +128,13 @@ describe "Admin edit translatable records", :admin do
scenario "Shows validation erros" do
visit edit_admin_budget_path(translatable)
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in "Name", with: ""
click_button "Update Budget"
expect(page).to have_css "#error_explanation"
select "Français", from: :select_language
select "Français", from: "Current language"
expect(page).to have_field "Name", with: "", class: "is-invalid-input"
end
@@ -146,14 +146,14 @@ describe "Admin edit translatable records", :admin do
scenario "Shows validation errors" do
visit edit_admin_budget_budget_investment_path(translatable.budget, translatable)
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in "Title", with: "Titre en Français"
fill_in_ckeditor "Description", with: ""
click_button "Update"
expect(page).to have_css "#error_explanation"
select "Français", from: :select_language
select "Français", from: "Current language"
expect(page).to have_ckeditor "Description", with: ""
end
@@ -165,7 +165,7 @@ describe "Admin edit translatable records", :admin do
scenario "Shows validation errors" do
visit edit_admin_legislation_process_draft_version_path(translatable.process, translatable)
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in "Version title", with: "Titre en Français"
click_link class: "fullscreen-toggle"
fill_in "Text", with: ""
@@ -174,7 +174,7 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_css "#error_explanation"
select "Français", from: :select_language
select "Français", from: "Current language"
click_link class: "fullscreen-toggle"
expect(page).to have_field "Text", with: "", class: "is-invalid-input"
@@ -190,7 +190,7 @@ describe "Admin edit translatable records", :admin do
scenario "Changes the existing translation" do
visit path
select "Español", from: :select_language
select "Español", from: "Current language"
within(".translatable-fields") do
fill_in "Title", with: "Título corregido"
@@ -221,7 +221,7 @@ describe "Admin edit translatable records", :admin do
scenario "Changes the existing translation" do
visit path
select "Español", from: :select_language
select "Español", from: "Current language"
within(".translatable-fields") do
fill_in "Answer", with: "Respuesta corregida"
@@ -266,7 +266,7 @@ describe "Admin edit translatable records", :admin do
scenario "Show validation errors" do
visit edit_admin_banner_path(translatable)
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field "Title", with: "Title en español"
@@ -275,7 +275,7 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_css "#error_explanation"
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field "Title", with: "", class: "is-invalid-input"
end
@@ -287,7 +287,7 @@ describe "Admin edit translatable records", :admin do
scenario "Shows validation errors" do
visit edit_admin_legislation_process_draft_version_path(translatable.process, translatable)
select "Español", from: :select_language
select "Español", from: "Current language"
click_link class: "fullscreen-toggle"
expect(page).to have_field "Text", with: "Texto en español"
@@ -298,7 +298,7 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_css "#error_explanation"
select "Español", from: :select_language
select "Español", from: "Current language"
click_link class: "fullscreen-toggle"
expect(page).to have_field "Text", with: ""
@@ -338,17 +338,17 @@ describe "Admin edit translatable records", :admin do
scenario "Keeps the other languages" do
visit path
select "Español", from: :select_language
select "Español", from: "Current language"
click_link "Remove language"
expect(page).not_to have_select :select_language, with_options: ["Español"]
expect(page).not_to have_select "Current language", with_options: ["Español"]
click_button "Save group"
visit path
expect(page).not_to have_select :select_language, with_options: ["Español"]
expect(page).to have_select :select_language, with_options: ["English"]
expect(page).not_to have_select "Current language", with_options: ["Español"]
expect(page).to have_select "Current language", with_options: ["English"]
end
end
@@ -389,10 +389,10 @@ describe "Admin edit translatable records", :admin do
scenario "Doesn't remove the translation" do
visit path
select "Español", from: :select_language
select "Español", from: "Current language"
click_link "Remove language"
select "English", from: :select_language
select "English", from: "Current language"
fill_in "Question", with: ""
click_button "Save"
@@ -402,7 +402,7 @@ describe "Admin edit translatable records", :admin do
expect_not_to_have_language "Español"
visit path
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field "Question", with: "Pregunta en español"
end
@@ -417,9 +417,9 @@ describe "Admin edit translatable records", :admin do
visit edit_admin_admin_notification_path(translatable)
select "English", from: :select_language
select "English", from: "Current language"
click_link "Remove language"
select "Español", from: :select_language
select "Español", from: "Current language"
click_link "Remove language"
click_button "Update notification"
@@ -436,9 +436,9 @@ describe "Admin edit translatable records", :admin do
visit edit_admin_budget_budget_phase_path(translatable.budget, translatable)
select "English", from: :select_language
select "English", from: "Current language"
click_link "Remove language"
select "Español", from: :select_language
select "Español", from: "Current language"
click_link "Remove language"
click_button "Save changes"
@@ -458,9 +458,9 @@ describe "Admin edit translatable records", :admin do
visit edit_admin_active_polls_path(translatable)
select "English", from: :select_language
select "English", from: "Current language"
click_link "Remove language"
select "Español", from: :select_language
select "Español", from: "Current language"
click_link "Remove language"
click_button "Save"
@@ -498,7 +498,7 @@ describe "Admin edit translatable records", :admin do
expect(page).to have_field "contents_content_#{content.key}values_value_en", with: "Value in English"
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field "contents_content_#{content.key}values_value_es", with: "Value en español"
end
@@ -506,10 +506,10 @@ describe "Admin edit translatable records", :admin do
scenario "Select a locale and add it to the form" do
visit path
select "Français", from: :add_language
select "Français", from: "Add language"
expect_to_have_language_selected "Français"
expect(page).to have_select :add_language, selected: "Add language"
expect(page).to have_select "Add language", selected: ""
expect(page).to have_field "contents_content_#{content.key}values_value_fr"
end
@@ -523,7 +523,7 @@ describe "Admin edit translatable records", :admin do
scenario "Increase description count after add new language" do
visit path
select "Français", from: :add_language
select "Français", from: "Add language"
expect(page).to have_content "3 languages in use"
end

View File

@@ -43,7 +43,7 @@ describe "Public area translatable records" do
fill_in_new_investment_title with: "My awesome project"
fill_in_ckeditor "Description", with: "Everything is awesome!"
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in_new_investment_title with: "Titre en Français"
fill_in_ckeditor "Description", with: "Contenu en Français"
@@ -56,7 +56,7 @@ describe "Public area translatable records" do
scenario "Add only single translation at once not having the current locale" do
visit new_proposal_path
click_link "Remove language"
select "Français", from: :add_language
select "Français", from: "Add language"
fill_in_new_proposal_title with: "Titre en Français"
fill_in "Proposal summary", with: "Résumé en Français"
@@ -71,7 +71,7 @@ describe "Public area translatable records" do
visit new_budget_investment_path(budget)
click_link "Remove language"
select "Português brasileiro", from: :add_language
select "Português brasileiro", from: "Add language"
fill_in_new_investment_title with: "Titre en Français"
fill_in_ckeditor "Description", with: "Contenu en Français"
@@ -123,7 +123,7 @@ describe "Public area translatable records" do
scenario "Select a locale and add it to the form" do
visit new_budget_investment_path(create(:budget))
select "Français", from: :add_language
select "Français", from: "Add language"
expect(page).to have_field "Title", with: ""
end
@@ -147,7 +147,7 @@ describe "Public area translatable records" do
scenario "Increase description count after add new language" do
visit new_proposal_path
select "Español", from: :add_language
select "Español", from: "Add language"
expect(page).to have_content "2 languages in use"
end
@@ -195,7 +195,7 @@ describe "Public area translatable records" do
scenario "Changes the existing translation" do
visit path
select "Español", from: :select_language
select "Español", from: "Current language"
fill_in "Debate title", with: "Título corregido"
fill_in_ckeditor "Initial debate text", with: "Texto corregido"
@@ -218,7 +218,7 @@ describe "Public area translatable records" do
scenario "Show validation errors" do
visit edit_proposal_path(translatable)
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field "Proposal title", with: "Título en español"
@@ -227,7 +227,7 @@ describe "Public area translatable records" do
expect(page).to have_css "#error_explanation"
select "Español", from: :select_language
select "Español", from: "Current language"
expect(page).to have_field "Proposal title", with: "", class: "is-invalid-input"
end