提交 356dacba 编写于 作者: X Xavier Noria

Merge branch 'master' of git://github.com/lifo/docrails

...@@ -133,9 +133,9 @@ The _setting part_ is easy. You can set the locale in a +before_filter+ in the + ...@@ -133,9 +133,9 @@ The _setting part_ is easy. You can set the locale in a +before_filter+ in the +
<ruby> <ruby>
before_filter :set_locale before_filter :set_locale
def set_locale def set_locale
# if params[:locale] is nil then I18n.default_locale will be used I18n.locale = params[:locale] || I18n.default_locale
I18n.locale = params[:locale]
end end
</ruby> </ruby>
...@@ -158,7 +158,7 @@ You can implement it like this in your +ApplicationController+: ...@@ -158,7 +158,7 @@ You can implement it like this in your +ApplicationController+:
before_filter :set_locale before_filter :set_locale
def set_locale def set_locale
I18n.locale = extract_locale_from_tld I18n.locale = extract_locale_from_tld || I18n.default_locale
end end
# Get locale from top-level domain or return nil if such locale is not available # Get locale from top-level domain or return nil if such locale is not available
...@@ -182,7 +182,7 @@ We can also set the locale from the _subdomain_ in a very similar way: ...@@ -182,7 +182,7 @@ We can also set the locale from the _subdomain_ in a very similar way:
# in your /etc/hosts file to try this out locally # in your /etc/hosts file to try this out locally
def extract_locale_from_subdomain def extract_locale_from_subdomain
parsed_locale = request.subdomains.first parsed_locale = request.subdomains.first
I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil
end end
</ruby> </ruby>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册