Rails Internationalization: currency format configuration

One of the nicest things in the built-in Rails internationalization features is the ability to format the currency according to the local culture (the number_to_currency method). For example, many european contries use ‘,’ as a separator and ‘.’ as a delimiter.

However, the examples presented in the help page (http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#M001684) are missing something essential.

 number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "")
 # => £1234567890,50
 number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "", :format => "%n %u")
 # => 1234567890,50 £

Why should i need a helper method where i can set all those parameters by hand?

Digging in the source code, i found how those settings can be put in the locale yml config file. Below is an example from my french localization file.

fr:
  number:
    currency:
      format:
        delimiter: ','
        separator: '.'
        precision: 2
        format: '%n %u'
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: