]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Enhancement: better detection of default currency code (#6020)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Thu, 7 Mar 2024 15:04:32 +0000 (07:04 -0800)
committerGitHub <noreply@github.com>
Thu, 7 Mar 2024 15:04:32 +0000 (15:04 +0000)
src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts
src-ui/src/app/components/common/input/monetary/monetary.component.ts

index 0a8608a1b33295c4f2b8f9a811e087f78f78e242..4106c01eca55f0c05c6f4685925fc42940452d18 100644 (file)
@@ -56,4 +56,10 @@ describe('MonetaryComponent', () => {
     component.monetaryValue = 10.5
     expect(component.value).toEqual('EUR10.50')
   })
+
+  it('should set the default currency code based on LOCALE_ID', () => {
+    expect(component.defaultCurrencyCode).toEqual('USD') // default
+    component = new MonetaryComponent('pt-BR')
+    expect(component.defaultCurrencyCode).toEqual('BRL')
+  })
 })
index a7957b4c35ade43849653daf6d7f821315d64a37..ebfd9b6bf7c6eed315d13a8dbf74494301b5477e 100644 (file)
@@ -1,13 +1,14 @@
 import {
   Component,
-  DEFAULT_CURRENCY_CODE,
   ElementRef,
   forwardRef,
   Inject,
+  LOCALE_ID,
   ViewChild,
 } from '@angular/core'
 import { NG_VALUE_ACCESSOR } from '@angular/forms'
 import { AbstractInputComponent } from '../abstract-input'
+import { getLocaleCurrencyCode } from '@angular/common'
 
 @Component({
   providers: [
@@ -24,11 +25,12 @@ import { AbstractInputComponent } from '../abstract-input'
 export class MonetaryComponent extends AbstractInputComponent<string> {
   @ViewChild('currencyField')
   currencyField: ElementRef
+  defaultCurrencyCode: string
 
-  constructor(
-    @Inject(DEFAULT_CURRENCY_CODE) public defaultCurrencyCode: string
-  ) {
+  constructor(@Inject(LOCALE_ID) currentLocale: string) {
     super()
+
+    this.defaultCurrencyCode = getLocaleCurrencyCode(currentLocale)
   }
 
   get currencyCode(): string {