Created
January 19, 2011 10:26
-
-
Save hemalich/785972 to your computer and use it in GitHub Desktop.
Setting the Locale from the Domain Name ApplicationController
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
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.