removes language switcher if only one locale

This commit is contained in:
Juanjo Bazán
2015-09-03 23:47:55 +02:00
parent 908a2aca55
commit 5af7bc1aee
2 changed files with 29 additions and 16 deletions

View File

@@ -1,16 +1,18 @@
<div class="locale">
<span class="inline-block">
<i class="icon-language"></i>
<%= t("layouts.header.locale") %>
</span>
<form class="locale-form">
<select class="js-location-changer locale-switcher" name="locale-switcher">
<% I18n.available_locales.map do |loc| %>
<option <%= 'selected' if loc == I18n.locale %>
value='<%= current_path_with_query_params(locale: loc) %>'>
<%= I18n.t('locale', locale: loc) %>
</option>
<% end %>
</select>
</form>
</div>
<% if I18n.available_locales.size > 1 %>
<div class="locale">
<span class="inline-block">
<i class="icon-language"></i>
<%= t("layouts.header.locale") %>
</span>
<form class="locale-form">
<select class="js-location-changer locale-switcher" name="locale-switcher">
<% I18n.available_locales.map do |loc| %>
<option <%= "selected" if loc == I18n.locale %>
value="<%= current_path_with_query_params(locale: loc) %>">
<%= I18n.t("locale", locale: loc) %>
</option>
<% end %>
</select>
</form>
</div>
<% end %>

View File

@@ -32,4 +32,15 @@ feature 'Localization' do
expect(page).to_not have_content('Language')
expect(page).to have_select('locale-switcher', selected: 'Español')
end
scenario 'Locale switcher not present if only one locale' do
initial_locales = I18n.available_locales
I18n.available_locales = [:en]
visit '/'
expect(page).to_not have_content('Language')
expect(page).to_not have_css('div.locale')
I18n.available_locales = initial_locales
end
end