From a96cca879d018b8a4dae2f1082eede2197fcdf0c Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 9 Jul 2020 22:15:25 +0200 Subject: [PATCH] Use browser's locale for currency format --- app/helpers/fmt-fiat-currency.js | 5 +++-- tests/integration/helpers/fmt-fiat-currency-test.js | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/helpers/fmt-fiat-currency.js b/app/helpers/fmt-fiat-currency.js index 712987a..61f75dd 100644 --- a/app/helpers/fmt-fiat-currency.js +++ b/app/helpers/fmt-fiat-currency.js @@ -1,10 +1,11 @@ import { helper } from '@ember/component/helper'; export default helper(function fmtFiatCurrency(params) { - const formatter = new Intl.NumberFormat('en-US', { + const lang = navigator.language || navigator.userLanguage; + const formatter = new Intl.NumberFormat(lang, { style: 'currency', currency: params[1] || 'EUR', - minimumFractionDigits: 2 + currencyDisplay: 'code' }) return formatter.format(params[0]); }); diff --git a/tests/integration/helpers/fmt-fiat-currency-test.js b/tests/integration/helpers/fmt-fiat-currency-test.js index 26dceb5..122760a 100644 --- a/tests/integration/helpers/fmt-fiat-currency-test.js +++ b/tests/integration/helpers/fmt-fiat-currency-test.js @@ -10,9 +10,13 @@ module('Integration | Helper | fmt-fiat-currency', function(hooks) { this.set('amount', 13.9); await render(hbs`{{fmt-fiat-currency this.amount}}`); - assert.equal(this.element.textContent.trim(), '€13.90', 'using EUR amount by default'); + assert.ok(this.element.textContent.trim().match(/13.90/), + 'formats the number with two decimals'); + assert.ok(this.element.textContent.trim().match(/EUR/), + 'using EUR by default'); await render(hbs`{{fmt-fiat-currency this.amount 'USD'}}`); - assert.equal(this.element.textContent.trim(), '$13.90', 'using the defined currency'); + assert.ok(this.element.textContent.trim().match(/USD/), + 'using defined currency when given'); }); });