Merge pull request #350 from AyuntamientoMadrid/locales

Removes language switcher if only one locale
This commit is contained in:
Raimond Garcia
2015-09-04 00:43:18 +02:00
3 changed files with 31 additions and 16 deletions

View File

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

View File

@@ -78,4 +78,6 @@ Rails.application.configure do
# Do not dump schema after migrations. # Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false
config.i18n.available_locales = [:es]
end end

View File

@@ -32,4 +32,15 @@ feature 'Localization' do
expect(page).to_not have_content('Language') expect(page).to_not have_content('Language')
expect(page).to have_select('locale-switcher', selected: 'Español') expect(page).to have_select('locale-switcher', selected: 'Español')
end 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 end