<% app_lang_tags = ["ja_JP", "fr", "pt_BR", "zh_CN", "en_Latn_US_NYNORSK", "uz_UZ", "nl"] %>

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.

<%=h I18n.candidates.inspect %>

I18n.locale (with inspect)

I18n.locale is set the result(Locale::TagList) of locale_candidates(:type => :rfc).
This method is extended by Ruby-Locale for Ruby on Rails and returns all candidates as the Locale::TagList.

<%=h I18n.locale.inspect %>

I18n.locale (without inspect)

Locale::TagList(the result of I18n.locale) can behave like a single tag string to follow I18n.locale specification.

<%=h I18n.locale %>

Auto-Detect the locale from the WWW browser

Reload this URL

Set locale as the "lang" parameter

    <% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang| url = samples_path(:lang => lang) %>
  1. <%= link_to h(url), url %> [<%= lang %>]
  2. <% end %>

Set "lang" as the cookie value.

Click one of the link below, and then click "Auto-Detect the locale from the WWW browser".

    <% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang| url = url_for(:controller => :samples, :action => :set_cookie, :id => lang) %>
  1. <%= link_to h(url), {:action => :set_cookie, :id => lang} %> [<%= lang %>]
  2. <% end %>
  3. <%= link_to "Clear cookie", :action => :clear_cookie %>

Localized Routes

See config/routes.rb

    <% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang| url = url_for(:controller => :samples, :lang => lang, :action => :index) %>
  1. <%= link_to h(url),:controller => :samples, :lang => lang, :action => :index %> [<%= lang %>]
  2. <% end %>

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.

    <% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang| url = url_for(:controller => :samples, :action => :cached_action, :lang => lang) %>
  1. <%= link_to h(url), {:controller => :samples, :action => :cached_action, :lang => lang} %> [<%= lang %>]
  2. <% end %>