Search code examples
ruby-on-railsspreesolidus

Spree/Solidus: format currency to show symbol before price with space "€ 99"


I use Rails 4 and Solidus 1.2 How does one format the price to have a currency symbol with a space before the number like "€ 99"?

Spree/Solidus use Ruby Money Gem to handle currencies and I see in https://github.com/RubyMoney/money/blob/master/lib/money/money/formatting.rb that there is a config option

Spree::Money.default_formatting_rules[:symbol_before_without_space] = true 

but no Spree::Money.default_formatting_rules[:symbol_before_with_space] = true

In my initializer:

# config/initializers/spree.rb

Money::Currency.register({
  :priority        => 1,
  :iso_code        => "EUR",
  :iso_numeric     => "978",
  :name            => "Euro",
  :symbol          => "€",
  :subunit         => "Cent",
  :subunit_to_unit => 100,
  :separator       => ".",
  :delimiter       => ","
})

And I tried also to format within my localization files like in de.yml:

---
de:
  number:
    currency:
      format: "%u %n"

But the price format is still "104,90 €" instead of "€ 104,90".

I don't want to do String Interpolation to format the currency. Is there an config option that I'm missing?


Solution

  • ok, it's embarrassing but i just had to set

    Spree::Money.default_formatting_rules[:symbol_before_without_space] = false
    

    to get my desired format.