Skip to content

Instantly share code, notes, and snippets.

@hemalich
Created January 19, 2011 10:27
Show Gist options
  • Select an option

  • Save hemalich/785973 to your computer and use it in GitHub Desktop.

Select an option

Save hemalich/785973 to your computer and use it in GitHub Desktop.
Get locale code from request subdomain
# Get locale code from request subdomain (like http://it.example.local:3000)
# You have to put something like:
# 127.0.0.1 gr.example.local
# in your /etc/hosts file to try this out locally
def extract_locale_from_subdomain
parsed_locale = request.subdomains.first
I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment