From 39b4d16f10983fe00760ee33e257a9573d2e8e87 Mon Sep 17 00:00:00 2001 From: "Guillaume (gdi)" Date: Thu, 6 Jul 2023 11:23:36 +0000 Subject: [PATCH] [FIX] website: format price according to client locale Since [this commit], we have a range input to select a price filter for products. This input displays a min and max price that the visitor can select. The problem is that the price is not formatted according to the visitor locale. This commit fixes this issue. Steps to reproduce the bug: - With English as language, go to the shop page - Go to Customize and activate filter by price - Install French on the website - Visit /shop in French => The price is not formatted according to the French locale. For example, we can see a price of a thousand euros displayed as 1,000.00 but in French, it should be displayed as 1 000,00. [this commit]: https://github.com/odoo/odoo/commit/41f7c7bc6428050d4c7956edca26b7c1bd2d8e04 task-3414455 closes odoo/odoo#127881 X-original-commit: 683b7edf0ce1f098757aa1e38ee6dc5d4e255272 Signed-off-by: Louis Wicket (wil) Signed-off-by: Guillaume Dieleman (gdi) Signed-off-by: Romain Derie (rde) --- .../website/static/lib/multirange/multirange_custom.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/website/static/lib/multirange/multirange_custom.js b/addons/website/static/lib/multirange/multirange_custom.js index eed01daf1f5..cc3348529cc 100644 --- a/addons/website/static/lib/multirange/multirange_custom.js +++ b/addons/website/static/lib/multirange/multirange_custom.js @@ -264,11 +264,11 @@ export class Multirange { } formatNumber(number) { - number = String(number).split('.'); - if (number[1] && number[1].length === 1) { - number[1] += '0'; - } - let formatedNumber = number[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ',') + (number[1] ? '.' + number[1] : '.00'); + const locale = document.querySelector("html").getAttribute("lang"); + let formatedNumber = number.toLocaleString(locale, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }); if (this.currency.length) { if (this.currencyPosition === 'after') { formatedNumber = formatedNumber + ' ' + this.currency;