Rails plugin for providing a localized "language_select" helper
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 4 commits ahead of kristianmandrup:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Rails plugin to provide support for localized menu with language names and for storing language information as language code (eg. ‘sv’), not name (eg. ‘Swedish’), in the database. Uses the Rails internationalization framework (I18n) for translating the names of languages. Requires Rails 2.2 (released November 21st, 2008) or later versions. This version works with Rails 3.2.2 Language names are loaded from hashes in plugin directory, according to I18n.locale value. You can easily translate language codes in your application like this: <%= I18n.t @user.language, :scope => 'languages' %> Generating language locale files The project comes with both rake tasks and a generator to generate and import locale files for languages: Rails 3 generator The project now comes with a Rails 3 generator to import locale files and place them in config/locales in your Rails 3 app. rails g localized_language_select:import de ru --file-ext yml Rake import tasks The following Rake tasks can be used for importing language names from Unicode.org’s CLDR repository (http://www.unicode.org/cldr/data/charts/summary/root.html) rake import:language_select locale=de rake yaml_locales:language_select locale=de The import one generates ruby files, the yaml_locales task generates yml files. Don’t forget to restart the application when you add new locale. The code borrows heavily from the LocalizedCountrySelect plugin – localized_country_select Install & Usage In your Gemfile add gem 'localized_language_select', :git => 'git://github.com/damianham/localized_language_select.git' Then to instal it, run: $ bundle install Then to install the locale files, run: $ rails g localized_language_select:locales This will copy the locale files to your Rails config/locales dir. The files will be called ‘language.en.yml’ and so on… Note: you can specify which locales using the --locales option, which takes a list of locales. $ rails g localized_language_select:locales --locales da en fr Usage example <%= localized_language_select(:user, :language, [], :include_blank => 'Please choose...') %> will become: <select name="user[language]" id="user_language"> <option value="">Please choose...</option> <option disabled="disabled" value="">-------------</option> <option value="aa">Afar</option> ... <option value="zza">ZaZa</option> </select> for the en locale. Options :exclude option <%= localized_language_select(:user, :language, ['English'], :include_blank => 'Please choose...', :exclude => ['Afrikaans']) %> :only option <%= localized_language_select(:user, :language, ['English'], :include_blank => 'Please choose...', :only => ['German', 'French']) %> Important! Add translations for your language requirements using the rake tasks supplied, then use the generator to copy them into the Rails locales folder. Framework usage This plugin should also integrate nicely with various formbuilders, including Formtastic Formtastic example: <%= semantic_form_for @user do |form| %> ... <%= form.input :lang, :as => :language, :priority_languages => ['English'], :include_blank => 'Please choose...', :only => ['German', 'French']) %> ... <% end %> Formbuilder configuration ActionView Formtastic Simpleform (please!) ActionView require 'localized_language/action_views_select' Formtastic Will auto detect formtastic major version and load the appropriate select helper. Should work with Formtastic 2.0 require 'localized_language/formtastic_select' Copyright Copyright © 2009 David Cato, released under the MIT license