From ed48419fc08172f336cde4c49a56f977b05d0093 Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:03:26 +0500 Subject: [PATCH 1/3] added translations for headers in excel report files --- .../shared/services/excel-export.service.ts | 52 ++++++++++++++++--- .../reset-password-modal.component.ts | 2 +- src/assets/i18n/Arabic.json | 23 +++++++- src/assets/i18n/English.json | 19 ++++++- 4 files changed, 86 insertions(+), 10 deletions(-) diff --git a/src/app/shared/services/excel-export.service.ts b/src/app/shared/services/excel-export.service.ts index d0b0c7d..9691cb8 100644 --- a/src/app/shared/services/excel-export.service.ts +++ b/src/app/shared/services/excel-export.service.ts @@ -1,28 +1,66 @@ import { Injectable } from '@angular/core'; import { saveAs } from 'file-saver'; import * as XLSX from 'xlsx'; +import { TranslateService } from '@ngx-translate/core'; import { EXCEL_FILE_EXTENSION, EXCEL_FILE_TYPE } from '../../utils/app.constants'; +import { StorageService } from './storage.service'; +import { supportedLanguages } from '../../utils/enums'; @Injectable({ providedIn: 'root' }) export class ExcelExportService { - constructor() { } - private fileType = EXCEL_FILE_TYPE; - private fileExtension = EXCEL_FILE_EXTENSION; + private fileExtension = EXCEL_FILE_EXTENSION; + + constructor(private translate: TranslateService, private storageService: StorageService) { } public exportExcel(jsonData: any[], fileName: string): void { - const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(jsonData); - const wb: XLSX.WorkBook = { Sheets: { 'data': ws }, SheetNames: ['data'] }; + const translatedData = this.translateHeaders(jsonData); + + const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(translatedData); + const wb: XLSX.WorkBook = { Sheets: { data: ws }, SheetNames: ['data'] }; const excelBuffer: any = XLSX.write(wb, { bookType: 'xlsx', type: 'array' }); + this.saveExcelFile(excelBuffer, fileName); } + private translateHeaders(data: any[]): any[] { + if (!data?.length) return data; + + return data.map(row => { + const newRow: any = {}; + + Object.keys(row).forEach(key => { + const candidates = [ + key, + key.toLowerCase(), + key.toUpperCase(), + key.replace(/([A-Z])/g, '_$1').toUpperCase() + ]; + + let translatedKey = key; + + for (const candidate of candidates) { + const value = this.translate.instant(candidate); + if (value !== candidate) { + translatedKey = value; + break; + } + } + + newRow[translatedKey] = row[key]; + }); + + return newRow; + }); + } + + private saveExcelFile(buffer: any, fileName: string): void { - const data: Blob = new Blob([buffer], {type: this.fileType}); - saveAs.saveAs(data, fileName + this.fileExtension); + const data: Blob = new Blob([buffer], { type: this.fileType }); + saveAs(data, fileName + this.fileExtension); } } diff --git a/src/app/user-management/reset-password-modal/reset-password-modal.component.ts b/src/app/user-management/reset-password-modal/reset-password-modal.component.ts index 025e5a4..964cfce 100644 --- a/src/app/user-management/reset-password-modal/reset-password-modal.component.ts +++ b/src/app/user-management/reset-password-modal/reset-password-modal.component.ts @@ -13,7 +13,7 @@ import { PasswordHideShowComponent } from '../../shared/components/password-hide @Component({ selector: 'app-reset-password-modal', standalone: true, - imports: [TranslateModule, ReactiveFormsModule, CommonModule, PasswordHideShowComponent], + imports: [TranslateModule, ReactiveFormsModule, CommonModule], templateUrl: './reset-password-modal.component.html' }) export class ResetPasswordModalComponent implements OnInit, OnChanges { diff --git a/src/assets/i18n/Arabic.json b/src/assets/i18n/Arabic.json index 46fdddb..78c06f2 100644 --- a/src/assets/i18n/Arabic.json +++ b/src/assets/i18n/Arabic.json @@ -269,5 +269,26 @@ "SAVED_SUCCESSFULLY": "تم الحفظ بنجاح", "activityLogs": "سجلات النشاط", "activityLogDetails": "تفاصيل سجل النشاط", - "resetPasswordButton": "إعادة تعيين كلمة المرور" + "resetPasswordButton": "إعادة تعيين كلمة المرور", + "dateTime": "التاريخ والوقت", + "responseCode": "رمز الاستجابة", + "remoteIp": "IP البعيد", + "requestBody": "هيئة الطلب", + "requestUri": "طلب URI", + "method": "طريقة", + "id": "بطاقة تعريف", + + "logId": "معرف السجل", + "porOrgacode": "رمز المنظمة", + "drMbmbkmsnumber": "رقم الحساب المدين", + "crMbmbkmsnumber": "رقم حساب الائتمان", + "ppmPymdcode": "رمز الدفع", + "sgtGntrdate": "تاريخ المعاملة", + "sgtGntrcreateat": "تاريخ الإنشاء", + "updatedAt": "تم التحديث في", + "crPcaglacode": "حساب CR GL", + "drPcaGlacode": "حساب DR GL", + "transactionUri": "معرّف المعاملة", + "transactionCode": "رمز المعاملة", + "channelCode": "رمز القناة" } \ No newline at end of file diff --git a/src/assets/i18n/English.json b/src/assets/i18n/English.json index 650d17d..4d04e43 100644 --- a/src/assets/i18n/English.json +++ b/src/assets/i18n/English.json @@ -276,5 +276,22 @@ "activityLogDetails": "Activity Log Details", "transactionCode": "Transaction Code", "transactionUri": "Transaction URI", - "resetPasswordButton": "Reset Password" + "resetPasswordButton": "Reset Password", + "dateTime": "Date Time", + "responseCode": "Response Code", + "remoteIp": "Remote IP", + "requestBody": "Request Body", + "requestUri": "Request URI", + "method": "Method", + "id": "Id", + "logId": "Log ID", + "porOrgacode": "Organization Code", + "drMbmbkmsnumber": "Debit Account Number", + "crMbmbkmsnumber": "Credit Account Number", + "ppmPymdcode": "Payment Code", + "sgtGntrdate": "Transaction Date", + "sgtGntrcreateat": "Creation Date", + "updatedAt": "Updated At", + + "channelCode": "Channel Code" } \ No newline at end of file From ef3952650d585a812e03032fed70538285d57462 Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:27:31 +0500 Subject: [PATCH 2/3] resolved direction issue in Arabic on browser reload --- src/app/app.component.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 6fa60d8..ea2cefd 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -35,6 +35,10 @@ export class AppComponent { this.direction = this.storageService.getItem('direction') || directions.LTR; this.storageService.setItem('direction', this.direction); + if (typeof document !== 'undefined') { + document.documentElement.setAttribute('dir', this.direction); + } + const userStr = this.storageService.getItem('user'); if (userStr) { try { From a930cfe6965b54bdaa68b9acb132d0cdf600a6b4 Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:51:07 +0500 Subject: [PATCH 3/3] Update app.component.ts --- src/app/app.component.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ea2cefd..4ca0dcf 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -35,9 +35,9 @@ export class AppComponent { this.direction = this.storageService.getItem('direction') || directions.LTR; this.storageService.setItem('direction', this.direction); - if (typeof document !== 'undefined') { - document.documentElement.setAttribute('dir', this.direction); - } + // if (typeof document !== 'undefined') { + // document.documentElement.setAttribute('dir', this.direction); + // } const userStr = this.storageService.getItem('user'); if (userStr) {