File: /home/bdedition/www/core/app/Http/Middleware/ConvertToBengaliNumbers.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class ConvertToBengaliNumbers
{
public function handle(Request $request, Closure $next)
{
$response = $next($request);
// Only modify response if it is HTML content
if ($response->isSuccessful() && $response->headers->get('content-type') === 'text/html; charset=UTF-8') {
$content = $response->getContent();
$response->setContent($this->convertToBengali($content));
}
return $response;
}
private function convertToBengali($text)
{
$englishNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
$bengaliNumbers = ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'];
return str_replace($englishNumbers, $bengaliNumbers, $text);
}
}