Created
March 21, 2009 20:38
-
-
Save genki/82975 to your computer and use it in GitHub Desktop.
This file contains 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
def set_locale | |
I18n.locale = @original_locale = fallback_locale(I18n.locale) | |
if request.host =~ /^([\w-]+)\.#{HOST.split(':')[0]}/i | |
I18n.locale = fallback_locale($1) | |
end | |
end | |
private | |
def fallback_locale(locale) | |
locale = locale.to_s | |
@available_locales ||= Set.new(I18n.available_locales) | |
until locale.empty? || @available_locales.include?(locale.intern) | |
locale = locale.split(/([-_])/)[0..-3].join | |
end | |
locale.present? ? locale.intern : I18n.default_locale | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment