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

Add formatting for EUR locales #1231

Conversation

zachgoll
Copy link
Collaborator

@zachgoll zachgoll commented Oct 2, 2024

This PR sets up some basic "exceptions" for formatting currencies.

As of now, we format currencies in the UI based on the following logic:

  1. We maintain a list of currencies with default formatting metadata in currencies.yml
  2. The Money and Money::Currency classes read this list and provide a method, format_options
  3. We have a global helper, format_currency which uses Rails number_to_currency(format_options) to format the currency

This works in 95% of cases, but there are some cases where a single currency like EUR should be formatted differently based on the locale of the user.

#1226 enabled setting locales for each user. We are now able to pass the configured locale directly to the format_options method on the Money class to "override" the default formatting.

For example, 25123.98 in the EUR currency will be formatted as follows based on the user's locale:

  • €25,123.98 - for en
  • €25.123,98 - for de

This PR will certainly not cover all exceptional cases, but sets up an easy way to add these via locale_options:

def locale_options(locale)
  case [ currency.iso_code, locale.to_sym ]
  when [ "EUR", :nl ], [ "EUR", :pt ]
    { delimiter: ".", separator: ",", format: "%u %n" }
  when [ "EUR", :en ], [ "EUR", :en_IE ]
    { delimiter: ",", separator: "." }
  else
    {}
  end
end

else
parts.last.ljust(precision, "0")
end
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legacy, not being used anywhere

@zachgoll zachgoll merged commit 82c2983 into main Oct 3, 2024
4 checks passed
@zachgoll zachgoll deleted the 1154-allow-user-to-select-separator-and-delimiter-convention-for-eur-currency branch October 3, 2024 14:25
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

Successfully merging this pull request may close these issues.

Allow user to select separator and delimiter convention for EUR currency
1 participant