Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add locale selector to frontend nav bar #2683

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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