From c6d6ed8f71c4131a0e5dc20360c64ad2b2f2232b Mon Sep 17 00:00:00 2001 From: Alvaro Canepa Date: Tue, 19 Apr 2022 09:23:30 -0300 Subject: [PATCH] - Add translation support --- src/ReportMedia/CSVReport.php | 2 +- src/ReportMedia/PdfReport.php | 6 +++--- src/ServiceProvider.php | 6 ++++++ src/lang/en/exceptions.php | 5 +++++ src/lang/en/messages.php | 19 +++++++++++++++++++ src/views/general-excel-template.blade.php | 6 +++--- src/views/general-pdf-template.blade.php | 14 +++++++------- ...hout-manipulation-excel-template.blade.php | 6 +++--- ...ithout-manipulation-pdf-template.blade.php | 14 +++++++------- 9 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 src/lang/en/exceptions.php create mode 100644 src/lang/en/messages.php diff --git a/src/ReportMedia/CSVReport.php b/src/ReportMedia/CSVReport.php index eb0231a..e2d0f5e 100755 --- a/src/ReportMedia/CSVReport.php +++ b/src/ReportMedia/CSVReport.php @@ -13,7 +13,7 @@ class CSVReport extends ReportGenerator public function download($filename, $save = false) { if (!class_exists(Writer::class)) { - throw new Exception('Please install league/csv to generate CSV Report!'); + throw new Exception(__('laravel-report-generator::exceptions.league_csv_not_found')); } if ($save) { diff --git a/src/ReportMedia/PdfReport.php b/src/ReportMedia/PdfReport.php index 9772622..8801abf 100644 --- a/src/ReportMedia/PdfReport.php +++ b/src/ReportMedia/PdfReport.php @@ -33,13 +33,13 @@ public function make() if ($pdfLibrary === 'snappy') { $pdf = \App::make('snappy.pdf.wrapper'); $pdf->setOption('footer-font-size', 10); - $pdf->setOption('footer-left', 'Page [page] of [topage]'); - $pdf->setOption('footer-right', 'Date Printed: ' . date('d M Y H:i:s')); + $pdf->setOption('footer-left', __('laravel-report-generator::messages.page')); + $pdf->setOption('footer-right', __('laravel-report-generator::messages.printed_at', ['date' => date('d M Y H:i:s')])); } else if ($pdfLibrary === 'dompdf') { try { $pdf = \App::make('dompdf.wrapper'); } catch (\ReflectionException $e) { - throw new \Exception('Please install either barryvdh/laravel-snappy or laravel-dompdf to generate PDF Report!'); + throw new \Exception(__('laravel-report-generator::exceptions.pdf_not_found')); } } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 2450bdb..4233e67 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -48,6 +48,8 @@ public function boot() } $this->loadViewsFrom(__DIR__ . '/views', 'laravel-report-generator'); + $this->loadTranslationsFrom(__DIR__.'/lang', 'laravel-report-generator'); + $this->publishes([ __DIR__.'/../config/report-generator.php' => config_path('report-generator.php') @@ -56,6 +58,10 @@ public function boot() $this->publishes([ __DIR__.'/views' => base_path('resources/views/vendor/laravel-report-generator') ], 'laravel-report:view-template'); + + $this->publishes([ + __DIR__.'/lang' => resource_path('lang/vendor/laravel-report-generator'), + ]); } protected function registerAliases() diff --git a/src/lang/en/exceptions.php b/src/lang/en/exceptions.php new file mode 100644 index 0000000..9790db4 --- /dev/null +++ b/src/lang/en/exceptions.php @@ -0,0 +1,5 @@ + 'Please install league/csv to generate CSV Report!', + 'pdf_not_found' => 'Please install either barryvdh/laravel-snappy or laravel-dompdf to generate PDF Report!', +]; diff --git a/src/lang/en/messages.php b/src/lang/en/messages.php new file mode 100644 index 0000000..94e3540 --- /dev/null +++ b/src/lang/en/messages.php @@ -0,0 +1,19 @@ + 'Page [page] of [topage]', + 'page_pdf' => 'Page {PAGE_NUM} of {PAGE_COUNT}', + 'printed_at' => 'Date Printed: :date', + 'no' => 'No', + 'grand_total' => 'Grand Total', +]; diff --git a/src/views/general-excel-template.blade.php b/src/views/general-excel-template.blade.php index f2e2fe2..0548d8d 100644 --- a/src/views/general-excel-template.blade.php +++ b/src/views/general-excel-template.blade.php @@ -71,7 +71,7 @@ @if ($showNumColumn) - No + {{ __('laravel-report-generator::messages.no') }} @endif @foreach ($columns as $colName => $colData) @if (array_key_exists($colName, $editColumns)) @@ -110,7 +110,7 @@ if ($isOnSameGroup === false) { echo ''; if ($showNumColumn || $grandTotalSkip > 1) { - echo 'Grand Total'; + echo ''.__('laravel-report-generator::messages.grand_total').''; } $dataFound = false; foreach ($columns as $colName => $colData) { @@ -179,7 +179,7 @@ @if ($showTotalColumns != [] && $ctr > 1) @if ($showNumColumn || $grandTotalSkip > 1) - Grand Total {{-- For Number --}} + {{ __('laravel-report-generator::messages.grand_total') }} {{-- For Number --}} @endif @foreach ($columns as $colName => $colData) diff --git a/src/views/general-pdf-template.blade.php b/src/views/general-pdf-template.blade.php index 0fe8cd7..04b3ac6 100644 --- a/src/views/general-pdf-template.blade.php +++ b/src/views/general-pdf-template.blade.php @@ -117,7 +117,7 @@ @if ($showNumColumn) - No + {{ __('laravel-report-generator::messages.no') }} @endif @foreach ($columns as $colName => $colData) @if (array_key_exists($colName, $editColumns)) @@ -157,7 +157,7 @@ if ($isOnSameGroup === false) { echo ''; if ($showNumColumn || $grandTotalSkip > 1) { - echo 'Grand Total'; + echo ''.__('laravel-report-generator::messages.grand_total').''; } $dataFound = false; foreach ($columns as $colName => $colData) { @@ -226,7 +226,7 @@ @if ($showTotalColumns != [] && $ctr > 1) @if ($showNumColumn || $grandTotalSkip > 1) - Grand Total {{-- For Number --}} + {{ __('laravel-report-generator::messages.grand_total') }} {{-- For Number --}} @endif @foreach ($columns as $colName => $colData) @@ -251,13 +251,13 @@ diff --git a/src/views/without-manipulation-excel-template.blade.php b/src/views/without-manipulation-excel-template.blade.php index 2446880..7821530 100644 --- a/src/views/without-manipulation-excel-template.blade.php +++ b/src/views/without-manipulation-excel-template.blade.php @@ -66,7 +66,7 @@ @if ($showNumColumn) - No + {{ __('laravel-report-generator::messages.no') }} @endif @foreach ($columns as $colName => $colData) {{ $colName }} @@ -101,7 +101,7 @@ if ($isOnSameGroup === false) { echo ''; if ($showNumColumn || $grandTotalSkip > 1) { - echo 'Grand Total'; + echo ''.__('laravel-report-generator::messages.grand_total').''; } $dataFound = false; foreach ($columns as $colName => $colData) { @@ -150,7 +150,7 @@ @endforeach @if ($showTotalColumns != [] && $ctr > 1) - Grand Total {{-- For Number --}} + {{ __('laravel-report-generator::messages.grand_total') }} {{-- For Number --}} @foreach ($columns as $colName => $colData) @if (array_key_exists($colName, $showTotalColumns)) diff --git a/src/views/without-manipulation-pdf-template.blade.php b/src/views/without-manipulation-pdf-template.blade.php index f240b15..e17afaa 100644 --- a/src/views/without-manipulation-pdf-template.blade.php +++ b/src/views/without-manipulation-pdf-template.blade.php @@ -112,7 +112,7 @@ @if ($showNumColumn) - No + {{ __('laravel-report-generator::messages.no') }} @endif @foreach ($columns as $colName => $colData) {{ $colName }} @@ -147,7 +147,7 @@ if ($isOnSameGroup === false) { echo ''; if ($showNumColumn || $grandTotalSkip > 1) { - echo 'Grand Total'; + echo ''.__('laravel-report-generator::messages.grand_total').''; } $dataFound = false; foreach ($columns as $colName => $colData) { @@ -197,7 +197,7 @@ @if ($showTotalColumns != [] && $ctr > 1) @if ($showNumColumn || $grandTotalSkip > 1) - Grand Total {{-- For Number --}} + {{ __('laravel-report-generator::messages.grand_total') }} {{-- For Number --}} @endif @foreach ($columns as $colName => $colData) @@ -222,13 +222,13 @@