Skip to content

Commit

Permalink
Add missing number formats and currencies (#244)
Browse files Browse the repository at this point in the history
* Add missing numbers formats and currencies

* Fix failing number tests

* Add tests for missung currencies
  • Loading branch information
marielakas authored Jul 31, 2018
1 parent fcaf5d7 commit 1beae74
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/util/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ import { currencyToRegex } from './regex';

export const CURRENCY_FORMATS = {
EUR: {
'el-CY': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'el-GR': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'et-EE': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'de-AT': { prependSymbol: true, fractionalPrecision: 2, addSpace: true },
'de-DE': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'en-IE': { prependSymbol: true, fractionalPrecision: 2, addSpace: false },
'en-MT': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'es-ES': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'fi-FI': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'fr-BE': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'fr-FR': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'fr-LU': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'it-IT': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'lt-LT': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'lv-LV': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'nl-BE': { prependSymbol: true, fractionalPrecision: 2, addSpace: true },
'nl-NL': { prependSymbol: true, fractionalPrecision: 2, addSpace: true },
'pt-PT': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'sk-SK': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
'sl-SI': { prependSymbol: false, fractionalPrecision: 2, addSpace: true },
default: { prependSymbol: false, fractionalPrecision: 2, addSpace: true }
},
CHF: {
Expand Down
64 changes: 57 additions & 7 deletions src/util/currency.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,36 @@ describe('currency', () => {
testCurrency(inputs, 'EUR', 'nl-BE', outputsNl);
});

it('should localize EUR for Germany', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'de-DE', outputs);
it('should localize EUR for Cyprus', () => {
const outputsFr = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'el-CY', outputsFr);
});

it('should localize EUR for Spain', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'es-ES', outputs);
it('should localize EUR for Estonia', () => {
const outputsFr = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'et-EE', outputsFr);
});

it('should localize EUR for Finland', () => {
const outputsFr = ['11,23\xA0€', '1\x00000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'fi-FI', outputsFr);
});

it('should localize EUR for France', () => {
const outputs = ['11,23\xA0€', '1\xA0000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'fr-FR', outputs);
});

it('should localize EUR for Germany', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'de-DE', outputs);
});

it('should localize EUR for Greece', () => {
const outputsFr = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'el-CY', outputsFr);
});

it('should localize EUR for Ireland', () => {
const outputs = ['€11.23', '€1,000.00', '€0.98'];
testCurrency(inputs, 'EUR', 'en-IE', outputs);
Expand All @@ -66,6 +81,26 @@ describe('currency', () => {
testCurrency(inputs, 'EUR', 'it-IT', outputs);
});

it('should localize EUR for Latvia', () => {
const outputs = ['11,23\xA0€', '1\x00000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'lv-LV', outputs);
});

it('should localize EUR for Lithuania', () => {
const outputs = ['11,23\xA0€', '1\x00000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'lv-LV', outputs);
});

it('should localize EUR for Luxembourg', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'fr-LU', outputs);
});

it('should localize EUR for Malta', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'en-MT', outputs);
});

it('should localize EUR for Netherlands', () => {
const outputs = ['€\xA011,23', '€\xA01.000,00', '€\xA00,98'];
testCurrency(inputs, 'EUR', 'nl-NL', outputs);
Expand All @@ -76,6 +111,21 @@ describe('currency', () => {
testCurrency(inputs, 'EUR', 'pt-PT', outputs);
});

it('should localize EUR for Spain', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'es-ES', outputs);
});

it('should localize EUR for Slovakia', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'sk-SK', outputs);
});

it('should localize EUR for Slovenia', () => {
const outputs = ['11,23\xA0€', '1.000,00\xA0€', '0,98\xA0€'];
testCurrency(inputs, 'EUR', 'sl-SI', outputs);
});

it('should localize CHF', () => {
const outputsDe = ['CHF\xA011.23', "CHF\xA01'000.00", 'CHF\xA00.98'];
testCurrency(inputs, 'CHF', 'de-CH', outputsDe);
Expand Down Expand Up @@ -133,7 +183,7 @@ describe('currency', () => {
});

it('should localize DKK', () => {
const outputs = ['11,23\xA0kr.', '1.000,00\xA0kr.', '0,98\xA0kr.'];
const outputs = ['11,23\xA0kr.', '1\xA0000,00\xA0kr.', '0,98\xA0kr.'];
testCurrency(inputs, 'DKK', 'da-DK', outputs);
});

Expand Down
12 changes: 11 additions & 1 deletion src/util/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@ import { get } from 'lodash';
export const NUMBER_SEPARATORS = {
'bg-BG': { decimal: ',', thousand: '\xA0' },
'cs-CZ': { decimal: ',', thousand: '\xA0' },
'da-DK': { decimal: ',', thousand: '.' },
'da-DK': { decimal: ',', thousand: '\xA0' },
'de-AT': { decimal: ',', thousand: '.' },
'de-CH': { decimal: '.', thousand: "'" },
'de-DE': { decimal: ',', thousand: '.' },
'el-CY': { decimal: ',', thousand: '.' },
'el-GR': { decimal: ',', thousand: '.' },
'en-GB': { decimal: '.', thousand: ',' },
'en-IE': { decimal: '.', thousand: ',' },
'en-MT': { decimal: ',', thousand: '.' },
'en-US': { decimal: '.', thousand: ',' },
'es-CL': { decimal: ',', thousand: '.' },
'es-ES': { decimal: ',', thousand: '.' },
'et-EE': { decimal: ',', thousand: '.' },
'fi-FI': { decimal: ',', thousand: '\0' },
'fr-BE': { decimal: ',', thousand: '\xA0' },
'fr-CH': { decimal: '.', thousand: '\xA0' },
'fr-FR': { decimal: ',', thousand: '\xA0' },
'fr-LU': { decimal: ',', thousand: '.' },
'hr-HR': { decimal: ',', thousand: '.' },
'hu-HU': { decimal: ',', thousand: '\xA0' },
'it-CH': { decimal: ',', thousand: '.' },
'it-IT': { decimal: ',', thousand: '.' },
'lt-LT': { decimal: ',', thousand: '\0' },
'lv-LV': { decimal: ',', thousand: '\0' },
'nb-NO': { decimal: ',', thousand: '\xA0' },
'nl-BE': { decimal: ',', thousand: '.' },
'nl-NL': { decimal: ',', thousand: '.' },
Expand All @@ -28,6 +36,8 @@ export const NUMBER_SEPARATORS = {
'pt-PT': { decimal: ',', thousand: '\xA0' },
'ro-RO': { decimal: ',', thousand: '.' },
'ru-RU': { decimal: ',', thousand: '\xA0' },
'sl-SI': { decimal: ',', thousand: '.' },
'sk-SK': { decimal: ',', thousand: '.' },
'sv-SE': { decimal: ',', thousand: '\xA0' }
};

Expand Down
12 changes: 11 additions & 1 deletion src/util/numbers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,30 @@ describe('numbers', () => {
const expectedNumbers = {
'bg-BG': '1\xA0000,00',
'cs-CZ': '1\xA0000,00',
'da-DK': '1.000,00',
'da-DK': '1\xA0000,00',
'de-AT': '1.000,00',
'de-CH': "1'000.00",
'de-DE': '1.000,00',
'el-CY': '1.000,00',
'el-GR': '1.000,00',
'en-GB': '1,000.00',
'en-IE': '1,000.00',
'en-MT': '1.000,00',
'en-US': '1,000.00',
'es-CL': '1.000,00',
'es-ES': '1.000,00',
'et-EE': '1.000,00',
'fi-FI': '1\x00000,00',
'fr-BE': '1\xA0000,00',
'fr-CH': '1\xA0000.00',
'fr-FR': '1\xA0000,00',
'fr-LU': '1.000,00',
'hr-HR': '1.000,00',
'hu-HU': '1\xA0000,00',
'it-CH': '1.000,00',
'it-IT': '1.000,00',
'lt-LT': '1\x00000,00',
'lv-LV': '1\x00000,00',
'nb-NO': '1\xA0000,00',
'nl-BE': '1.000,00',
'nl-NL': '1.000,00',
Expand All @@ -94,6 +102,8 @@ describe('numbers', () => {
'pt-PT': '1\xA0000,00',
'ro-RO': '1.000,00',
'ru-RU': '1\xA0000,00',
'sl-SI': '1.000,00',
'sk-SK': '1.000,00',
'sv-SE': '1\xA0000,00'
};
locales.forEach(locale => {
Expand Down

0 comments on commit 1beae74

Please sign in to comment.