Skip to content

Rails plugin for localized "country_select" helper with Rake task for downloading locales from Unicode.org's CLDR

License

Notifications You must be signed in to change notification settings

clarif/localized_country_select

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro

This plugin is a fork of the localized_country_select plugin available at github.com/karmi/localized_country_select.

Only minors changes have been done to be compliant with the former select_country from Rails. It allows this plugin to be used with the Formtastic gem (see in the “example” section) to provide 1/ localized countries and 2/ country codes stored in the DB (instead of country name).

LocalizedCountrySelect

Rails plugin to provide support for localized <select> menu with country names and for storing country information as country code (eg. ‘es’), not name (eg. ‘Spain’), in the database.

Uses the Rails internationalization framework (I18n, rails-i18n.org) for translating the names of countries. Requires Rails 2.2 (released November 21st, 2008) or later versions. Country names are loaded from hashes in plugin directory, according to I18n.locale value.

You can easily translate country codes in your application like this:

<%= I18n.t @user.country, :scope => 'countries' %>

Comes with a Rake task rake import:country_select 'de' for importing country names from Unicode.org’s CLDR repository (www.unicode.org/cldr/data/charts/summary/root.html) Don’t forget to restart the application when you add new locale.

ActionView helper code is adapted from Rails’ default country_select plugin (previously in core). See github.com/rails/country_select/tree/master/lib/country_select.rb

Example

<%= localized_country_select(:user, :country, [], :include_blank => 'Please choose...') %>

will become:

<select name="user[country]" id="user_country">
<option value="">Please choose...</option>
<option disabled="disabled" value="">-------------</option>
<option value="AF">Afghanistan</option>
...
<option value="ZW">Zimbabwe</option>
</select>

for the en locale.

To use this plugin with Formtastic:

For a model which has a country_code attribute: <%= form.input :country_code, :as => :country, :priority_countries => [‘fr’, ‘it’, ‘be’] %>

Other resources

Copyright © 2008 Karel Minarik (www.karmi.cz), released under the MIT license

About

Rails plugin for localized "country_select" helper with Rake task for downloading locales from Unicode.org's CLDR

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%