Hide languages link when there's only one language

Most existing Consul Democracy installations will have changed their
`config.i18n.available_locales` option so only a few locales are
available. In many cases, only one locale will be available. In these
cases, rendering a form that only offers one option is useless.

We've considered adding a text in this case mentioning that, in order to
enable more languages, they need to configure their
`config.i18n.available_locales`. However, we haven't done it for two
reasons.

First, if they've changed the available locales to just one, there's a
good chance they aren't interested at all in configuring the locales.

And, second, if there's only one available locale, administrators will
learn to ignore the "languages" link, so they won't realize that locales
can be configured if developers change the available locales. If we hide
the link, on the other hand, they will notice that locales can now be
configured once developers change the available locales.

Note we're still allowing access by entering the URL. This is harmless,
though, since people accessing it this way will see a form with only one
possible option and won't be able to modify anything.
This commit is contained in:
Javi Martín
2024-06-25 18:45:23 +02:00
parent 8c8c99eb2c
commit 12e49ff607
2 changed files with 25 additions and 1 deletions

View File

@@ -462,7 +462,7 @@ class Admin::MenuComponent < ApplicationComponent
settings_link, settings_link,
tenants_link, tenants_link,
tags_link, tags_link,
locales_link, (locales_link if I18n.available_locales.many?),
geozones_link, geozones_link,
local_census_records_link local_census_records_link
) )

View File

@@ -35,4 +35,28 @@ describe Admin::MenuComponent, controller: Admin::NewslettersController do
expect(page).to have_css "[aria-current]", exact_text: "Polls" expect(page).to have_css "[aria-current]", exact_text: "Polls"
end end
end end
describe "#locales_link" do
it "is present when two or more locales are available" do
render_inline Admin::MenuComponent.new
expect(page).to have_link "Languages"
end
it "is present when two or more locales are available but only one is enabled" do
Setting["locales.enabled"] = "en"
render_inline Admin::MenuComponent.new
expect(page).to have_link "Languages"
end
it "is not present when only one locale is available" do
allow(I18n).to receive(:available_locales).and_return([:en])
render_inline Admin::MenuComponent.new
expect(page).not_to have_link "Languages"
end
end
end end