Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Created September 2, 2021 07:07
Show Gist options
  • Save julianrubisch/c8a80a866eca7c4fc0758149c6cbac5c to your computer and use it in GitHub Desktop.
Save julianrubisch/c8a80a866eca7c4fc0758149c6cbac5c to your computer and use it in GitHub Desktop.
class LocaleReflex < ApplicationReflex
def switch
@locale = element.value
end
end
class ApplicationController < ActionController::Base
around_action :switch_locale
def switch_locale(&action)
locale = current_user.try(:language) || @locale || I18n.default_locale
I18n.with_locale(locale, &action)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment