parent
bcb251923c
commit
6440b3fad4
|
@ -58,7 +58,7 @@ export function formatValue({
|
|||
if (typeof value !== 'number') {
|
||||
return value
|
||||
}
|
||||
const serializedUnit = serialiseUnit(unit, value)
|
||||
const serializedUnit = serialiseUnit(unit, value, language)
|
||||
|
||||
switch (serializedUnit) {
|
||||
case '€':
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { expect } from 'chai'
|
||||
import { formatCurrency, formatPercentage, formatValue } from './format'
|
||||
import { parseUnit } from 'Engine/units'
|
||||
|
||||
describe('format engine values', () => {
|
||||
it('format currencies', () => {
|
||||
|
@ -25,3 +26,23 @@ describe('format engine values', () => {
|
|||
expect(formatValue({ value: 1200, language: 'fr' })).to.equal('1 200')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Units handling', () => {
|
||||
it('translate unit', () => {
|
||||
expect(formatValue({ value: 1, unit: 'jour', language: 'fr' })).to.equal(
|
||||
'1 jour'
|
||||
)
|
||||
expect(formatValue({ value: 1, unit: 'jour', language: 'en' })).to.equal(
|
||||
'1 day'
|
||||
)
|
||||
})
|
||||
|
||||
it('pluralize unit', () => {
|
||||
expect(formatValue({ value: 2, unit: 'jour', language: 'fr' })).to.equal(
|
||||
'2 jours'
|
||||
)
|
||||
expect(
|
||||
formatValue({ value: 7, unit: parseUnit('jour/semaine'), language: 'fr' })
|
||||
).to.equal('7 jours / semaine')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -18,10 +18,10 @@ let printUnits = (units, count) =>
|
|||
.join('-')
|
||||
|
||||
const plural = 2
|
||||
export let serialiseUnit = (rawUnit, count = plural) => {
|
||||
export let serialiseUnit = (rawUnit, count = plural, lng = undefined) => {
|
||||
if (typeof rawUnit !== 'object') {
|
||||
return typeof rawUnit === 'string'
|
||||
? i18n.t(`units:${rawUnit}`, { count })
|
||||
? i18n.t(`units:${rawUnit}`, { count, lng })
|
||||
: rawUnit
|
||||
}
|
||||
let unit = simplify(rawUnit),
|
||||
|
|
Loading…
Reference in New Issue