Skip to content

Commit

Permalink
Merge pull request #2683 from jhawthorn/frontend_locale_selector
Browse files Browse the repository at this point in the history
Add locale selector to frontend nav bar
  • Loading branch information
jhawthorn committed May 3, 2018
2 parents c28f0f5 + 9a36956 commit 2492b6e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/app/assets/javascripts/spree/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
//= require spree/frontend/checkout
//= require spree/frontend/product
//= require spree/frontend/cart
//= require spree/frontend/locale_selector
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(function() {
$('#locale_selector select').change(function() {
this.form.submit();
});
});
25 changes: 25 additions & 0 deletions frontend/app/views/spree/shared/_locale_selector.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% available_locales = current_store.available_locales %>
<% if available_locales.many? %>
<li id="locale_selector" data-hook>
<%= form_tag spree.select_locale_path, class: 'navbar-form' do %>
<div class="form-group">
<label for="switch_to_locale" class="sr-only">
<%= Spree.t(:'i18n.language') %>
</label>
<%=
select_tag(
:switch_to_locale,
options_for_select(
available_locales.map do |locale|
[I18n.t('spree.i18n.this_file_language', locale: locale, default: locale.to_s, fallback: false), locale]
end.sort,
selected: I18n.locale
),
class: 'form-control'
)
%>
<noscript><%= submit_tag t("spree.select") %></noscript>
</div>
<% end %>
</li>
<% end %>
1 change: 1 addition & 0 deletions frontend/app/views/spree/shared/_nav_bar.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<nav id="top-nav-bar" class="columns ten">
<ul id="nav-bar" class="inline" data-hook>
<%= render 'spree/shared/locale_selector' %>
<%= render 'spree/shared/login_bar_items' %>
<li id="search-bar" data-hook>
<%= render partial: 'spree/shared/search' %>
Expand Down

0 comments on commit 2492b6e

Please sign in to comment.