fix: Locale-aware currency formatting (#677)

* fix: Locale-aware currency formatting

Add locale-specific formatting for money display:
- French (fr): symbol after number with non-breaking space (1 000,12 €)
- German (de): symbol after number (1.000,12 €)
- Spanish (es): symbol after number (1.000,12 €)
- Italian (it): symbol after number (1.000,12 €)
- Portuguese-Brazil (pt-BR): symbol before with space (R$ 1.000,12)

This follows international conventions where most European languages
place the currency symbol after the number, unlike English.

* fix: Address CodeRabbit review comments

- Use non-breaking spaces (NBSP) for French locale formatting
- Add nil guard in locale_options to prevent NoMethodError
- Add test coverage for Portuguese (Brazil) locale

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
foXaCe
2026-01-16 23:55:51 +01:00
committed by GitHub
parent 9792ab838f
commit 917101853b
2 changed files with 52 additions and 1 deletions

View File

@@ -31,7 +31,35 @@ module Money::Formatting
end
def locale_options(locale)
case [ currency.iso_code, locale.to_sym ]
locale_sym = (locale || I18n.locale || :en).to_sym
# French locale: symbol after number with non-breaking space, comma as decimal separator
if locale_sym == :fr
return { delimiter: "\u00A0", separator: ",", format: "%n\u00A0%u" }
end
# German locale: symbol after number with space, comma as decimal separator
if locale_sym == :de
return { delimiter: ".", separator: ",", format: "%n %u" }
end
# Spanish locale: symbol after number with space, comma as decimal separator
if locale_sym == :es
return { delimiter: ".", separator: ",", format: "%n %u" }
end
# Italian locale: symbol after number with space, comma as decimal separator
if locale_sym == :it
return { delimiter: ".", separator: ",", format: "%n %u" }
end
# Portuguese (Brazil) locale: symbol before, comma as decimal separator
if locale_sym == :"pt-BR"
return { delimiter: ".", separator: ",", format: "%u %n" }
end
# Currency-specific overrides for remaining locales
case [ currency.iso_code, locale_sym ]
when [ "EUR", :nl ], [ "EUR", :pt ]
{ delimiter: ".", separator: ",", format: "%u %n" }
when [ "EUR", :en ], [ "EUR", :en_IE ]