Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails number_to_currency options #76

Closed
jesteracer opened this issue Jul 25, 2012 · 10 comments
Closed

Rails number_to_currency options #76

jesteracer opened this issue Jul 25, 2012 · 10 comments

Comments

@jesteracer
Copy link

I am trying to use number_to_currency helper with :locale option and it works strange
Without r18n gem i get what i want as documented in the rails docs:

helper.number_to_currency(10)
=> "$10.00"
helper.number_to_currency(10, :locale => :ru)
=> "10.00 руб."

But when r18n is used, no matter what i pass in :location option i get the result with the current R18n locale, but not with a locale that i have provided.

So,

helper.number_to_currency(10)
=> "$10.00"
helper.number_to_currency(10, :locale => :ru)
=> "$10.00"
# but when i set it manualy 
R18n.set("ru")
helper.number_to_currency(10)
=> "10.00 руб."

Ps. I need to provide a custom locale to this helper, because it depends on user.locale.

As i tried to understand, why this happens i tested I18n.translate methods (which are used in number_to_currency helper) with and without r18n and got

# With R18n
I18n.translate(:'number.currency.format', :locale => :ru)
=> {:format=>"%u%n", :unit=>"$", :separator=>".", :delimiter=>",", :precision=>2, :significant=>false, :strip_insignificant_zeros=>false}
I18n.translate(:'number.currency.format')
=> {:format=>"%u%n", :unit=>"$", :separator=>".", :delimiter=>",", :precision=>2, :significant=>false, :strip_insignificant_zeros=>false}

# Without R18n
I18n.translate(:'number.currency.format', :locale => :ru)
=> {:delimiter=>" ", :format=>"%n %u", :precision=>2, :separator=>".", :significant=>false, :strip_insignificant_zeros=>false, :unit=>"руб.", :negative_format=>"-%n %u"}
I18n.translate(:'number.currency.format')
=> {:format=>"%u%n", :unit=>"$", :separator=>".", :delimiter=>",", :precision=>2, :significant=>false, :strip_insignificant_zeros=>false, :negative_format=>"-%u%n"}

Then i found, that .translate method in R18n does not support locale option https://github.com/ai/r18n/blob/master/r18n-rails-api/lib/r18n-rails-api/backend.rb but only uses the current locale.

So i am a little bit confused.
What should i do, to get it working?

@ai
Copy link
Member

ai commented Jul 25, 2012

Just wait my patch :), I try to be quick :).

@ai
Copy link
Member

ai commented Jul 25, 2012

Try fix dbde99f

@ai ai closed this as completed Jul 25, 2012
@ai
Copy link
Member

ai commented Jul 25, 2012

You should update r18n-rails too 6338e51

@jesteracer
Copy link
Author

@ai thank you!

@imran-ashraf-tkxel
Copy link

number_to_currency not working in model. any idea?

@ai
Copy link
Member

ai commented Sep 5, 2012

Oops, I forget to create release :). I release new version after fix #80. You can use git master, just add to Gemfile:

gem 'r18n-core', git: 'git://github.com/ai/r18n.git'

@imran-ashraf-tkxel
Copy link

included this in my gem file.
but still getting error.
I want currency up to two precision values only i.e 15.6666666667 to 15.66 but not 15.67.
please share format to be used in my model

@ai
Copy link
Member

ai commented Sep 5, 2012

Do you run bundle update after add git? Also, can you show me your code?

@imran-ashraf-tkxel
Copy link

yea I do bundle update.
here is the code:
amount = number_to_currency(amount, :precision => 2)

@ai ai reopened this Sep 8, 2012
@ai
Copy link
Member

ai commented Sep 8, 2012

I add addition test 00959be and everythings is fine for me. Do you have format instructions in your locale?

@ai ai closed this as completed Sep 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants