Merge pull request #1017 from demeteren/fix/numberformat

fix(localization): was not formatting minus values
This commit is contained in:
Joren Broekema 2020-10-12 09:29:38 +02:00 committed by GitHub
commit e6cc18c69f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/localize': patch
---
Fix formatting negative values for Turkish locale.

View file

@ -4,13 +4,17 @@
* @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options] * @param {import('../../types/LocalizeMixinTypes').FormatNumberOptions} [options]
* @returns {FormatNumberPart[]} * @returns {FormatNumberPart[]}
*/ */
export function forceTryCurrencyCode(formattedParts, { currency, currencyDisplay } = {}) { export function forceTryCurrencyCode(formattedParts, { currency, currencyDisplay } = {}) {
const result = formattedParts; const result = formattedParts;
// Change the currency code from TRY to TL, for Turkey
if (currency === 'TRY' && currencyDisplay === 'code') { if (currency === 'TRY' && currencyDisplay === 'code') {
if (result[0].value === 'TRY') { result.map(part => {
result[0].value = 'TL'; const newPart = part;
} if (part.type === 'currency') {
newPart.value = 'TL';
}
return newPart;
});
} }
return result; return result;
} }

View file

@ -329,6 +329,16 @@ describe('formatNumber', () => {
expect(formatNumber(123456.789, currencySymbol('JPY'))).to.equal('¥123.457'); expect(formatNumber(123456.789, currencySymbol('JPY'))).to.equal('¥123.457');
expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79'); expect(formatNumber(123456.789, currencySymbol('TRY'))).to.equal('₺123.456,79');
}); });
it('forces turkish currency code ', () => {
localize.locale = 'tr-TR';
expect(
formatNumber(1234.56, { style: 'currency', currencyDisplay: 'code', currency: 'TRY' }),
).to.equal('1.234,56 TL');
expect(
formatNumber(-1234.56, { style: 'currency', currencyDisplay: 'code', currency: 'TRY' }),
).to.equal('1.234,56 TL');
});
}); });
}); });
}); });