From 68018040f2ec0a7c89ca5c8490b4b74d11cc07f7 Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Fri, 29 Jan 2021 14:36:21 +0100 Subject: localize decimal separator in video miniatures (#3643) * fix(client): localize decimal separator * fix(client/numpipe): handle Intl failure gently * Revert "fix(client/numpipe): handle Intl failure gently" This reverts commit e275049f1fabb0a7af5a274ebfc33f9c3fb279ed. * client: switch from Intl to ng formatNumber --- .../shared/shared-main/angular/number-formatter.pipe.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'client/src/app/shared/shared-main') diff --git a/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts b/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts index 5e6ccfa16..8badb1573 100644 --- a/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts +++ b/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts @@ -1,14 +1,10 @@ -import { Pipe, PipeTransform } from '@angular/core' +import { formatNumber } from '@angular/common' +import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core' // Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/ng-pipes/pipes/math/bytes.ts @Pipe({ name: 'myNumberFormatter' }) export class NumberFormatterPipe implements PipeTransform { - private dictionary: Array<{max: number, type: string}> = [ - { max: 1000, type: '' }, - { max: 1000000, type: 'K' }, - { max: 1000000000, type: 'M' } - ] /** * @param x number @@ -21,6 +17,13 @@ export class NumberFormatterPipe implements PipeTransform { return +f } + private dictionary: Array<{max: number, type: string}> = [ + { max: 1000, type: '' }, + { max: 1000000, type: 'K' }, + { max: 1000000000, type: 'M' } + ] + constructor (@Inject(LOCALE_ID) private localeId: string) {} + transform (value: number) { const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1] const calc = value / (format.max / 1000) @@ -28,7 +31,7 @@ export class NumberFormatterPipe implements PipeTransform { const decimalPart = NumberFormatterPipe.getDecimalForNumber(calc) return integralPart < 10 && decimalPart > 0 - ? `${integralPart}.${decimalPart}${format.type}` + ? formatNumber(parseFloat(`${integralPart}.${decimalPart}`), this.localeId) + format.type : `${integralPart}${format.type}` } } -- cgit v1.2.3