Skip to content

Commit

Permalink
Reload admin after language change
Browse files Browse the repository at this point in the history
Reload the admin interface completely after a language change to have a proper initialization of locales and the usage of the i18n translate function inside of our web components.
  • Loading branch information
sascha-karnatz committed Oct 6, 2023
1 parent 70e2ad4 commit b387b27
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/javascript/alchemy_admin/initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
* add change listener to select to redirect the user after selecting another locale or site
* @param {string} selectId
* @param {string} parameterName
* @param {boolean} forcedReload
*/
function selectHandler(selectId, parameterName) {
function selectHandler(selectId, parameterName, forcedReload = false) {
$(`select#${selectId}`).on("change", function (e) {
let url = window.location.pathname
let delimiter = url.match(/\?/) ? "&" : "?"
Turbo.visit(`${url}${delimiter}${parameterName}=${$(this).val()}`, {})
const location = `${url}${delimiter}${parameterName}=${$(this).val()}`

if (forcedReload) {
window.location.href = location
} else {
Turbo.visit(location, {})
}
})
}

Expand All @@ -32,7 +39,7 @@ function Initialize() {
$("a.button").attr({ tabindex: 0 })

// Locale select handler
selectHandler("change_locale", "admin_locale")
selectHandler("change_locale", "admin_locale", true)

// Site select handler
selectHandler("change_site", "site_id")
Expand Down

0 comments on commit b387b27

Please sign in to comment.