Skip to content

Commit

Permalink
Symbol fallback (#129)
Browse files Browse the repository at this point in the history
* fix(currency): symbol fallback

* test(currency): add case for lang/locale pair without explicit symbol
  • Loading branch information
kspeyanski authored Jan 8, 2024
1 parent 64db9ef commit d2286da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cldr/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function currencyDisplay(locale, options) {
let result;

if (currencyDisplay === SYMBOL) {
result = currencyInfo["symbol-alt-narrow"] || currencyInfo[SYMBOL];
result = currencyInfo["symbol-alt-narrow"] || currencyInfo[SYMBOL] || currency;
} else {
if (typeof value === "undefined" || value !== 1) {
result = currencyInfo["displayName-count-other"];
Expand Down
9 changes: 8 additions & 1 deletion test/numbers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const numbers = require("cldr-numbers-full/main/bg/numbers.json");
const currencies = require("cldr-numbers-full/main/bg/currencies.json");
const currencyData = require("cldr-core/supplemental/currencyData.json");

load(likelySubtags, currencyData, numbers, currencies);
const localNumbers = require("cldr-numbers-full/main/de-CH/numbers.json");
const localCurrencies = require("cldr-numbers-full/main/de-CH/currencies.json");

load(likelySubtags, currencyData, numbers, currencies, localNumbers, localCurrencies);

function loadCustom(options) {
load({
Expand Down Expand Up @@ -300,6 +303,10 @@ describe('standard currency formatting', () => {
expect(formatNumber(10, "c", "bg-BG")).toEqual("10,00 лв.");
});

it("should apply format when passing language and territory without symbol", () => {
expect(formatNumber(10, "c", "de-CH")).toEqual("CHF 10.00");
});

it("should apply format when passing object", () => {
expect(formatNumber(10, { style: "currency" })).toEqual("$10.00");
});
Expand Down

0 comments on commit d2286da

Please sign in to comment.