From 3676954b2323f2c5ede86ee6d754d276523ea63d Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 6 Mar 2024 22:56:11 +0100 Subject: [PATCH] Fix JS locale data for release of Money 6.19 The money gem in its latest iteration added a space between value and unit of the Swiss Franc. Our heuristic in `_js_locale_data.html.erb` can't deal with that, so we add a third branch to it: If the money gem has a format wish, we'll respect it, but replace its abbreviations with the one the `accounting.js` library prefers. (cherry picked from commit f19e6fcab59db4887ba46c36ee6e2616c06d3a46) --- backend/app/assets/javascripts/spree/backend/format_money.js | 2 +- .../app/views/spree/admin/shared/_js_locale_data.html.erb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/app/assets/javascripts/spree/backend/format_money.js b/backend/app/assets/javascripts/spree/backend/format_money.js index 6f327937053..535693cbd9a 100644 --- a/backend/app/assets/javascripts/spree/backend/format_money.js +++ b/backend/app/assets/javascripts/spree/backend/format_money.js @@ -7,5 +7,5 @@ Spree.formatMoney = function(amount, currency) { var thousand = Spree.t('currency_delimiter'); var decimal = Spree.t('currency_separator'); - return accounting.formatMoney(amount, currencyInfo[0], currencyInfo[1], thousand, decimal, currencyInfo[2]); + return accounting.formatMoney(amount, currencyInfo[0], currencyInfo[1], thousand, decimal, currencyInfo[2]).trim(); } diff --git a/backend/app/views/spree/admin/shared/_js_locale_data.html.erb b/backend/app/views/spree/admin/shared/_js_locale_data.html.erb index b92b6ca38c2..47c0d3381c0 100644 --- a/backend/app/views/spree/admin/shared/_js_locale_data.html.erb +++ b/backend/app/views/spree/admin/shared/_js_locale_data.html.erb @@ -17,11 +17,14 @@ JSON.dump( Spree::Config.available_currencies.map { |c| format = - if c.symbol == "" || c.symbol_first + if c.format.present? + c.format.gsub("%u", "%s").gsub("%n", "%v") + elsif c.symbol == "" || c.symbol_first "%s%v" else "%v %s" end + [c.id.to_s.upcase, [ c.symbol || "ยค", c.exponent,