mirror of
https://github.com/we-promise/sure
synced 2026-04-25 17:15:07 +02:00
Fix Polish translation template error (and increase testing/fix other locales as well) (#734)
* Add Polish locale support for money formatting
The Money::Formatting module handles locale-specific currency formatting
for French, German, Spanish, Italian, and Portuguese (Brazil), but was
missing support for Polish locale. This caused formatting issues when
users with Polish locale viewed account valuations.
- Add Polish locale handling to locale_options method
- Polish formatting uses: space as thousands delimiter, comma as
decimal separator, symbol after number ("%n %u" format)
- Add test coverage for Polish locale formatting
* Add locale support for all supported locales in Money::Formatting
Extend the Money::Formatting module to handle all locales from
SUPPORTED_LOCALES to prevent template errors when users select
different languages.
Added locale-specific formatting for:
- Turkish (tr): dot delimiter, comma separator, symbol after number
- Norwegian Bokmål (nb): space delimiter, comma separator, symbol after
- Catalan (ca): dot delimiter, comma separator, symbol after number
- Romanian (ro): dot delimiter, comma separator, symbol after number
- Dutch (nl): dot delimiter, comma separator, symbol before number
Also improved Dutch handling to work with all currencies (not just EUR).
Added comprehensive tests for:
- All newly supported locales
- Chinese (zh-CN, zh-TW) which use default English-style formatting
- A test that verifies all SUPPORTED_LOCALES can format without errors
* Fix broken money formatting tests
- Fix Chinese Traditional locale test: TWD currency uses "TW$" symbol
(prefixed with first 2 chars of ISO code to distinguish from USD)
- Fix all supported locales test: replace assert_nothing_raised (which
doesn't accept message argument in Minitest) with explicit assertions
* Refactor Money::Formatting to consolidate locale patterns
Group locales by their formatting patterns into constants to reduce
repetition and make it easier to add new locales:
- EUROPEAN_SYMBOL_AFTER: de, es, it, tr, ca, ro
(dot delimiter, comma separator, symbol after)
- SPACE_DELIMITER_SYMBOL_AFTER: pl, nb
(space delimiter, comma separator, symbol after)
- EUROPEAN_SYMBOL_BEFORE: nl, pt-BR
(dot delimiter, comma separator, symbol before)
French locale remains separate due to its unique non-breaking space usage.
---------
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
module Money::Formatting
|
||||
include ActiveSupport::NumberHelper
|
||||
|
||||
# Locale groups by formatting pattern
|
||||
# European style: dot as thousands delimiter, comma as decimal separator, symbol after number
|
||||
EUROPEAN_SYMBOL_AFTER = %i[de es it tr ca ro].freeze
|
||||
# Scandinavian/Eastern European: space as thousands delimiter, comma as decimal separator, symbol after number
|
||||
SPACE_DELIMITER_SYMBOL_AFTER = %i[pl nb].freeze
|
||||
# European style: dot as thousands delimiter, comma as decimal separator, symbol before number
|
||||
EUROPEAN_SYMBOL_BEFORE = %i[nl pt-BR].freeze
|
||||
|
||||
def format(options = {})
|
||||
locale = options[:locale] || I18n.locale
|
||||
default_opts = format_options(locale)
|
||||
@@ -33,34 +41,29 @@ module Money::Formatting
|
||||
def locale_options(locale)
|
||||
locale_sym = (locale || I18n.locale || :en).to_sym
|
||||
|
||||
# French locale: symbol after number with non-breaking space, comma as decimal separator
|
||||
# French locale: uses non-breaking spaces (unique formatting)
|
||||
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
|
||||
# European style: dot delimiter, comma separator, symbol after number
|
||||
if EUROPEAN_SYMBOL_AFTER.include?(locale_sym)
|
||||
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" }
|
||||
# Space delimiter, comma separator, symbol after number
|
||||
if SPACE_DELIMITER_SYMBOL_AFTER.include?(locale_sym)
|
||||
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"
|
||||
# European style: dot delimiter, comma separator, symbol before number
|
||||
if EUROPEAN_SYMBOL_BEFORE.include?(locale_sym)
|
||||
return { delimiter: ".", separator: ",", format: "%u %n" }
|
||||
end
|
||||
|
||||
# Currency-specific overrides for remaining locales
|
||||
case [ currency.iso_code, locale_sym ]
|
||||
when [ "EUR", :nl ], [ "EUR", :pt ]
|
||||
when [ "EUR", :pt ]
|
||||
{ delimiter: ".", separator: ",", format: "%u %n" }
|
||||
when [ "EUR", :en ], [ "EUR", :en_IE ]
|
||||
{ delimiter: ",", separator: "." }
|
||||
|
||||
Reference in New Issue
Block a user