-
-
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 #2559 from jhawthorn/locale_chooser
Add locale chooser to admin
- Loading branch information
Showing
13 changed files
with
141 additions
and
8 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
18 changes: 18 additions & 0 deletions
18
backend/app/assets/javascripts/spree/backend/locale_selection.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,18 @@ | ||
Spree.ready(function() { | ||
var localeSelect = document.querySelector('.js-locale-selection'); | ||
if (!localeSelect) return; | ||
|
||
localeSelect.addEventListener('change', function() { | ||
Spree.ajax({ | ||
type: "PUT", | ||
dataType: "json", | ||
url: Spree.pathFor("admin/locale/set"), | ||
data: { | ||
switch_to_locale: localeSelect.value | ||
}, | ||
success: function(data) { | ||
document.location.href = data.location; | ||
} | ||
}); | ||
}); | ||
}); |
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
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree | ||
module Admin | ||
class LocaleController < Spree::Admin::BaseController | ||
def set | ||
locale = params[:switch_to_locale].to_s.presence | ||
|
||
if locale && I18n.available_locales.include?(locale.to_sym) | ||
I18n.locale = locale | ||
session[:locale] = locale | ||
|
||
respond_to do |format| | ||
format.json { render json: { locale: locale, location: spree.admin_url } } | ||
end | ||
else | ||
respond_to do |format| | ||
format.json { render json: { locale: I18n.locale }, status: 404 } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
backend/app/views/spree/admin/shared/_locale_selection.html.erb
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,15 @@ | ||
<% available_locales = Spree.i18n_available_locales %> | ||
<% if available_locales.size > 1 %> | ||
<div class="admin-locale-selection"> | ||
<select class="js-locale-selection custom-select fullwidth"> | ||
<%= | ||
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, | ||
) | ||
%> | ||
</select> | ||
</div> | ||
<% 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
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
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
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
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
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
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
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