Fix date localization and transaction type translation (#2922)

This commit is contained in:
Shubham Kumar
2025-12-22 14:40:28 -06:00
committed by GitHub
parent 185d084127
commit 12d00ca784
14 changed files with 72 additions and 7 deletions
+59 -7
View File
@@ -1,26 +1,78 @@
import { Pipe, PipeTransform, inject } from '@angular/core'; import { Pipe, PipeTransform, inject, OnDestroy } from '@angular/core';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import moment from 'moment'; import moment from 'moment';
@Pipe({ name: 'dateFormat' }) // Load moment.js locale data for all supported languages
export class DateFormatPipe implements PipeTransform { import 'moment/locale/ne'; // Nepali
import 'moment/locale/es'; // Spanish
import 'moment/locale/de'; // German
import 'moment/locale/fr'; // French
import 'moment/locale/it'; // Italian
import 'moment/locale/ko'; // Korean
import 'moment/locale/lt'; // Lithuanian
import 'moment/locale/lv'; // Latvian
import 'moment/locale/pt'; // Portuguese
import 'moment/locale/sw'; // Swahili
import 'moment/locale/cs'; // Czech
@Pipe({ name: 'dateFormat', pure: false })
export class DateFormatPipe implements PipeTransform, OnDestroy {
private settingsService = inject(SettingsService); private settingsService = inject(SettingsService);
private translateService = inject(TranslateService);
private onLangChange: Subscription;
constructor() {
// Subscribe to language changes so Angular re-evaluates the pipe when language switches
this.onLangChange = this.translateService.onLangChange.subscribe(() => {
// No body needed; impure pipe will be re-run during change detection
});
}
ngOnDestroy(): void {
if (this.onLangChange) {
this.onLangChange.unsubscribe();
}
}
transform(value: any, dateFormat?: string): any { transform(value: any, dateFormat?: string): any {
const defaultDateFormat = this.settingsService.dateFormat.replace('dd', 'DD'); const defaultDateFormat = this.settingsService.dateFormat.replace('dd', 'DD');
if (typeof value === 'undefined') { if (typeof value === 'undefined' || value === null) {
return ''; return '';
} }
// Map SettingsService language code to a moment.js locale identifier
const langCode = this.settingsService.language.code;
let momentLocale: string;
if (!langCode) {
momentLocale = 'en';
} else if (langCode.includes('-')) {
// Convert codes like 'ne-NE' or 'es-MX' to base language 'ne', 'es'
momentLocale = langCode.split('-')[0];
} else {
momentLocale = langCode;
}
moment.locale(momentLocale);
let dateVal; let dateVal;
moment.locale(this.settingsService.language.code); if (Array.isArray(value)) {
if (value instanceof Array) { // Backend sometimes returns [yyyy, MM, dd]
dateVal = moment(value.join('-'), 'YYYY-MM-DD'); dateVal = moment(value.join('-'), 'YYYY-MM-DD');
} else { } else {
dateVal = moment(value); dateVal = moment(value);
} }
if (dateFormat == null) {
if (!dateVal.isValid()) {
return '';
}
if (!dateFormat) {
return dateVal.format(defaultDateFormat); return dateVal.format(defaultDateFormat);
} }
return dateVal.format(dateFormat); return dateVal.format(dateFormat);
} }
} }
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Splatná pokuta, úrok, jistina, poplatek, Pokuta předem, úrok, jistina, poplatek", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Splatná pokuta, úrok, jistina, poplatek, Pokuta předem, úrok, jistina, poplatek",
"Principal": "Ředitel školy", "Principal": "Ředitel školy",
"Repayment": "Splácení", "Repayment": "Splácení",
"Repayment (at time of disbursement)": "Splácení (v době výplaty)",
"Down payment": "Záloha", "Down payment": "Záloha",
"Charge refund": "Vrácení poplatku", "Charge refund": "Vrácení poplatku",
"Charge adjustment": "Úprava náboje", "Charge adjustment": "Úprava náboje",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Fällige Strafe, Zinsen, Kapital, Gebühr, Vorabstrafe, Zinsen, Kapital, Gebühr", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Fällige Strafe, Zinsen, Kapital, Gebühr, Vorabstrafe, Zinsen, Kapital, Gebühr",
"Principal": "Rektor", "Principal": "Rektor",
"Repayment": "Rückzahlung", "Repayment": "Rückzahlung",
"Repayment (at time of disbursement)": "Rückzahlung (zum Zeitpunkt der Auszahlung)",
"Down payment": "Anzahlung", "Down payment": "Anzahlung",
"Charge refund": "Rückerstattung der Gebühr", "Charge refund": "Rückerstattung der Gebühr",
"Charge adjustment": "Gebührenanpassung", "Charge adjustment": "Gebührenanpassung",
+1
View File
@@ -724,6 +724,7 @@
"Share Building Contribution": "Share Building Contribution", "Share Building Contribution": "Share Building Contribution",
"Principal": "Principal", "Principal": "Principal",
"Repayment": "Repayment", "Repayment": "Repayment",
"Repayment (at time of disbursement)": "Repayment (at time of disbursement)",
"Down payment": "Down payment", "Down payment": "Down payment",
"Charge refund": "Charge refund", "Charge refund": "Charge refund",
"Charge adjustment": "Charge adjustment", "Charge adjustment": "Charge adjustment",
+1
View File
@@ -703,6 +703,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Penalización vencida, Intereses, Capital, Comisiones, Penalización por adelantado, Intereses, Capital, Comisiones", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Penalización vencida, Intereses, Capital, Comisiones, Penalización por adelantado, Intereses, Capital, Comisiones",
"Principal": "Capital", "Principal": "Capital",
"Repayment": "Reembolso", "Repayment": "Reembolso",
"Repayment (at time of disbursement)": "Reembolso (al momento del desembolso)",
"Down payment": "Auto Pago", "Down payment": "Auto Pago",
"Charge refund": "Reembolso de cargo", "Charge refund": "Reembolso de cargo",
"Charge adjustment": "Ajuste de cargo", "Charge adjustment": "Ajuste de cargo",
+1
View File
@@ -703,6 +703,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Penalización vencida, Intereses, Capital, Comisiones, Penalización por adelantado, Intereses, Capital, Comisiones", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Penalización vencida, Intereses, Capital, Comisiones, Penalización por adelantado, Intereses, Capital, Comisiones",
"Principal": "Capital", "Principal": "Capital",
"Repayment": "Reembolso", "Repayment": "Reembolso",
"Repayment (at time of disbursement)": "Reembolso (al momento del desembolso)",
"Down payment": "Auto Pago", "Down payment": "Auto Pago",
"Charge refund": "Reembolso de cargo", "Charge refund": "Reembolso de cargo",
"Charge adjustment": "Ajuste de cargo", "Charge adjustment": "Ajuste de cargo",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Pénalité due, intérêts, principal, frais, Pénalité d'avance, intérêts, principal, frais", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Pénalité due, intérêts, principal, frais, Pénalité d'avance, intérêts, principal, frais",
"Principal": "Principal", "Principal": "Principal",
"Repayment": "Remboursement", "Repayment": "Remboursement",
"Repayment (at time of disbursement)": "Remboursement (au moment du décaissement)",
"Down payment": "Acompte", "Down payment": "Acompte",
"Charge refund": "Remboursement des frais", "Charge refund": "Remboursement des frais",
"Charge adjustment": "Ajustement des frais", "Charge adjustment": "Ajustement des frais",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Penale dovuta, interessi, capitale, commissione, Penale anticipata, interessi, capitale, commissione", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Penale dovuta, interessi, capitale, commissione, Penale anticipata, interessi, capitale, commissione",
"Principal": "Principale", "Principal": "Principale",
"Repayment": "Rimborso", "Repayment": "Rimborso",
"Repayment (at time of disbursement)": "Rimborso (al momento del disborso)",
"Down payment": "Acconto", "Down payment": "Acconto",
"Charge refund": "Rimborso addebito", "Charge refund": "Rimborso addebito",
"Charge adjustment": "Adeguamento della tariffa", "Charge adjustment": "Adeguamento della tariffa",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "위약금, 이자, 원금, 수수료, 선납 위약금, 이자, 원금, 수수료", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "위약금, 이자, 원금, 수수료, 선납 위약금, 이자, 원금, 수수료",
"Principal": "주요한", "Principal": "주요한",
"Repayment": "반환", "Repayment": "반환",
"Repayment (at time of disbursement)": "상환 (지급 시)",
"Down payment": "계약금", "Down payment": "계약금",
"Charge refund": "청구금액 환불", "Charge refund": "청구금액 환불",
"Charge adjustment": "요금 조정", "Charge adjustment": "요금 조정",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Delspinigiai, delspinigiai, pagrindinė suma, mokestis, Avansinė bauda, ​​palūkanos, pagrindinė suma, mokestis", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Delspinigiai, delspinigiai, pagrindinė suma, mokestis, Avansinė bauda, ​​palūkanos, pagrindinė suma, mokestis",
"Principal": "direktorius", "Principal": "direktorius",
"Repayment": "Grąžinimas", "Repayment": "Grąžinimas",
"Repayment (at time of disbursement)": "Grąžinimas (išmokėjimo metu)",
"Down payment": "Pradinis įnašas", "Down payment": "Pradinis įnašas",
"Charge refund": "Mokesčio grąžinimas", "Charge refund": "Mokesčio grąžinimas",
"Charge adjustment": "Krovinio reguliavimas", "Charge adjustment": "Krovinio reguliavimas",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Maksājamais līgumsods, procenti, pamatsumma, maksa, avansa līgumsods, procenti, pamatsumma, maksa", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Maksājamais līgumsods, procenti, pamatsumma, maksa, avansa līgumsods, procenti, pamatsumma, maksa",
"Principal": "Direktors", "Principal": "Direktors",
"Repayment": "Atmaksa", "Repayment": "Atmaksa",
"Repayment (at time of disbursement)": "Atmaksa (izmaksas laikā)",
"Down payment": "Pirmā iemaksa", "Down payment": "Pirmā iemaksa",
"Charge refund": "Maksas atmaksa", "Charge refund": "Maksas atmaksa",
"Charge adjustment": "Uzlādes regulēšana", "Charge adjustment": "Uzlādes regulēšana",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "बक्यौता जरिवाना, व्याज, मुद्दल, शुल्क, अग्रिम जरिवाना, व्याज, मूल, शुल्क", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "बक्यौता जरिवाना, व्याज, मुद्दल, शुल्क, अग्रिम जरिवाना, व्याज, मूल, शुल्क",
"Principal": "प्रिन्सिपल", "Principal": "प्रिन्सिपल",
"Repayment": "भुक्तानी", "Repayment": "भुक्तानी",
"Repayment (at time of disbursement)": "भुक्तानी (वितरणको समयमा)",
"Down payment": "डाउन पेमेन्ट", "Down payment": "डाउन पेमेन्ट",
"Charge refund": "शुल्क फिर्ता", "Charge refund": "शुल्क फिर्ता",
"Charge adjustment": "चार्ज समायोजन", "Charge adjustment": "चार्ज समायोजन",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Pena devida, juros, principal, taxa, multa antecipada, juros, principal, taxa", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Pena devida, juros, principal, taxa, multa antecipada, juros, principal, taxa",
"Principal": "Diretor", "Principal": "Diretor",
"Repayment": "Reembolso", "Repayment": "Reembolso",
"Repayment (at time of disbursement)": "Reembolso (no momento do desembolso)",
"Down payment": "Pagamento inicial", "Down payment": "Pagamento inicial",
"Charge refund": "Reembolso de cobrança", "Charge refund": "Reembolso de cobrança",
"Charge adjustment": "Ajuste de cobrança", "Charge adjustment": "Ajuste de cobrança",
+1
View File
@@ -704,6 +704,7 @@
"Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Adhabu inayostahili, riba, mkuu, ada, Adhabu ya mapema, riba, mkuu, ada", "Due penalty, interest, principal, fee, In advance penalty, interest, principal, fee": "Adhabu inayostahili, riba, mkuu, ada, Adhabu ya mapema, riba, mkuu, ada",
"Principal": "Mkuu wa shule", "Principal": "Mkuu wa shule",
"Repayment": "Ulipaji", "Repayment": "Ulipaji",
"Repayment (at time of disbursement)": "Ulipaji (wakati wa malipo)",
"Down payment": "Malipo ya chini", "Down payment": "Malipo ya chini",
"Charge refund": "Maliza marejesho", "Charge refund": "Maliza marejesho",
"Charge adjustment": "Marekebisho ya malipo", "Charge adjustment": "Marekebisho ya malipo",