Skip to content

Commit 8afc123

Browse files
fix: load locale currency on demand
1 parent 5080821 commit 8afc123

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

src/cldr/load-numbers.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { cldr } from './info';
2-
import { territoryCurrencyCode } from './currency';
3-
import localeTerritory from './territory';
42

53
const LATIN_NUMBER_FORMATS = "Formats-numberSystem-latn";
64
const LATIN_NUMBER_SYMBOLS = "symbols-numberSystem-latn";
@@ -59,10 +57,6 @@ export default function loadNumbersInfo(locale, info) {
5957
}
6058
} else if (field === "currencies") {
6159
numbers.currencies = info[field];
62-
const territory = localeTerritory(localeInfo);
63-
if (territory && cldr.supplemental.currencyData) {
64-
numbers.localeCurrency = territoryCurrencyCode(territory);
65-
}
6660
}
6761
}
6862
}

test/cldr.js

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('load', () => {
2929
});
3030

3131
describe('load numbers', () => {
32+
3233
it('should set symbols', () => {
3334
const symbols = cldr.bg.numbers.symbols;
3435
expect(symbols.decimal).toEqual(",");
@@ -43,34 +44,45 @@ describe('load numbers', () => {
4344
});
4445

4546
it('should set currency pattern', () => {
46-
const currency = cldr.bg.numbers.currency;
47-
expect(currency.patterns[0]).toEqual("n $");
48-
expect(currency.groupSize.length).toEqual(1);
49-
expect(currency.groupSize[0]).toEqual(3);
50-
});
51-
52-
it('should set currency unit patterns', () => {
53-
const currency = cldr.bg.numbers.currency;
54-
expect(currency["unitPattern-count-one"]).toEqual("n $");
55-
expect(currency["unitPattern-count-other"]).toEqual("n $");
56-
});
57-
58-
it('should set percent pattern', () => {
59-
const percent = cldr.bg.numbers.percent;
60-
expect(percent.patterns[0]).toEqual("n%");
61-
expect(percent.groupSize.length).toEqual(1);
62-
expect(percent.groupSize[0]).toEqual(3);
63-
});
64-
65-
it('should set currencies', () => {
66-
const currencies = cldr.bg.numbers.currencies;
67-
expect(currencies).toBeDefined();
68-
});
69-
70-
it('should set localeCurrency', () => {
71-
const localeCurrency = cldr.bg.numbers.localeCurrency;
72-
expect(localeCurrency).toEqual("BGN");
73-
});
47+
const currency = cldr.bg.numbers.currency;
48+
expect(currency.patterns[0]).toEqual("n $");
49+
expect(currency.groupSize.length).toEqual(1);
50+
expect(currency.groupSize[0]).toEqual(3);
51+
});
52+
53+
it('should set currency unit patterns', () => {
54+
const currency = cldr.bg.numbers.currency;
55+
expect(currency["unitPattern-count-one"]).toEqual("n $");
56+
expect(currency["unitPattern-count-other"]).toEqual("n $");
57+
});
58+
59+
it('should set percent pattern', () => {
60+
const percent = cldr.bg.numbers.percent;
61+
expect(percent.patterns[0]).toEqual("n%");
62+
expect(percent.groupSize.length).toEqual(1);
63+
expect(percent.groupSize[0]).toEqual(3);
64+
});
65+
66+
describe('load currencies', () => {
67+
68+
it('should set currencies', () => {
69+
const currencies = cldr.bg.numbers.currencies;
70+
expect(currencies).toBeDefined();
71+
});
72+
73+
it('should not throw error if territory currency is missing in currencyData', () => {
74+
expect(() => {
75+
const bgCurrencies = cldr.supplemental.currencyData.region.BG;
76+
try {
77+
delete cldr.supplemental.currencyData.region.BG;
78+
load(currencies);
79+
} finally {
80+
cldr.supplemental.currencyData.region.BG = bgCurrencies;
81+
}
82+
}).not.toThrow();
83+
});
84+
});
85+
7486
});
7587

7688
describe('load calendar', () => {

0 commit comments

Comments
 (0)