A simple package to calculate and display estimated reading time in both Arabic and English.
somarkn99/estimated-reading-time is a Laravel package for a simple package to calculate and display estimated reading time in both arabic and english..
It currently has 6 GitHub stars and 8 downloads on Packagist (latest version v1.0.0).
Install it with composer require somarkn99/estimated-reading-time.
Discover more Laravel packages by somarkn99
or browse all Laravel packages to compare alternatives.
Last updated
This package provides a simple way to calculate and display the estimated reading time for content in both Arabic and English.
You can install the package via composer:
composer require somarkn99/estimated-reading-time
A Wordpress version of this package is available as a plugin here
Add the service provider to the providers array in config/app.php:
'providers' => [
// Other Service Providers
Somarkn99\EstimatedReadingTime\EstimatedReadingTimeServiceProvider::class,
],
You can publish the configuration file using this command:
php artisan vendor:publish --provider="Somarkn99\EstimatedReadingTime\EstimatedReadingTimeServiceProvider" --tag="config"
This will publish the estimatedreadingtime.php configuration file to the config directory.
You can use the Blade directive to display the estimated reading time in your views:
@readingtime($content, 'en')
Or for Arabic content:
@readingtime($content, 'ar')
You can directly call the calculate method from the EstimatedReadingTime class in your controllers, commands, or other parts of your application:
use Somarkn99\EstimatedReadingTime\EstimatedReadingTime;
$readingTime = EstimatedReadingTime::calculate($content, 'en');
If you prefer to use an API to get the estimated reading time, you can use the provided endpoint.
Ensure the route is loaded by including it in your routes/api.php:
Route::prefix('api')->group(function () {
require base_path('vendor/somarkn99/estimated-reading-time/src/routes/api.php');
});
Send a POST request to /api/reading-time with the content and language in the request body.
Request:
POST /api/reading-time
Content-Type: application/json
{
"content": "Your article content goes here...",
"lang": "en"
}
Response:
{
"reading_time": "Estimated Time of Reading: 3 Min"
}
You can customize the package by modifying the configuration options:
return [
'ar_prefix' => 'الوقت المقدر للقراءة: ',
'ar_suffix_s' => 'دقيقة',
'ar_suffix_p' => 'دقائق',
'en_prefix' => 'Estimated Time of Reading: ',
'en_suffix' => 'Min',
'en_wpm' => 300,
'ar_wpm' => 250,
'exclude_images' => true,
];
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.