Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- before_filter :set_locale
- def set_locale
- I18n.locale = extract_locale_from_tld
- end
- def extract_locale_from_tld
- parsed_locale = request.host.split('.').last
- I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil
- end
- # Get locale from top-level domain or return nil if such locale is not available
- # You have to put something like:
- # 127.0.0.1 example.com
- # 127.0.0.1 example.it
- # 127.0.0.1 example.pl
- # in your /etc/hosts file to try this out locally
Add Comment
Please, Sign In to add comment