Created
September 4, 2015 05:46
-
-
Save tristanm/e85b635499b720863ff6 to your computer and use it in GitHub Desktop.
Concerns::Localizable
This file contains hidden or 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
module Concerns::Localizable | |
extend ActiveSupport::Concern | |
included do | |
around_action :localize | |
end | |
def localize | |
return false if set_locale === false | |
yield | |
set_language_header | |
end | |
def default_url_options(options = {}) | |
super.merge({ locale: I18n.locale }) | |
end | |
private | |
def set_locale | |
if request.get? && params[:locale].blank? | |
redirect_to request.query_parameters.merge(locale: I18n.default_locale) | |
return false | |
else | |
I18n.locale = params[:locale] || I18n.default_locale | |
end | |
end | |
def set_language_header | |
response.headers['Content-Language'] = I18n.locale.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment