#StackBounty: #ruby-on-rails #internationalization #ruby-on-rails-3.2 Why don't my locale settings in number_to_currency work?

Bounty: 100

Per the Rails 3.2 API Docs, to use different locales for number_to_currency, I need to do the following:

<%= number_to_currency(1234567890.506, :locale => :fr) %>

I was expecting the following output:

# => 1 234 567 890,51 €

Even though I literally use that exact thing within my app and it keeps outputting the following:

$1,234,567,890.51

When I check for the available_locales within my app I get the following:

> I18n.available_locales
=> [:en, :de, :es, :fr, :ja, :pl, :"pt-BR", :ru, :sv, :"zh-CN"]

So it SHOULD work, but it doesn’t.

What am I missing?

Update 1

Per @s3tjan’s comment, I did some digging in that linked Rails issue and that led me to my application.rb where I discovered I18n.enforce_available_locales = false. I changed that to true and restarted the server.

When I tried the above again, I am now getting this error:

ActionView::Template::Error (:fr is not a valid locale):

Not sure how to fix this.

Update 2

So I just realize that I never had a locale file in my config/locales. What I really want is to use the GBP Pounds for currency, so I added an en-GB.yml file in my config/locales, then I restarted my server and console.

In my application.rb, I have the following:

I18n.enforce_available_locales = true

Then I checked my console and got this:

[1] pry(main)> I18n.available_locales
=> [:en, :de, :es, :fr, :ja, :pl, :"pt-BR", :ru, :sv, :"zh-CN", :"en-GB"]
[2] pry(main)> 

So the :"en-GB" was added successfully to my app’s load path.

But when I do this in my view:

<%= number_to_currency(1234567890.506, :locale => :"en-GB") %>

This is the error I get:

:"en-GB" is not a valid locale excluded from capture due to environment or should_capture callback

ActionView::Template::Error (:"en-GB" is not a valid locale):

So still not working.

Update 3

My en-GB.yml file was taken directly from https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en-GB.yml

So it looks exactly like that.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.