-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2683 from jhawthorn/frontend_locale_selector
Add locale selector to frontend nav bar
- Loading branch information
Showing
4 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
frontend/app/assets/javascripts/spree/frontend/locale_selector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$(function() { | ||
$('#locale_selector select').change(function() { | ||
this.form.submit(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters