public
Description: Provide a simple way to add locales switching in your application.
Homepage:
Clone URL: git://github.com/olkeene/locales_switch.git
name age message
file .gitignore Sun Jan 04 14:35:18 -0800 2009 to_a obsolete warning. to_a -> Array() [olkeene]
file MIT-LICENSE Thu Dec 04 12:34:34 -0800 2008 add code [olkeene]
file README.rdoc Fri Dec 05 03:12:25 -0800 2008 added migration, fixed included part, changed r... [olkeene]
file Rakefile Thu Dec 04 12:34:34 -0800 2008 add code [olkeene]
directory generators/ Sun Jan 04 14:35:18 -0800 2009 to_a obsolete warning. to_a -> Array() [olkeene]
file init.rb Thu Dec 04 12:34:34 -0800 2008 add code [olkeene]
file install.rb Thu Dec 04 12:34:34 -0800 2008 add code [olkeene]
directory lib/ Fri Dec 05 03:12:25 -0800 2008 added migration, fixed included part, changed r... [olkeene]
directory tasks/ Thu Dec 04 12:34:34 -0800 2008 add code [olkeene]
directory test/ Thu Dec 04 12:34:34 -0800 2008 add code [olkeene]
file uninstall.rb Thu Dec 04 12:34:34 -0800 2008 add code [olkeene]
README.rdoc

LocalesSwitch

Following the idea from rails-i18n.org/wiki/pages/available_locales

LocalesSwitch provides a simple way to add locale switching in your application. It extends Controller with *prepend_before_filter :set_locale*

In Controller available methods are:

 *set_locale* - set current locale from params, session, current_user.site_language or I18n.default_locale
 *available_locales* - return a hash of available locales. Key: language code, Value: language name.

Ex: # {"it-IT" => "Italiano", "en-US" => "American English"}

In Helper:

 *language_selection* - display locales
 *locale_identifier* - indicate a params key that must hold a locale code.

Example

  <%= language_selection %> # => <a href="?locale=en">American English</a>&nbsp;Spanish
  # NOTE: in this sample Spanish is currently selected lang.

  <% language_selection do |language_code, language| %>
    <%= link_to language, "?#{locale_identifier}=#{language_code}" %><br />
  <% end %>
  # => <a href="?locale=en">American English</a>&nbsp;"<a href="?locale=sp">Spanish</a>

TODO:

add tests ability to change current_user prefered language and logged_in? identificator

Patches, ideas are always welcome. Copyright © 2008 Zhurbiy Oleg ( Ol.keene ), released under the MIT license