Ruby-Locale and Ruby on Rails 2.2 sample
[source code]
The values from Rails
| Variables | Values |
| HTTP_ACCEPT_LANGUAGE | en-us,en;q=0.5 |
| HTTP_ACCEPT_CHARSET | ISO-8859-1,utf-8;q=0.7,*;q=0.7 |
| QUERY_STRING | |
| params[:lang] | pt_BR |
| cookies[:lang] | |
Get the current locale
I18n.candidates(with no option)
Requested Locales order by the priority. This method is added by Ruby-Locale for Ruby on Rails.
[#<Locale::Tag::Common: pt_BR>, #<Locale::Tag::Common: pt>, #<Locale::Tag::Common: en>]
I18n.locale (with inspect)
I18n.locale is set the result(Locale::TagList) of I18n.candidates(:type => :rfc).
This method is extended by Ruby-Locale for Ruby on Rails and returns all candidates as the Locale::TagList.
[#<Locale::Tag::Rfc: pt-BR>, #<Locale::Tag::Rfc: pt>, #<Locale::Tag::Rfc: en>]
I18n.locale (without inspect)
Locale::TagList(the result of I18n.locale) can behave like a single tag string to follow I18n.locale specification.
pt-BR
Auto-Detect the locale from the WWW browser
Reload this URL
Set locale as the "lang" parameter
- /locale_rails_sample/samples?lang=ja_JP [ja_JP]
- /locale_rails_sample/samples?lang=fr [fr]
- /locale_rails_sample/samples?lang=pt_BR [pt_BR]
- /locale_rails_sample/samples?lang=zh_CN [zh_CN]
- /locale_rails_sample/samples?lang=en_Latn_US_NYNORSK [en_Latn_US_NYNORSK]
Set "lang" as the cookie value.
Click one of the link below, and then click "Auto-Detect the locale from the WWW browser".
- /locale_rails_sample/pt_BR/samples/set_cookie/ja_JP [ja_JP]
- /locale_rails_sample/pt_BR/samples/set_cookie/fr [fr]
- /locale_rails_sample/pt_BR/samples/set_cookie/pt_BR [pt_BR]
- /locale_rails_sample/pt_BR/samples/set_cookie/zh_CN [zh_CN]
- /locale_rails_sample/pt_BR/samples/set_cookie/en_Latn_US_NYNORSK [en_Latn_US_NYNORSK]
- Clear cookie
Localized Routes
See config/routes.rb
- /locale_rails_sample/ja_JP/samples [ja_JP]
- /locale_rails_sample/fr/samples [fr]
- /locale_rails_sample/pt_BR/samples [pt_BR]
- /locale_rails_sample/zh_CN/samples [zh_CN]
- /locale_rails_sample/en_Latn_US_NYNORSK/samples [en_Latn_US_NYNORSK]
Caching
Fragment/Action caching is supported. Here is the sample for action caching.
Click the links then check %{RAILS_ROOT}/tmp/cache/ where Cached file is stored.
- /locale_rails_sample/ja_JP/samples/cached_action [ja_JP]
- /locale_rails_sample/fr/samples/cached_action [fr]
- /locale_rails_sample/pt_BR/samples/cached_action [pt_BR]
- /locale_rails_sample/zh_CN/samples/cached_action [zh_CN]
- /locale_rails_sample/en_Latn_US_NYNORSK/samples/cached_action [en_Latn_US_NYNORSK]
Separate Localized View template file in each languages
View template can be separeted with language tags.
- uz_UZ has special index page(index_uz_UZ.html.erb)
- uz uses normal index page
- nl has special _part page(_part_nl.html.erb)
- nl_BE also uses the special _part page(_part_nl.html.erb)
Copyright (C) 2008 Masao Mutoh