Last active
August 29, 2015 14:06
-
-
Save pachisaez/603432d8b554d6ab3879 to your computer and use it in GitHub Desktop.
Internationalization for two languages: EN (english) and ES (spanish), taking EN by default.
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
| class ApplicationController < ActionController::Base | |
| before_filter :set_locale | |
| protected | |
| def set_locale | |
| locale = params[:locale] || session[:locale] || | |
| (extact_locale_from_accept_language_header=='es' ? 'es' : 'en') | |
| session[:locale] = locale | |
| I18n.locale = locale | |
| end | |
| private | |
| def extact_locale_from_accept_language_header | |
| request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue "en" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment