Skip to content

Commit

Permalink
Merge pull request #75 from alvaro-canepa/master
Browse files Browse the repository at this point in the history
- Add translation support
  • Loading branch information
Jimmy-JS authored Apr 23, 2022
2 parents 19ccc56 + c6d6ed8 commit 2e39ea8
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/ReportMedia/CSVReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/ReportMedia/PdfReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/lang/en/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
return [
'league_csv_not_found' => 'Please install league/csv to generate CSV Report!',
'pdf_not_found' => 'Please install either barryvdh/laravel-snappy or laravel-dompdf to generate PDF Report!',
];
19 changes: 19 additions & 0 deletions src/lang/en/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Footer PDF Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used by the laravel-report-generator library
| You are free to change them to anything you want to customize your views to
| better match your application.
|
*/

'page' => 'Page [page] of [topage]',
'page_pdf' => 'Page {PAGE_NUM} of {PAGE_COUNT}',
'printed_at' => 'Date Printed: :date',
'no' => 'No',
'grand_total' => 'Grand Total',
];
6 changes: 3 additions & 3 deletions src/views/general-excel-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<thead>
<tr>
@if ($showNumColumn)
<th class="left">No</th>
<th class="left">{{ __('laravel-report-generator::messages.no') }}</th>
@endif
@foreach ($columns as $colName => $colData)
@if (array_key_exists($colName, $editColumns))
Expand Down Expand Up @@ -110,7 +110,7 @@
if ($isOnSameGroup === false) {
echo '<tr class="f-white">';
if ($showNumColumn || $grandTotalSkip > 1) {
echo '<td class="bg-black" colspan="' . $grandTotalSkip . '"><b>Grand Total</b></td>';
echo '<td class="bg-black" colspan="' . $grandTotalSkip . '"><b>'.__('laravel-report-generator::messages.grand_total').'</b></td>';
}
$dataFound = false;
foreach ($columns as $colName => $colData) {
Expand Down Expand Up @@ -179,7 +179,7 @@
@if ($showTotalColumns != [] && $ctr > 1)
<tr class="f-white">
@if ($showNumColumn || $grandTotalSkip > 1)
<td colspan="{{ $grandTotalSkip }}" class="bg-black"><b>Grand Total</b></td> {{-- For Number --}}
<td colspan="{{ $grandTotalSkip }}" class="bg-black"><b>{{ __('laravel-report-generator::messages.grand_total') }}</b></td> {{-- For Number --}}
@endif
<?php $dataFound = false; ?>
@foreach ($columns as $colName => $colData)
Expand Down
14 changes: 7 additions & 7 deletions src/views/general-pdf-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<thead>
<tr>
@if ($showNumColumn)
<th class="left">No</th>
<th class="left">{{ __('laravel-report-generator::messages.no') }}</th>
@endif
@foreach ($columns as $colName => $colData)
@if (array_key_exists($colName, $editColumns))
Expand Down Expand Up @@ -157,7 +157,7 @@
if ($isOnSameGroup === false) {
echo '<tr class="bg-black f-white">';
if ($showNumColumn || $grandTotalSkip > 1) {
echo '<td colspan="' . $grandTotalSkip . '"><b>Grand Total</b></td>';
echo '<td colspan="' . $grandTotalSkip . '"><b>'.__('laravel-report-generator::messages.grand_total').'</b></td>';
}
$dataFound = false;
foreach ($columns as $colName => $colData) {
Expand Down Expand Up @@ -226,7 +226,7 @@
@if ($showTotalColumns != [] && $ctr > 1)
<tr class="bg-black f-white">
@if ($showNumColumn || $grandTotalSkip > 1)
<td colspan="{{ $grandTotalSkip }}"><b>Grand Total</b></td> {{-- For Number --}}
<td colspan="{{ $grandTotalSkip }}"><b>{{ __('laravel-report-generator::messages.grand_total') }}</b></td> {{-- For Number --}}
@endif
<?php $dataFound = false; ?>
@foreach ($columns as $colName => $colData)
Expand All @@ -251,13 +251,13 @@
<script type="text/php">
@if (strtolower($orientation) == 'portrait')
if ( isset($pdf) ) {
$pdf->page_text(30, ($pdf->get_height() - 26.89), "Date Printed: " . date('d M Y H:i:s'), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10);
$pdf->page_text(30, ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.printed_at', ['date' => date('d M Y H:i:s')]), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.page_pdf'), null, 10);
}
@elseif (strtolower($orientation) == 'landscape')
if ( isset($pdf) ) {
$pdf->page_text(30, ($pdf->get_height() - 26.89), "Date Printed: " . date('d M Y H:i:s'), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10);
$pdf->page_text(30, ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.printed_at', ['date' => date('d M Y H:i:s')]), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.page_pdf'), null, 10);
}
@endif
</script>
Expand Down
6 changes: 3 additions & 3 deletions src/views/without-manipulation-excel-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<thead>
<tr>
@if ($showNumColumn)
<th class="left">No</th>
<th class="left">{{ __('laravel-report-generator::messages.no') }}</th>
@endif
@foreach ($columns as $colName => $colData)
<th class="left">{{ $colName }}</th>
Expand Down Expand Up @@ -101,7 +101,7 @@
if ($isOnSameGroup === false) {
echo '<tr class="f-white">';
if ($showNumColumn || $grandTotalSkip > 1) {
echo '<td class="bg-black" colspan="' . $grandTotalSkip . '"><b>Grand Total</b></td>';
echo '<td class="bg-black" colspan="' . $grandTotalSkip . '"><b>'.__('laravel-report-generator::messages.grand_total').'</b></td>';
}
$dataFound = false;
foreach ($columns as $colName => $colData) {
Expand Down Expand Up @@ -150,7 +150,7 @@
@endforeach
@if ($showTotalColumns != [] && $ctr > 1)
<tr class="f-white">
<td colspan="{{ $grandTotalSkip }}" class="bg-black"><b>Grand Total</b></td> {{-- For Number --}}
<td colspan="{{ $grandTotalSkip }}" class="bg-black"><b>{{ __('laravel-report-generator::messages.grand_total') }}</b></td> {{-- For Number --}}
<?php $dataFound = false; ?>
@foreach ($columns as $colName => $colData)
@if (array_key_exists($colName, $showTotalColumns))
Expand Down
14 changes: 7 additions & 7 deletions src/views/without-manipulation-pdf-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<thead>
<tr>
@if ($showNumColumn)
<th class="left">No</th>
<th class="left">{{ __('laravel-report-generator::messages.no') }}</th>
@endif
@foreach ($columns as $colName => $colData)
<th class="left">{{ $colName }}</th>
Expand Down Expand Up @@ -147,7 +147,7 @@
if ($isOnSameGroup === false) {
echo '<tr class="bg-black f-white">';
if ($showNumColumn || $grandTotalSkip > 1) {
echo '<td colspan="' . ($grandTotalSkip) . '"><b>Grand Total</b></td>';
echo '<td colspan="' . ($grandTotalSkip) . '"><b>'.__('laravel-report-generator::messages.grand_total').'</b></td>';
}
$dataFound = false;
foreach ($columns as $colName => $colData) {
Expand Down Expand Up @@ -197,7 +197,7 @@
@if ($showTotalColumns != [] && $ctr > 1)
<tr class="bg-black f-white">
@if ($showNumColumn || $grandTotalSkip > 1)
<td colspan="{{ $grandTotalSkip }}"><b>Grand Total</b></td> {{-- For Number --}}
<td colspan="{{ $grandTotalSkip }}"><b>{{ __('laravel-report-generator::messages.grand_total') }}</b></td> {{-- For Number --}}
@endif
<?php $dataFound = false; ?>
@foreach ($columns as $colName => $colData)
Expand All @@ -222,13 +222,13 @@
<script type="text/php">
@if (strtolower($orientation) == 'portrait')
if ( isset($pdf) ) {
$pdf->page_text(30, ($pdf->get_height() - 26.89), "Date Printed: " . date('d M Y H:i:s'), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10);
$pdf->page_text(30, ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.printed_at', ['date' => date('d M Y H:i:s')]), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.page_pdf'), null, 10);
}
@elseif (strtolower($orientation) == 'landscape')
if ( isset($pdf) ) {
$pdf->page_text(30, ($pdf->get_height() - 26.89), "Date Printed: " . date('d M Y H:i:s'), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10);
$pdf->page_text(30, ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.printed_at', ['date' => date('d M Y H:i:s')]), null, 10);
$pdf->page_text(($pdf->get_width() - 84), ($pdf->get_height() - 26.89), __('laravel-report-generator::messages.page_pdf'), null, 10);
}
@endif
</script>
Expand Down

0 comments on commit 2e39ea8

Please sign in to comment.