Giter VIP home page Giter VIP logo

localized_country_select's Introduction

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 LOCALE=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

Rails 3

In your Gemfile add:

gem 'localized_country_select', '>= 0.9.2'

Rails 2.3

No longer supported, but you can still use old version of gem. In environment.rb add

config.gem 'localized_country_select, , :version => '0.0.1'

Example

Show full country names:

<%= 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>

Show only country codes:

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

will become:

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

for the en locale.

Formtastic and SimpleForm

Gem supports (via alias_method) both formtastic and simple_form :country input

Other resources

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

localized_country_select's People

Contributors

karmi avatar mlitwiniuk avatar freegenie avatar johnnyshields avatar scharfie avatar donaldpiret avatar jheuing avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.